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: Handle exceptions in with_field, with_overrides.

Anders Kaseorg58b18fd49956
diff --git a/frontend_tests/zjsunit/namespace.js b/frontend_tests/zjsunit/namespace.js
index 83c68586699..dc657fa8f52 100644
--- a/frontend_tests/zjsunit/namespace.js
+++ b/frontend_tests/zjsunit/namespace.js
@@ -68,10 +68,12 @@ exports.restore = function () {
exports.with_field = function (obj, field, val, f) {
const old_val = obj[field];
- obj[field] = val;
- const result = f();
- obj[field] = old_val;
- return result;
+ try {
+ obj[field] = val;
+ return f();
+ } finally {
+ obj[field] = old_val;
+ }
};
exports.with_overrides = function (test_function) {
@@ -165,11 +167,13 @@ exports.with_overrides = function (test_function) {
});
};
- test_function(override);
-
- restore_callbacks.reverse();
- for (const restore_callback of restore_callbacks) {
- restore_callback();
+ try {
+ test_function(override);
+ } finally {
+ restore_callbacks.reverse();
+ for (const restore_callback of restore_callbacks) {
+ restore_callback();
+ }
}
for (const module_unused_funcs of unused_funcs.values()) {