js: Convert static/js/i18n.js to ES6 module.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg
2021-03-25 13:38:40 -07:00
committed by Tim Abbott
parent 40c3d07b2c
commit bb1b2048bd
82 changed files with 106 additions and 9 deletions

View File

@@ -1,6 +1,7 @@
"use strict";
exports.t = function (str, context) {
exports.i18n = {};
exports.i18n.t = function (str, context) {
// HAPPY PATH: most translations are a simple string:
if (context === undefined) {
return "translated: " + str;

View File

@@ -89,7 +89,8 @@ try {
namespace.mock_esm("../../static/js/blueslip", blueslip);
require("../../static/js/blueslip");
namespace.set_global("i18n", stub_i18n);
namespace.mock_esm("../../static/js/i18n", stub_i18n);
require("../../static/js/i18n");
run_one_module(file);

View File

@@ -93,6 +93,25 @@ exports.mock_esm = (request, obj = {}) => {
return exports.mock_cjs(request, {...obj, __esModule: true});
};
exports.unmock_module = (request) => {
const filename = Module._resolveFilename(
request,
require.cache[callsites()[1].getFileName()],
false,
);
if (!module_mocks.has(filename)) {
throw new Error(`Cannot unmock ${filename}, which was not mocked`);
}
if (!used_module_mocks.has(filename)) {
throw new Error(`You asked to mock ${filename} but we never saw it during compilation.`);
}
module_mocks.delete(filename);
used_module_mocks.delete(filename);
};
exports.set_global = function (name, val) {
if (val === null) {
throw new Error(`