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 with_field.

Anders Kaseorgdb50451a5a84
diff --git a/frontend_tests/zjsunit/namespace.js b/frontend_tests/zjsunit/namespace.js
index 62cc51fc676..4d95b8fb8f1 100644
--- a/frontend_tests/zjsunit/namespace.js
+++ b/frontend_tests/zjsunit/namespace.js
@@ -67,16 +67,26 @@ exports.restore = function () {
};
exports.with_field = function (obj, field, val, f) {
- const had_val = Object.prototype.hasOwnProperty.call(obj, field);
- const old_val = obj[field];
- try {
- obj[field] = val;
- return f();
- } finally {
- if (had_val) {
- obj[field] = old_val;
- } else {
- delete obj[field];
+ if ("__esModule" in obj && "__Rewire__" in obj) {
+ const old_val = field in obj ? obj[field] : obj.__GetDependency__(field);
+ try {
+ obj.__Rewire__(field, val);
+ return f();
+ } finally {
+ obj.__Rewire__(field, old_val);
+ }
+ } else {
+ const had_val = Object.prototype.hasOwnProperty.call(obj, field);
+ const old_val = obj[field];
+ try {
+ obj[field] = val;
+ return f();
+ } finally {
+ if (had_val) {
+ obj[field] = old_val;
+ } else {
+ delete obj[field];
+ }
}
}
};