From a4a233b189c5eeb2b474f68deb7359d3a10a00eb Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Wed, 17 Aug 2022 17:13:22 -0700 Subject: [PATCH] zjsunit: Support asynchronous tests. Signed-off-by: Anders Kaseorg --- frontend_tests/zjsunit/index.js | 12 ++++++------ frontend_tests/zjsunit/test.js | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/frontend_tests/zjsunit/index.js b/frontend_tests/zjsunit/index.js index def22d08b5..2511e65d00 100644 --- a/frontend_tests/zjsunit/index.js +++ b/frontend_tests/zjsunit/index.js @@ -89,7 +89,7 @@ function short_tb(tb) { require("../../static/js/templates"); // register Zulip extensions -function run_one_module(file) { +async function run_one_module(file) { zjquery.clear_initialize_function(); zjquery.clear_all_elements(); console.info("running test " + path.basename(file, ".js")); @@ -97,14 +97,14 @@ function run_one_module(file) { test.suite.length = 0; require(file); for (const f of test.suite) { - f(); + await f(); } namespace.complain_about_unused_mocks(); } test.set_verbose(files.length === 1); -try { +(async () => { for (const file of files) { namespace.start(); namespace.set_global("window", window); @@ -129,7 +129,7 @@ try { namespace.mock_esm("../../static/js/realm_user_settings_defaults", zpage_params); require("../../static/js/realm_user_settings_defaults"); - run_one_module(file); + await run_one_module(file); if (blueslip.reset) { blueslip.reset(); @@ -137,7 +137,7 @@ try { namespace.finish(); } -} catch (error) /* istanbul ignore next */ { +})().catch((error) => /* istanbul ignore next */ { if (process.env.USING_INSTRUMENTED_CODE) { console.info(` TEST FAILED! Before using the --coverage option please make sure that your @@ -150,4 +150,4 @@ try { console.info(error); } process.exit(1); -} +}); diff --git a/frontend_tests/zjsunit/test.js b/frontend_tests/zjsunit/test.js index 0b1532309f..94917945e8 100644 --- a/frontend_tests/zjsunit/test.js +++ b/frontend_tests/zjsunit/test.js @@ -18,7 +18,7 @@ exports.set_verbose = (value) => { exports.suite = []; -function execute_test(label, f, opts) { +async function execute_test(label, f, opts) { const {sloppy_$} = opts || {}; /* istanbul ignore if */ @@ -33,8 +33,8 @@ function execute_test(label, f, opts) { try { namespace._start_template_mocking(); - namespace.with_overrides((helpers) => { - f({ + await namespace.with_overrides(async (helpers) => { + await f({ ...helpers, mock_template: namespace._mock_template, });