mirror of https://github.com/zulip/zulip.git
zjsunit: Extract complain_about_unused_mocks.
This is prep toward allowing individual tests to fail while continuing to run the test suite. Most of the steps in namespace.finish() could be put in a `finally` block, but once a test fails, there's no reason to complain about unused mocks, since there are bigger things to address.
This commit is contained in:
parent
e0f0b7f4a7
commit
e5669f9087
|
@ -74,6 +74,7 @@ function run_one_module(file) {
|
||||||
console.info("running test " + path.basename(file, ".js"));
|
console.info("running test " + path.basename(file, ".js"));
|
||||||
test.set_current_file_name(file);
|
test.set_current_file_name(file);
|
||||||
require(file);
|
require(file);
|
||||||
|
namespace.complain_about_unused_mocks();
|
||||||
}
|
}
|
||||||
|
|
||||||
test.set_verbose(files.length === 1);
|
test.set_verbose(files.length === 1);
|
||||||
|
|
|
@ -136,6 +136,16 @@ exports.zrequire = function (short_fn) {
|
||||||
const staticPath = path.resolve(__dirname, "../../static") + path.sep;
|
const staticPath = path.resolve(__dirname, "../../static") + path.sep;
|
||||||
const templatesPath = staticPath + "templates" + path.sep;
|
const templatesPath = staticPath + "templates" + path.sep;
|
||||||
|
|
||||||
|
exports.complain_about_unused_mocks = function () {
|
||||||
|
for (const filename of module_mocks.keys()) {
|
||||||
|
if (!used_module_mocks.has(filename)) {
|
||||||
|
throw new Error(
|
||||||
|
`You asked to mock ${filename} but we never saw it during compilation.`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
exports.finish = function () {
|
exports.finish = function () {
|
||||||
/*
|
/*
|
||||||
Handle cleanup tasks after we've run one module.
|
Handle cleanup tasks after we've run one module.
|
||||||
|
@ -151,13 +161,6 @@ exports.finish = function () {
|
||||||
Module._load = actual_load;
|
Module._load = actual_load;
|
||||||
actual_load = undefined;
|
actual_load = undefined;
|
||||||
|
|
||||||
for (const filename of module_mocks.keys()) {
|
|
||||||
if (!used_module_mocks.has(filename)) {
|
|
||||||
throw new Error(
|
|
||||||
`You asked to mock ${filename} but we never saw it during compilation.`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
module_mocks.clear();
|
module_mocks.clear();
|
||||||
used_module_mocks.clear();
|
used_module_mocks.clear();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue