Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

zjsunit: Extract complain_about_unused_mocks.

Steve Howelle5669f90876a
diff --git a/frontend_tests/zjsunit/index.js b/frontend_tests/zjsunit/index.js
index 26e1ae6f6d1..8fe80a406aa 100644
--- a/frontend_tests/zjsunit/index.js
+++ b/frontend_tests/zjsunit/index.js
@@ -74,6 +74,7 @@ function run_one_module(file) {
console.info("running test " + path.basename(file, ".js"));
test.set_current_file_name(file);
require(file);
+ namespace.complain_about_unused_mocks();
}
test.set_verbose(files.length === 1);
diff --git a/frontend_tests/zjsunit/namespace.js b/frontend_tests/zjsunit/namespace.js
index 463d3e55ff9..0301182dc9d 100644
--- a/frontend_tests/zjsunit/namespace.js
+++ b/frontend_tests/zjsunit/namespace.js
@@ -136,6 +136,16 @@ exports.zrequire = function (short_fn) {
const staticPath = path.resolve(__dirname, "../../static") + 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 () {
/*
Handle cleanup tasks after we've run one module.
@@ -151,13 +161,6 @@ exports.finish = function () {
Module._load = actual_load;
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();
used_module_mocks.clear();