zjsunit: Remove objs_installed flag.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2021-03-09 21:03:25 -08:00 committed by Steve Howell
parent 1689c57cc4
commit 1b58f5a700
1 changed files with 4 additions and 12 deletions

View File

@ -7,7 +7,6 @@ const new_globals = new Set();
let old_globals = {};
let actual_load;
let objs_installed;
const module_mocks = new Map();
const used_module_mocks = new Set();
@ -28,7 +27,6 @@ exports.start = () => {
actual_load = Module._load;
Module._load = load;
objs_installed = false;
module_mocks.clear();
used_module_mocks.clear();
};
@ -48,15 +46,6 @@ exports.mock_module = (short_fn, obj) => {
We just assume the file is under static/js.
`);
}
if (objs_installed) {
throw new Error(`
It is too late to install this mock. Consider instead:
foo.__Rewire__("${short_fn}", ...)
Or call this earlier.
`);
}
const filename = require.resolve(`../../static/js/${short_fn}`);
@ -64,6 +53,10 @@ exports.mock_module = (short_fn, obj) => {
throw new Error(`You already set up a mock for ${filename}`);
}
if (filename in require.cache) {
throw new Error(`It is too late to mock ${filename}; call this earlier.`);
}
obj.__esModule = true;
module_mocks.set(filename, obj);
return obj;
@ -102,7 +95,6 @@ exports.set_global = function (name, val) {
};
exports.zrequire = function (short_fn) {
objs_installed = true;
return require(`../../static/js/${short_fn}`);
};