Mock jed for test determinism
What does this MR do and why?
This MR adds a __mocks__/jed/index.js
so that we won't actually translate strings in unit tests. This would allow us to remove the test file externalization requirement for JavaScript unit tests (see current relevant docs).
From the commit message:
- #390934 (comment 1494028934)
- It'a possible for some test environments to run in a specific locale. This change skips pulling translations in unit tests to improve test determinism across environments.
How to set up and validate locally
- Run
bin/rake gettext:compile
- Add an import to any of the
locale/*/app
intest_setup.js
diff --git a/spec/frontend/test_setup.js b/spec/frontend/test_setup.js index d3d3e5c8c720..85f0711c135b 100644 --- a/spec/frontend/test_setup.js +++ b/spec/frontend/test_setup.js @@ -3,6 +3,7 @@ import { setImmediate } from 'timers'; import Dexie from 'dexie'; import { IDBKeyRange, IDBFactory } from 'fake-indexeddb'; +import '~/locale/es/app'; import 'helpers/shared_test_setup'; const indexedDB = new IDBFactory();
- Run jest for a test that includes a hardcoded non-translated string in the assertion. Example
yarn run jest ee/spec/frontend/pages/admin/application_settings/ci_cd/ci_template_dropdown_spec.js
.
Thanks
Thanks @afontaine for your help on this! https://youtu.be/0-6gspPSFkA
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Edited by Paul Slaughter