From e67be551528c81adae615e3728ff34c2b92ef6c0 Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Sat, 29 Feb 2020 11:59:56 +0000 Subject: [PATCH] node tests: Actually test `translations.js`. Before this test, we were validating the behavior of `i18next`, but we weren't validating our light layer that sits on top of `i18next`, which currently resides in the slightly misnamed `translations.js` file. The translations module is now so small that I'll just quote it verbatim here: import i18next from 'i18next'; i18next.init({ lng: 'lang', resources: { lang: { translation: page_params.translation_data, }, }, nsSeparator: false, keySeparator: false, interpolation: { prefix: "__", suffix: "__", }, returnEmptyString: false, // Empty string is not a valid translation. }); window.i18n = i18next; We now just do `zrequire('translations')` to initialize the `i18next` library, which allows us to have simpler test setup and to actually exercise the above call to `i18next.init`. This change now gives us 100% line coverage of `translations.js`, which of course isn't that hard to acheive (see above). --- frontend_tests/node_tests/i18n.js | 35 +++++++++++++------------------ tools/test-js-with-node | 1 - 2 files changed, 14 insertions(+), 22 deletions(-) diff --git a/frontend_tests/node_tests/i18n.js b/frontend_tests/node_tests/i18n.js index 0ae9240aea..b81e6a404f 100644 --- a/frontend_tests/node_tests/i18n.js +++ b/frontend_tests/node_tests/i18n.js @@ -1,30 +1,23 @@ set_global('Handlebars', global.make_handlebars()); zrequire('templates'); -// All of our other tests stub out i18n activity; -// here we do a quick sanity check on the engine itself. -const i18next = zrequire('i18next', 'i18next'); - -global.i18n = i18next; - -i18next.init({ - nsSeparator: false, - keySeparator: false, - interpolation: { - prefix: "__", - suffix: "__", - }, - lng: 'fr', - resources: { - fr: { - translation: { - "Quote and reply": "French translation", - "Desktop notifications are triggered for messages that are offscreen when they arrive. Mobile and email notifications are triggered once you have been away from Zulip for a few minutes.": "Some French text", - }, - }, +// We download our translations in `page_params` (which +// are for the user's chosen language), so we simulate +// that here for the tests. +set_global('page_params', { + translation_data: { + "Quote and reply": "French translation", + "Desktop notifications are triggered for messages that are offscreen when they arrive. Mobile and email notifications are triggered once you have been away from Zulip for a few minutes.": "Some French text", }, }); +// All of our other tests stub out i18n activity; +// here we do a quick sanity check on the engine itself. +// We use `translations.js` to initialize `i18next` and +// to set `i18n` to `i18next` on the global namespace +// for `templates.js`. +zrequire('translations'); + run_test('t_tag', () => { const args = { message: { diff --git a/tools/test-js-with-node b/tools/test-js-with-node index 0aa4b92caf..80b03a37fc 100755 --- a/tools/test-js-with-node +++ b/tools/test-js-with-node @@ -146,7 +146,6 @@ EXEMPT_FILES = { 'static/js/todo_widget.js', 'static/js/topic_list.js', 'static/js/topic_zoom.js', - 'static/js/translations.js', 'static/js/tutorial.js', 'static/js/typing_events.js', 'static/js/typing.js',