Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
zjsunit: Restrict overrides to once-per-function.
Steve Howell16ad65dd66f0
diff --git a/frontend_tests/zjsunit/namespace.js b/frontend_tests/zjsunit/namespace.jsindex df778e4462c..4b86c60cc20 100644--- a/frontend_tests/zjsunit/namespace.js+++ b/frontend_tests/zjsunit/namespace.js@@ -96,15 +96,31 @@ exports.with_overrides = function (test_function) {const restore_callbacks = [];const unused_funcs = new Map();+ const funcs = new Map();const override = function (module, func_name, f) {if (typeof f !== "function") {throw new TypeError("You can only override with a function.");}+ if (!funcs.has(module)) {+ funcs.set(module, new Map());+ }++ if (funcs.get(module).has(func_name)) {+ // Prevent overriding the same function twice, so that+ // it's super easy to reason about our logic to restore+ // the original function. Usually if somebody sees this+ // error, it's a symptom of not breaking up tests enough.+ throw new Error("You can only override a function one time.");+ }++ funcs.get(module).set(func_name, true);+if (!unused_funcs.has(module)) {unused_funcs.set(module, new Map());}+unused_funcs.get(module).set(func_name, true);const old_f = module[func_name];