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: Defer run_test execution to the end of the test module.

Anders Kaseorg485fe8556e7a
diff --git a/frontend_tests/node_tests/compose.js b/frontend_tests/node_tests/compose.js
index c8d05be2a26..bf845fc3d1f 100644
--- a/frontend_tests/node_tests/compose.js
+++ b/frontend_tests/node_tests/compose.js
@@ -966,4 +966,6 @@ test_ui("narrow_button_titles", () => {
);
});
-MockDate.reset();
+run_test("reset MockDate", () => {
+ MockDate.reset();
+});
diff --git a/frontend_tests/node_tests/echo.js b/frontend_tests/node_tests/echo.js
index 7ca02698a8e..6c9a6631e73 100644
--- a/frontend_tests/node_tests/echo.js
+++ b/frontend_tests/node_tests/echo.js
@@ -324,4 +324,6 @@ run_test("test reify_message_id", ({override, override_rewire}) => {
assert.ok(draft_deleted);
});
-MockDate.reset();
+run_test("reset MockDate", () => {
+ MockDate.reset();
+});
diff --git a/frontend_tests/node_tests/people.js b/frontend_tests/node_tests/people.js
index f9d245d8a09..502b6b31dd5 100644
--- a/frontend_tests/node_tests/people.js
+++ b/frontend_tests/node_tests/people.js
@@ -634,8 +634,6 @@ test_people("filtered_users", () => {
assert.ok(filtered_people.has(linus.user_id));
});
-people.init();
-
test_people("multi_user_methods", () => {
people.add_active_user(emp401);
people.add_active_user(emp402);
@@ -1202,4 +1200,6 @@ test_people("huddle_string", () => {
});
// reset to native Date()
-MockDate.reset();
+run_test("reset MockDate", () => {
+ MockDate.reset();
+});
diff --git a/frontend_tests/node_tests/stream_list.js b/frontend_tests/node_tests/stream_list.js
index 9f663f1d334..b33b83baaac 100644
--- a/frontend_tests/node_tests/stream_list.js
+++ b/frontend_tests/node_tests/stream_list.js
@@ -17,7 +17,9 @@ let num_unread_for_stream;
const noop = () => {};
-const narrow_state = mock_esm("../../static/js/narrow_state");
+mock_esm("../../static/js/narrow_state", {
+ active: () => false,
+});
const topic_list = mock_esm("../../static/js/topic_list");
mock_esm("../../static/js/keydown_util", {
handle: noop,
@@ -627,8 +629,6 @@ test_ui("separators_only_pinned", ({mock_template}) => {
assert.ok(pinned_subheader_flag);
});
-narrow_state.active = () => false;
-
test_ui("rename_stream", ({mock_template}) => {
create_stream_subheader({mock_template});
initialize_stream_data();
diff --git a/frontend_tests/node_tests/watchdog.js b/frontend_tests/node_tests/watchdog.js
index ae7249022ae..e22b24cde39 100644
--- a/frontend_tests/node_tests/watchdog.js
+++ b/frontend_tests/node_tests/watchdog.js
@@ -68,4 +68,6 @@ run_test("suspect_offline", () => {
assert.ok(!watchdog.suspects_user_is_offline());
});
-MockDate.reset();
+run_test("reset MockDate", () => {
+ MockDate.reset();
+});
diff --git a/frontend_tests/zjsunit/index.js b/frontend_tests/zjsunit/index.js
index c5d59eb449e..def22d08b5f 100644
--- a/frontend_tests/zjsunit/index.js
+++ b/frontend_tests/zjsunit/index.js
@@ -94,7 +94,11 @@ function run_one_module(file) {
zjquery.clear_all_elements();
console.info("running test " + path.basename(file, ".js"));
test.set_current_file_name(file);
+ test.suite.length = 0;
require(file);
+ for (const f of test.suite) {
+ f();
+ }
namespace.complain_about_unused_mocks();
}
diff --git a/frontend_tests/zjsunit/test.js b/frontend_tests/zjsunit/test.js
index 8207a69fb32..0b1532309f8 100644
--- a/frontend_tests/zjsunit/test.js
+++ b/frontend_tests/zjsunit/test.js
@@ -16,7 +16,9 @@ exports.set_verbose = (value) => {
verbose = value;
};
-exports.run_test = (label, f, opts) => {
+exports.suite = [];
+
+function execute_test(label, f, opts) {
const {sloppy_$} = opts || {};
/* istanbul ignore if */
@@ -46,4 +48,8 @@ exports.run_test = (label, f, opts) => {
}
// defensively reset blueslip after each test.
zblueslip.reset();
+}
+
+exports.run_test = (label, f, opts) => {
+ exports.suite.push(() => execute_test(label, f, opts));
};