Bug 1575823 - Enable support for l10n.getString in tests r=Ola
authorBelén Albeza <balbeza@mozilla.com>
Fri, 23 Aug 2019 09:53:19 +0000
changeset 489563 8f6e40f9a0ad9a477e7f7e0d629ca20fdec91996
parent 489562 ea71d4d41dceec656608e9b03b591d5b41f2ac7b
child 489571 85b4e005b39ce061e796d65ce1b2fc4e83c96a41
child 489572 f5b29024aa67972a45b617c7210c3da7f644f872
push id36476
push userncsoregi@mozilla.com
push dateFri, 23 Aug 2019 15:36:51 +0000
treeherdermozilla-central@8f6e40f9a0ad [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersOla
bugs1575823
milestone70.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1575823 - Enable support for l10n.getString in tests r=Ola - This creates a mock for fluent-l10n module, so we can use `l10n.getString()` in our code and test for it. - This patch also removes unused files `test/fixtures/l10n.js` and `test/fixtures/PluralForm.js` In order to double check the mock works, these two lines can be added to any test: ``` const { l10n } = require("devtools/client/application/src/modules/l10n"); expect(l10n.getString("foo")).toBe("foo"); ``` Differential Revision: https://phabricator.services.mozilla.com/D43050
devtools/client/application/test/components/fixtures/PluralForm.js
devtools/client/application/test/components/fixtures/fluent-l10n.js
devtools/client/application/test/components/fixtures/l10n.js
devtools/client/application/test/components/jest.config.js
deleted file mode 100644
--- a/devtools/client/application/test/components/fixtures/PluralForm.js
+++ /dev/null
@@ -1,11 +0,0 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
-
-"use strict";
-
-module.exports.PluralForm = {
-  get(num, str) {
-    return str;
-  },
-};
rename from devtools/client/application/test/components/fixtures/l10n.js
rename to devtools/client/application/test/components/fixtures/fluent-l10n.js
--- a/devtools/client/application/test/components/fixtures/l10n.js
+++ b/devtools/client/application/test/components/fixtures/fluent-l10n.js
@@ -1,23 +1,23 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 "use strict";
 
-// @TODO Load the actual strings from instead.
-class L10N {
-  getStr(str) {
-    switch (str) {
-      default:
-        return str;
-    }
+/**
+ * Mock for devtools/client/shared/modules/fluent-l10n/fluent-l10n
+ */
+class FluentL10n {
+  async init() {}
+
+  getBundles() {
+    return [];
   }
 
-  getFormatStr(str) {
-    return this.getStr(str);
+  getString(id, args) {
+    return args ? `${id}__${JSON.stringify(args)}` : id;
   }
 }
 
-module.exports = {
-  L10N: new L10N(),
-};
+// Export the class
+exports.FluentL10n = FluentL10n;
--- a/devtools/client/application/test/components/jest.config.js
+++ b/devtools/client/application/test/components/jest.config.js
@@ -4,20 +4,19 @@
 "use strict";
 
 /* global __dirname */
 
 module.exports = {
   verbose: true,
   moduleNameMapper: {
     // Custom name mappers for modules that require m-c specific API.
-    "^../utils/l10n": `${__dirname}/fixtures/l10n`,
     "^devtools/client/shared/link": `${__dirname}/fixtures/stub`,
-    "^devtools/shared/plural-form": `${__dirname}/fixtures/plural-form`,
     "^chrome": `${__dirname}/fixtures/Chrome`,
     "^Services": `${__dirname}/fixtures/Services`,
+    "^devtools/client/shared/fluent-l10n/fluent-l10n$": `${__dirname}/fixtures/fluent-l10n`,
     "^devtools/client/shared/unicode-url": `${__dirname}/fixtures/unicode-url`,
     // Map all require("devtools/...") to the real devtools root.
     "^devtools\\/(.*)": `${__dirname}/../../../../$1`,
   },
   setupFiles: ["<rootDir>setup.js"],
   snapshotSerializers: ["enzyme-to-json/serializer"],
 };