mirror of https://github.com/zulip/zulip.git
zjsunit: Use __Rewire__ for ES modules in override.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
parent
a6510789c9
commit
8985b5ffc7
|
@ -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;
|
||||
|
||||
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 {
|
||||
|
|
Loading…
Reference in New Issue