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: Use __Rewire__ for ES modules in override.

Anders Kaseorg8985b5ffc78f
diff --git a/frontend_tests/zjsunit/namespace.js b/frontend_tests/zjsunit/namespace.js
index 965ad88d0f1..62cc51fc676 100644
--- a/frontend_tests/zjsunit/namespace.js
+++ b/frontend_tests/zjsunit/namespace.js
@@ -144,7 +144,10 @@ exports.with_overrides = function (test_function) {
unused_funcs.get(obj).set(func_name, true);
- let old_f = obj[func_name];
+ let old_f =
+ "__esModule" in obj && "__Rewire__" in obj && !(func_name in obj)
+ ? obj.__GetDependency__(func_name)
+ : obj[func_name];
if (old_f === undefined) {
// Create a dummy function so that we can
// attach _patched_with_override to it.
@@ -163,13 +166,19 @@ exports.with_overrides = function (test_function) {
// code can also use this, as needed.)
new_f._patched_with_override = true;
- obj[func_name] = new_f;
-
- restore_callbacks.push(() => {
- old_f._patched_with_override = true;
- obj[func_name] = old_f;
- delete old_f._patched_with_override;
- });
+ if ("__esModule" in obj && "__Rewire__" in obj) {
+ obj.__Rewire__(func_name, new_f);
+ restore_callbacks.push(() => {
+ obj.__Rewire__(func_name, old_f);
+ });
+ } else {
+ obj[func_name] = new_f;
+ restore_callbacks.push(() => {
+ old_f._patched_with_override = true;
+ obj[func_name] = old_f;
+ delete old_f._patched_with_override;
+ });
+ }
};
try {