Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
zjsunit: Add unmock_module function.
Anders Kaseorgf4d38bc39f44
diff --git a/frontend_tests/node_tests/tutorial.js b/frontend_tests/node_tests/tutorial.jsindex 0eefdae95b9..0b30198b092 100644--- a/frontend_tests/node_tests/tutorial.js+++ b/frontend_tests/node_tests/tutorial.js@@ -9,7 +9,13 @@// become clear as you keep reading.const {strict: assert} = require("assert");-const {mock_module, set_global, with_field, zrequire} = require("../zjsunit/namespace");+const {+ mock_module,+ set_global,+ unmock_module,+ with_field,+ zrequire,+} = require("../zjsunit/namespace");const {make_stub} = require("../zjsunit/stub");const {run_test} = require("../zjsunit/test");@@ -581,6 +587,7 @@ run_test("explore make_stub", (override) => {*/+unmock_module("unread_ops");unread_ops = zrequire("unread_ops");run_test("unread_ops", (override) => {@@ -679,6 +686,7 @@ run_test("unread_ops", (override) => {*/+unmock_module("stream_list");stream_list = zrequire("stream_list");const social_stream = {diff --git a/frontend_tests/zjsunit/namespace.js b/frontend_tests/zjsunit/namespace.jsindex bb92f95e273..a00bdfe6b5e 100644--- a/frontend_tests/zjsunit/namespace.js+++ b/frontend_tests/zjsunit/namespace.js@@ -70,6 +70,22 @@ exports.mock_module = (short_fn, obj) => {return obj;};+exports.unmock_module = (short_fn) => {+ const base_path = path.resolve("./static/js");+ const long_fn = path.join(base_path, short_fn);++ if (!module_mocks.has(long_fn)) {+ throw new Error(`Cannot unmock ${long_fn}, which was not mocked`);+ }++ if (!used_module_mocks.has(long_fn)) {+ throw new Error(`You asked to mock ${long_fn} but we never saw it during compilation.`);+ }++ module_mocks.delete(long_fn);+ used_module_mocks.delete(long_fn);+};+exports.set_global = function (name, val) {if (val === null) {throw new Error(`@@ -113,10 +129,7 @@ exports.finish = function () {for (const fn of module_mocks.keys()) {if (!used_module_mocks.has(fn)) {- throw new Error(`- You asked to mock ${fn} but we never- saw it during compilation.- `);+ throw new Error(`You asked to mock ${fn} but we never saw it during compilation.`);}}