diff --git a/.eslintrc.json b/.eslintrc.json index 8b256ce349..cf3876cbde 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -362,11 +362,7 @@ "files": ["frontend_tests/**"], "globals": { "document": false, - "reset_module": false, - "set_global": false, - "window": false, - "with_field": false, - "zrequire": false + "window": false }, "rules": { "no-sync": "off" diff --git a/frontend_tests/node_tests/activity.js b/frontend_tests/node_tests/activity.js index dd5dac640c..3067442198 100644 --- a/frontend_tests/node_tests/activity.js +++ b/frontend_tests/node_tests/activity.js @@ -2,6 +2,8 @@ const {strict: assert} = require("assert"); +const {set_global, zrequire} = require("../zjsunit/namespace"); + set_global("$", global.make_zjquery()); const window_stub = $.create("window-stub"); set_global("to_$", () => window_stub); diff --git a/frontend_tests/node_tests/alert_words.js b/frontend_tests/node_tests/alert_words.js index c3f00f4088..4b13cb1eb7 100644 --- a/frontend_tests/node_tests/alert_words.js +++ b/frontend_tests/node_tests/alert_words.js @@ -2,6 +2,8 @@ const {strict: assert} = require("assert"); +const {zrequire} = require("../zjsunit/namespace"); + const params = { alert_words: ["alertone", "alerttwo", "alertthree", "al*rt.*s", ".+", "emoji"], }; diff --git a/frontend_tests/node_tests/alert_words_ui.js b/frontend_tests/node_tests/alert_words_ui.js index 3d7f9b305b..42b34e2b62 100644 --- a/frontend_tests/node_tests/alert_words_ui.js +++ b/frontend_tests/node_tests/alert_words_ui.js @@ -2,6 +2,8 @@ const {strict: assert} = require("assert"); +const {set_global, zrequire} = require("../zjsunit/namespace"); + set_global("$", global.make_zjquery()); set_global("channel", {}); diff --git a/frontend_tests/node_tests/billing.js b/frontend_tests/node_tests/billing.js index a3c3de5db3..7716a583fd 100644 --- a/frontend_tests/node_tests/billing.js +++ b/frontend_tests/node_tests/billing.js @@ -5,6 +5,8 @@ const fs = require("fs"); const {JSDOM} = require("jsdom"); +const {set_global, zrequire} = require("../zjsunit/namespace"); + const noop = () => {}; const template = fs.readFileSync("templates/corporate/billing.html", "utf-8"); const dom = new JSDOM(template, {pretendToBeVisual: true}); diff --git a/frontend_tests/node_tests/billing_helpers.js b/frontend_tests/node_tests/billing_helpers.js index 978435ef32..028e4f7196 100644 --- a/frontend_tests/node_tests/billing_helpers.js +++ b/frontend_tests/node_tests/billing_helpers.js @@ -6,6 +6,8 @@ const fs = require("fs"); const JQuery = require("jquery"); const {JSDOM} = require("jsdom"); +const {set_global, zrequire} = require("../zjsunit/namespace"); + const template = fs.readFileSync("templates/corporate/upgrade.html", "utf-8"); const dom = new JSDOM(template, {pretendToBeVisual: true}); const jquery = JQuery(dom.window); diff --git a/frontend_tests/node_tests/blueslip_stacktrace.js b/frontend_tests/node_tests/blueslip_stacktrace.js index a21d9e1c64..a821469ef2 100644 --- a/frontend_tests/node_tests/blueslip_stacktrace.js +++ b/frontend_tests/node_tests/blueslip_stacktrace.js @@ -2,6 +2,8 @@ const {strict: assert} = require("assert"); +const {zrequire} = require("../zjsunit/namespace"); + const blueslip_stacktrace = zrequire("blueslip_stacktrace"); run_test("clean_path", () => { diff --git a/frontend_tests/node_tests/bot_data.js b/frontend_tests/node_tests/bot_data.js index d4e594e20f..b4bbfbcb09 100644 --- a/frontend_tests/node_tests/bot_data.js +++ b/frontend_tests/node_tests/bot_data.js @@ -2,6 +2,8 @@ const {strict: assert} = require("assert"); +const {set_global, zrequire} = require("../zjsunit/namespace"); + const _settings_bots = { render_bots: () => {}, }; diff --git a/frontend_tests/node_tests/buddy_data.js b/frontend_tests/node_tests/buddy_data.js index b36d751a05..5fd573ac26 100644 --- a/frontend_tests/node_tests/buddy_data.js +++ b/frontend_tests/node_tests/buddy_data.js @@ -4,6 +4,8 @@ const {strict: assert} = require("assert"); const _ = require("lodash"); +const {set_global, zrequire} = require("../zjsunit/namespace"); + const _page_params = {}; set_global("page_params", _page_params); diff --git a/frontend_tests/node_tests/buddy_list.js b/frontend_tests/node_tests/buddy_list.js index bd71d7ef3f..015e871c42 100644 --- a/frontend_tests/node_tests/buddy_list.js +++ b/frontend_tests/node_tests/buddy_list.js @@ -4,6 +4,8 @@ const {strict: assert} = require("assert"); const _ = require("lodash"); +const {set_global, zrequire} = require("../zjsunit/namespace"); + set_global("$", global.make_zjquery()); const people = zrequire("people"); zrequire("buddy_data"); diff --git a/frontend_tests/node_tests/channel.js b/frontend_tests/node_tests/channel.js index 6b87121305..d0525e1bcd 100644 --- a/frontend_tests/node_tests/channel.js +++ b/frontend_tests/node_tests/channel.js @@ -4,6 +4,8 @@ const {strict: assert} = require("assert"); const _ = require("lodash"); +const {set_global, zrequire} = require("../zjsunit/namespace"); + set_global("$", {}); set_global("reload", {}); @@ -249,7 +251,7 @@ run_test("retry", () => { }, check_ajax_options(options) { - global.patch_builtin("setTimeout", (f, delay) => { + set_global("setTimeout", (f, delay) => { assert.equal(delay, 0); f(); }); diff --git a/frontend_tests/node_tests/color_data.js b/frontend_tests/node_tests/color_data.js index dce99ec987..da93028267 100644 --- a/frontend_tests/node_tests/color_data.js +++ b/frontend_tests/node_tests/color_data.js @@ -2,6 +2,8 @@ const {strict: assert} = require("assert"); +const {zrequire} = require("../zjsunit/namespace"); + zrequire("color_data"); run_test("pick_color", () => { diff --git a/frontend_tests/node_tests/colorspace.js b/frontend_tests/node_tests/colorspace.js index 1eccb53e12..8b5621ba6a 100644 --- a/frontend_tests/node_tests/colorspace.js +++ b/frontend_tests/node_tests/colorspace.js @@ -2,6 +2,8 @@ const {strict: assert} = require("assert"); +const {zrequire} = require("../zjsunit/namespace"); + zrequire("colorspace"); run_test("sRGB_to_linear", () => { diff --git a/frontend_tests/node_tests/common.js b/frontend_tests/node_tests/common.js index 2cdc1cf256..0c79474196 100644 --- a/frontend_tests/node_tests/common.js +++ b/frontend_tests/node_tests/common.js @@ -2,6 +2,8 @@ const {strict: assert} = require("assert"); +const {set_global, zrequire} = require("../zjsunit/namespace"); + const noop = () => {}; set_global("$", global.make_zjquery()); diff --git a/frontend_tests/node_tests/components.js b/frontend_tests/node_tests/components.js index 81299fda1b..4aa216ca20 100644 --- a/frontend_tests/node_tests/components.js +++ b/frontend_tests/node_tests/components.js @@ -4,6 +4,8 @@ const {strict: assert} = require("assert"); const _ = require("lodash"); +const {set_global, zrequire} = require("../zjsunit/namespace"); + zrequire("keydown_util"); zrequire("components"); diff --git a/frontend_tests/node_tests/compose.js b/frontend_tests/node_tests/compose.js index f438f4d68d..8c3ffc5376 100644 --- a/frontend_tests/node_tests/compose.js +++ b/frontend_tests/node_tests/compose.js @@ -5,6 +5,8 @@ const {strict: assert} = require("assert"); const {JSDOM} = require("jsdom"); const rewiremock = require("rewiremock/node"); +const {set_global, zrequire} = require("../zjsunit/namespace"); + const events = require("./lib/events"); set_global("bridge", false); @@ -721,7 +723,7 @@ run_test("send_message", () => { return stub_state; } - global.patch_builtin("setTimeout", (func) => { + set_global("setTimeout", (func) => { func(); }); global.server_events = { diff --git a/frontend_tests/node_tests/compose_actions.js b/frontend_tests/node_tests/compose_actions.js index 8007f66297..4e00f8e710 100644 --- a/frontend_tests/node_tests/compose_actions.js +++ b/frontend_tests/node_tests/compose_actions.js @@ -2,6 +2,8 @@ const {strict: assert} = require("assert"); +const {set_global, zrequire} = require("../zjsunit/namespace"); + const noop = function () {}; const return_false = function () { return false; diff --git a/frontend_tests/node_tests/compose_fade.js b/frontend_tests/node_tests/compose_fade.js index 3198ae15b5..61305c89b3 100644 --- a/frontend_tests/node_tests/compose_fade.js +++ b/frontend_tests/node_tests/compose_fade.js @@ -2,6 +2,8 @@ const {strict: assert} = require("assert"); +const {zrequire} = require("../zjsunit/namespace"); + zrequire("stream_data"); const people = zrequire("people"); zrequire("compose_fade"); diff --git a/frontend_tests/node_tests/compose_pm_pill.js b/frontend_tests/node_tests/compose_pm_pill.js index 9fb7e37437..5374a929d0 100644 --- a/frontend_tests/node_tests/compose_pm_pill.js +++ b/frontend_tests/node_tests/compose_pm_pill.js @@ -2,6 +2,8 @@ const {strict: assert} = require("assert"); +const {set_global, zrequire} = require("../zjsunit/namespace"); + set_global("$", global.make_zjquery()); const people = zrequire("people"); diff --git a/frontend_tests/node_tests/compose_ui.js b/frontend_tests/node_tests/compose_ui.js index cd3ce813d0..c70cb03980 100644 --- a/frontend_tests/node_tests/compose_ui.js +++ b/frontend_tests/node_tests/compose_ui.js @@ -4,6 +4,8 @@ const {strict: assert} = require("assert"); const autosize = require("autosize"); +const {set_global, with_field, zrequire} = require("../zjsunit/namespace"); + zrequire("compose_ui"); const people = zrequire("people"); zrequire("user_status"); diff --git a/frontend_tests/node_tests/composebox_typeahead.js b/frontend_tests/node_tests/composebox_typeahead.js index 7711a124a0..d562ee27cc 100644 --- a/frontend_tests/node_tests/composebox_typeahead.js +++ b/frontend_tests/node_tests/composebox_typeahead.js @@ -2,6 +2,8 @@ const {strict: assert} = require("assert"); +const {set_global, zrequire} = require("../zjsunit/namespace"); + const emoji = zrequire("emoji", "shared/js/emoji"); const typeahead = zrequire("typeahead", "shared/js/typeahead"); zrequire("compose_state"); @@ -331,7 +333,7 @@ run_test("content_typeahead_selected", () => { }, }); let set_timeout_called = false; - global.patch_builtin("setTimeout", (f, time) => { + set_global("setTimeout", (f, time) => { f(); assert.equal(time, 0); set_timeout_called = true; diff --git a/frontend_tests/node_tests/copy_and_paste.js b/frontend_tests/node_tests/copy_and_paste.js index a5efdab187..fb81f4b03d 100644 --- a/frontend_tests/node_tests/copy_and_paste.js +++ b/frontend_tests/node_tests/copy_and_paste.js @@ -2,15 +2,17 @@ const {strict: assert} = require("assert"); -global.stub_out_jquery(); +const {JSDOM} = require("jsdom"); + +const {set_global, stub_out_jquery, zrequire} = require("../zjsunit/namespace"); + +stub_out_jquery(); set_global("page_params", { development_environment: true, }); set_global("compose_ui", {}); -const {JSDOM} = require("jsdom"); - const {window} = new JSDOM("

Hello world

"); const {DOMParser, document} = window; set_global("$", require("jquery")(window)); diff --git a/frontend_tests/node_tests/dispatch.js b/frontend_tests/node_tests/dispatch.js index 80d4db25c4..1993e7fe78 100644 --- a/frontend_tests/node_tests/dispatch.js +++ b/frontend_tests/node_tests/dispatch.js @@ -2,6 +2,8 @@ const {strict: assert} = require("assert"); +const {set_global, zrequire} = require("../zjsunit/namespace"); + const noop = function () {}; const events = require("./lib/events"); @@ -14,7 +16,7 @@ const typing_person1 = events.typing_person1; set_global("$", global.make_zjquery()); -global.patch_builtin("setTimeout", (func) => func()); +set_global("setTimeout", (func) => func()); set_global("activity", {}); set_global("alert_words_ui", {}); diff --git a/frontend_tests/node_tests/dispatch_subs.js b/frontend_tests/node_tests/dispatch_subs.js index b7df0b384f..892104fb14 100644 --- a/frontend_tests/node_tests/dispatch_subs.js +++ b/frontend_tests/node_tests/dispatch_subs.js @@ -2,6 +2,8 @@ const {strict: assert} = require("assert"); +const {set_global, zrequire} = require("../zjsunit/namespace"); + const events = require("./lib/events"); const event_fixtures = events.fixtures; diff --git a/frontend_tests/node_tests/drafts.js b/frontend_tests/node_tests/drafts.js index 3166e979fc..8928fe8f1a 100644 --- a/frontend_tests/node_tests/drafts.js +++ b/frontend_tests/node_tests/drafts.js @@ -4,6 +4,8 @@ const {strict: assert} = require("assert"); const XDate = require("xdate"); +const {set_global, with_field, zrequire} = require("../zjsunit/namespace"); + set_global("$", global.make_zjquery()); zrequire("localstorage"); diff --git a/frontend_tests/node_tests/dropdown_list_widget.js b/frontend_tests/node_tests/dropdown_list_widget.js index 91022c0c00..9898c75ea9 100644 --- a/frontend_tests/node_tests/dropdown_list_widget.js +++ b/frontend_tests/node_tests/dropdown_list_widget.js @@ -2,6 +2,8 @@ const {strict: assert} = require("assert"); +const {set_global, zrequire} = require("../zjsunit/namespace"); + zrequire("dropdown_list_widget"); zrequire("scroll_util"); set_global("$", global.make_zjquery()); diff --git a/frontend_tests/node_tests/echo.js b/frontend_tests/node_tests/echo.js index 0df5ef8610..665c5e30bd 100644 --- a/frontend_tests/node_tests/echo.js +++ b/frontend_tests/node_tests/echo.js @@ -2,6 +2,8 @@ const {strict: assert} = require("assert"); +const {set_global, zrequire} = require("../zjsunit/namespace"); + set_global("$", global.make_zjquery()); set_global("markdown", {}); set_global("local_message", { diff --git a/frontend_tests/node_tests/emoji.js b/frontend_tests/node_tests/emoji.js index 81a37dc030..51d0f767af 100644 --- a/frontend_tests/node_tests/emoji.js +++ b/frontend_tests/node_tests/emoji.js @@ -2,6 +2,8 @@ const {strict: assert} = require("assert"); +const {zrequire} = require("../zjsunit/namespace"); + const emoji_codes = zrequire("emoji_codes", "generated/emoji/emoji_codes.json"); const events = require("./lib/events"); diff --git a/frontend_tests/node_tests/emoji_picker.js b/frontend_tests/node_tests/emoji_picker.js index 2c2c79a3a6..29a07d49b0 100644 --- a/frontend_tests/node_tests/emoji_picker.js +++ b/frontend_tests/node_tests/emoji_picker.js @@ -4,6 +4,8 @@ const {strict: assert} = require("assert"); const _ = require("lodash"); +const {zrequire} = require("../zjsunit/namespace"); + const emoji = zrequire("emoji", "shared/js/emoji"); zrequire("emoji_picker"); diff --git a/frontend_tests/node_tests/fenced_code.js b/frontend_tests/node_tests/fenced_code.js index 50c18d3f85..2bc56da6d1 100644 --- a/frontend_tests/node_tests/fenced_code.js +++ b/frontend_tests/node_tests/fenced_code.js @@ -2,6 +2,8 @@ const {strict: assert} = require("assert"); +const {zrequire} = require("../zjsunit/namespace"); + const fenced_code = zrequire("fenced_code", "shared/js/fenced_code"); run_test("get_unused_fence", () => { diff --git a/frontend_tests/node_tests/fetch_status.js b/frontend_tests/node_tests/fetch_status.js index 5c5eb02c22..144d946e22 100644 --- a/frontend_tests/node_tests/fetch_status.js +++ b/frontend_tests/node_tests/fetch_status.js @@ -2,6 +2,8 @@ const {strict: assert} = require("assert"); +const {set_global, zrequire} = require("../zjsunit/namespace"); + const FetchStatus = zrequire("fetch_status"); set_global("message_scroll", { hide_loading_older: () => {}, diff --git a/frontend_tests/node_tests/filter.js b/frontend_tests/node_tests/filter.js index 73be82a877..9087c078d4 100644 --- a/frontend_tests/node_tests/filter.js +++ b/frontend_tests/node_tests/filter.js @@ -2,10 +2,12 @@ const {strict: assert} = require("assert"); +const {set_global, stub_out_jquery, zrequire} = require("../zjsunit/namespace"); + zrequire("unread"); zrequire("stream_data"); const people = zrequire("people"); -global.stub_out_jquery(); +stub_out_jquery(); set_global("$", global.make_zjquery()); zrequire("message_util", "js/message_util"); zrequire("Filter", "js/filter"); diff --git a/frontend_tests/node_tests/fold_dict.js b/frontend_tests/node_tests/fold_dict.js index 24fb5d1884..6c6cbff6cf 100644 --- a/frontend_tests/node_tests/fold_dict.js +++ b/frontend_tests/node_tests/fold_dict.js @@ -2,6 +2,8 @@ const {strict: assert} = require("assert"); +const {zrequire} = require("../zjsunit/namespace"); + const {FoldDict} = zrequire("fold_dict"); run_test("basic", () => { diff --git a/frontend_tests/node_tests/general.js b/frontend_tests/node_tests/general.js index 39d9425913..1ff02953de 100644 --- a/frontend_tests/node_tests/general.js +++ b/frontend_tests/node_tests/general.js @@ -2,6 +2,8 @@ const {strict: assert} = require("assert"); +const {set_global, zrequire} = require("../zjsunit/namespace"); + // This is a general tour of how to write node tests that // may also give you some quick insight on how the Zulip // browser app is constructed. Let's start with testing diff --git a/frontend_tests/node_tests/hash_util.js b/frontend_tests/node_tests/hash_util.js index 217790b2d3..d9568ff8e4 100644 --- a/frontend_tests/node_tests/hash_util.js +++ b/frontend_tests/node_tests/hash_util.js @@ -2,6 +2,8 @@ const {strict: assert} = require("assert"); +const {set_global, zrequire} = require("../zjsunit/namespace"); + zrequire("hash_util"); zrequire("stream_data"); const people = zrequire("people"); diff --git a/frontend_tests/node_tests/hashchange.js b/frontend_tests/node_tests/hashchange.js index 52ee398e44..e65e2341e6 100644 --- a/frontend_tests/node_tests/hashchange.js +++ b/frontend_tests/node_tests/hashchange.js @@ -2,6 +2,8 @@ const {strict: assert} = require("assert"); +const {set_global, zrequire} = require("../zjsunit/namespace"); + set_global("$", global.make_zjquery()); const window_stub = $.create("window-stub"); set_global("location", { diff --git a/frontend_tests/node_tests/hotkey.js b/frontend_tests/node_tests/hotkey.js index 3293489661..3a2063b52c 100644 --- a/frontend_tests/node_tests/hotkey.js +++ b/frontend_tests/node_tests/hotkey.js @@ -2,6 +2,8 @@ const {strict: assert} = require("assert"); +const {set_global, with_overrides, zrequire} = require("../zjsunit/namespace"); + // Important note on these tests: // // The way the Zulip hotkey tests work is as follows. First, we set @@ -80,7 +82,7 @@ function return_false() { } function stubbing(func_name_to_stub, test_function) { - global.with_overrides((override) => { + with_overrides((override) => { global.with_stub((stub) => { override(func_name_to_stub, stub.f); test_function(stub); diff --git a/frontend_tests/node_tests/i18n.js b/frontend_tests/node_tests/i18n.js index ee5762e18c..69be53840f 100644 --- a/frontend_tests/node_tests/i18n.js +++ b/frontend_tests/node_tests/i18n.js @@ -2,6 +2,8 @@ const {strict: assert} = require("assert"); +const {set_global, zrequire} = require("../zjsunit/namespace"); + zrequire("templates"); // We download our translations in `page_params` (which diff --git a/frontend_tests/node_tests/input_pill.js b/frontend_tests/node_tests/input_pill.js index 90c3922f3a..4fdb8e9927 100644 --- a/frontend_tests/node_tests/input_pill.js +++ b/frontend_tests/node_tests/input_pill.js @@ -2,6 +2,8 @@ const {strict: assert} = require("assert"); +const {set_global, zrequire} = require("../zjsunit/namespace"); + set_global("$", global.make_zjquery()); zrequire("input_pill"); diff --git a/frontend_tests/node_tests/keydown_util.js b/frontend_tests/node_tests/keydown_util.js index a31d2edf74..913946aefc 100644 --- a/frontend_tests/node_tests/keydown_util.js +++ b/frontend_tests/node_tests/keydown_util.js @@ -1,5 +1,7 @@ "use strict"; +const {set_global, zrequire} = require("../zjsunit/namespace"); + set_global("$", global.make_zjquery()); zrequire("keydown_util"); diff --git a/frontend_tests/node_tests/lazy_set.js b/frontend_tests/node_tests/lazy_set.js index f33508e769..d3e1557636 100644 --- a/frontend_tests/node_tests/lazy_set.js +++ b/frontend_tests/node_tests/lazy_set.js @@ -2,6 +2,8 @@ const {strict: assert} = require("assert"); +const {zrequire} = require("../zjsunit/namespace"); + const {LazySet} = zrequire("lazy_set"); /* diff --git a/frontend_tests/node_tests/lightbox.js b/frontend_tests/node_tests/lightbox.js index 508aa02f98..bf0486ed11 100644 --- a/frontend_tests/node_tests/lightbox.js +++ b/frontend_tests/node_tests/lightbox.js @@ -2,6 +2,8 @@ const {strict: assert} = require("assert"); +const {set_global, zrequire} = require("../zjsunit/namespace"); + zrequire("rows"); zrequire("lightbox"); diff --git a/frontend_tests/node_tests/list_cursor.js b/frontend_tests/node_tests/list_cursor.js index ec006d8d16..b3446fd535 100644 --- a/frontend_tests/node_tests/list_cursor.js +++ b/frontend_tests/node_tests/list_cursor.js @@ -2,6 +2,8 @@ const {strict: assert} = require("assert"); +const {zrequire} = require("../zjsunit/namespace"); + zrequire("list_cursor"); run_test("config errors", () => { diff --git a/frontend_tests/node_tests/list_render.js b/frontend_tests/node_tests/list_render.js index 2dcd5ee6f1..827a2eb135 100644 --- a/frontend_tests/node_tests/list_render.js +++ b/frontend_tests/node_tests/list_render.js @@ -2,6 +2,8 @@ const {strict: assert} = require("assert"); +const {set_global, zrequire} = require("../zjsunit/namespace"); + zrequire("list_render"); // We need these stubs to get by instanceof checks. diff --git a/frontend_tests/node_tests/markdown.js b/frontend_tests/node_tests/markdown.js index f2f2ec1acb..078652f62c 100644 --- a/frontend_tests/node_tests/markdown.js +++ b/frontend_tests/node_tests/markdown.js @@ -2,6 +2,8 @@ const {strict: assert} = require("assert"); +const {set_global, with_field, zrequire} = require("../zjsunit/namespace"); + zrequire("hash_util"); const emoji = zrequire("emoji", "shared/js/emoji"); diff --git a/frontend_tests/node_tests/markdown_katex.js b/frontend_tests/node_tests/markdown_katex.js index dc9e6636c1..b209214aa1 100644 --- a/frontend_tests/node_tests/markdown_katex.js +++ b/frontend_tests/node_tests/markdown_katex.js @@ -9,6 +9,8 @@ const rewiremock = require("rewiremock/node"); +const {set_global, zrequire} = require("../zjsunit/namespace"); + const markdown_config = zrequire("markdown_config"); set_global("page_params", {}); diff --git a/frontend_tests/node_tests/message_edit.js b/frontend_tests/node_tests/message_edit.js index 775389586b..f3d21383ad 100644 --- a/frontend_tests/node_tests/message_edit.js +++ b/frontend_tests/node_tests/message_edit.js @@ -2,12 +2,14 @@ const {strict: assert} = require("assert"); +const {set_global, stub_out_jquery, zrequire} = require("../zjsunit/namespace"); + set_global("document", null); set_global("page_params", { realm_community_topic_editing_limit_seconds: 86400, }); -global.stub_out_jquery(); +stub_out_jquery(); zrequire("message_edit"); diff --git a/frontend_tests/node_tests/message_events.js b/frontend_tests/node_tests/message_events.js index a30885de7c..cb55627536 100644 --- a/frontend_tests/node_tests/message_events.js +++ b/frontend_tests/node_tests/message_events.js @@ -2,6 +2,8 @@ const {strict: assert} = require("assert"); +const {set_global, zrequire} = require("../zjsunit/namespace"); + zrequire("message_events"); zrequire("message_store"); zrequire("muting"); diff --git a/frontend_tests/node_tests/message_fetch.js b/frontend_tests/node_tests/message_fetch.js index 690cae239a..6aa4deb187 100644 --- a/frontend_tests/node_tests/message_fetch.js +++ b/frontend_tests/node_tests/message_fetch.js @@ -4,6 +4,8 @@ const {strict: assert} = require("assert"); const _ = require("lodash"); +const {set_global, zrequire} = require("../zjsunit/namespace"); + set_global("$", global.make_zjquery()); set_global("document", "document-stub"); diff --git a/frontend_tests/node_tests/message_flags.js b/frontend_tests/node_tests/message_flags.js index 18087079fa..af8530162d 100644 --- a/frontend_tests/node_tests/message_flags.js +++ b/frontend_tests/node_tests/message_flags.js @@ -2,6 +2,8 @@ const {strict: assert} = require("assert"); +const {set_global, zrequire} = require("../zjsunit/namespace"); + zrequire("unread"); zrequire("unread_ops"); zrequire("message_flags"); diff --git a/frontend_tests/node_tests/message_list.js b/frontend_tests/node_tests/message_list.js index 75a21a98ab..b8c9e6d41a 100644 --- a/frontend_tests/node_tests/message_list.js +++ b/frontend_tests/node_tests/message_list.js @@ -1,6 +1,8 @@ "use strict"; const {strict: assert} = require("assert"); + +const {set_global, stub_out_jquery, zrequire} = require("../zjsunit/namespace"); // These unit tests for static/js/message_list.js emphasize the model-ish // aspects of the MessageList class. We have to stub out a few functions // related to views and events to get the tests working. @@ -8,7 +10,7 @@ const {strict: assert} = require("assert"); const noop = function () {}; set_global("Filter", noop); -global.stub_out_jquery(); +stub_out_jquery(); set_global("document", null); set_global("narrow_state", {}); set_global("stream_data", {}); diff --git a/frontend_tests/node_tests/message_list_data.js b/frontend_tests/node_tests/message_list_data.js index 874e8c130f..034c46eb5d 100644 --- a/frontend_tests/node_tests/message_list_data.js +++ b/frontend_tests/node_tests/message_list_data.js @@ -2,6 +2,8 @@ const {strict: assert} = require("assert"); +const {set_global, zrequire} = require("../zjsunit/namespace"); + zrequire("unread"); zrequire("Filter", "js/filter"); @@ -11,7 +13,7 @@ zrequire("MessageListData", "js/message_list_data"); set_global("page_params", {}); set_global("muting", {}); -global.patch_builtin("setTimeout", (f, delay) => { +set_global("setTimeout", (f, delay) => { assert.equal(delay, 0); return f(); }); diff --git a/frontend_tests/node_tests/message_list_view.js b/frontend_tests/node_tests/message_list_view.js index b2cb072578..6b80e7f12a 100644 --- a/frontend_tests/node_tests/message_list_view.js +++ b/frontend_tests/node_tests/message_list_view.js @@ -4,6 +4,8 @@ const {strict: assert} = require("assert"); const _ = require("lodash"); +const {set_global, zrequire} = require("../zjsunit/namespace"); + set_global("$", global.make_zjquery()); set_global("document", "document-stub"); diff --git a/frontend_tests/node_tests/message_store.js b/frontend_tests/node_tests/message_store.js index 87a93bd985..a5e305b000 100644 --- a/frontend_tests/node_tests/message_store.js +++ b/frontend_tests/node_tests/message_store.js @@ -2,6 +2,8 @@ const {strict: assert} = require("assert"); +const {set_global, zrequire} = require("../zjsunit/namespace"); + const util = zrequire("util"); zrequire("pm_conversations"); const people = zrequire("people"); diff --git a/frontend_tests/node_tests/muting.js b/frontend_tests/node_tests/muting.js index b9ceab6da8..9ea92d6c79 100644 --- a/frontend_tests/node_tests/muting.js +++ b/frontend_tests/node_tests/muting.js @@ -2,6 +2,8 @@ const {strict: assert} = require("assert"); +const {set_global, zrequire} = require("../zjsunit/namespace"); + zrequire("timerender"); zrequire("muting"); zrequire("stream_data"); diff --git a/frontend_tests/node_tests/narrow.js b/frontend_tests/node_tests/narrow.js index 887f16662e..e46ca399d8 100644 --- a/frontend_tests/node_tests/narrow.js +++ b/frontend_tests/node_tests/narrow.js @@ -2,6 +2,8 @@ const {strict: assert} = require("assert"); +const {set_global, zrequire} = require("../zjsunit/namespace"); + set_global("$", global.make_zjquery()); zrequire("hash_util"); zrequire("hashchange"); diff --git a/frontend_tests/node_tests/narrow_activate.js b/frontend_tests/node_tests/narrow_activate.js index 17b8bcc82c..768180d4a5 100644 --- a/frontend_tests/node_tests/narrow_activate.js +++ b/frontend_tests/node_tests/narrow_activate.js @@ -2,6 +2,8 @@ const {strict: assert} = require("assert"); +const {set_global, zrequire} = require("../zjsunit/namespace"); + const util = zrequire("util"); set_global("$", global.make_zjquery()); @@ -54,7 +56,7 @@ set_global("search_pill_widget", { // // We have strange hacks in narrow.activate to sleep 0 // seconds. -global.patch_builtin("setTimeout", (f, t) => { +set_global("setTimeout", (f, t) => { assert.equal(t, 0); f(); }); diff --git a/frontend_tests/node_tests/narrow_local.js b/frontend_tests/node_tests/narrow_local.js index 3833b0c8e2..8a4bdd97bd 100644 --- a/frontend_tests/node_tests/narrow_local.js +++ b/frontend_tests/node_tests/narrow_local.js @@ -2,6 +2,8 @@ const {strict: assert} = require("assert"); +const {set_global, zrequire} = require("../zjsunit/namespace"); + zrequire("Filter", "js/filter"); zrequire("FetchStatus", "js/fetch_status"); zrequire("MessageListData", "js/message_list_data"); diff --git a/frontend_tests/node_tests/narrow_state.js b/frontend_tests/node_tests/narrow_state.js index fce2426b8b..3518734a1e 100644 --- a/frontend_tests/node_tests/narrow_state.js +++ b/frontend_tests/node_tests/narrow_state.js @@ -2,6 +2,8 @@ const {strict: assert} = require("assert"); +const {set_global, zrequire} = require("../zjsunit/namespace"); + const people = zrequire("people"); zrequire("Filter", "js/filter"); zrequire("stream_data"); diff --git a/frontend_tests/node_tests/narrow_unread.js b/frontend_tests/node_tests/narrow_unread.js index c7dae7ed77..08b638e33b 100644 --- a/frontend_tests/node_tests/narrow_unread.js +++ b/frontend_tests/node_tests/narrow_unread.js @@ -2,6 +2,8 @@ const {strict: assert} = require("assert"); +const {set_global, zrequire} = require("../zjsunit/namespace"); + zrequire("Filter", "js/filter"); const people = zrequire("people"); zrequire("stream_data"); diff --git a/frontend_tests/node_tests/notifications.js b/frontend_tests/node_tests/notifications.js index cf08b473ea..b5ca900191 100644 --- a/frontend_tests/node_tests/notifications.js +++ b/frontend_tests/node_tests/notifications.js @@ -4,6 +4,8 @@ const {strict: assert} = require("assert"); const rewiremock = require("rewiremock/node"); +const {set_global, zrequire} = require("../zjsunit/namespace"); + // Dependencies set_global( "$", diff --git a/frontend_tests/node_tests/password.js b/frontend_tests/node_tests/password.js index 9cd8d9177d..e55a679d36 100644 --- a/frontend_tests/node_tests/password.js +++ b/frontend_tests/node_tests/password.js @@ -2,6 +2,8 @@ const {strict: assert} = require("assert"); +const {set_global, zrequire} = require("../zjsunit/namespace"); + set_global("zxcvbn", zrequire("zxcvbn", "zxcvbn")); zrequire("common"); diff --git a/frontend_tests/node_tests/people.js b/frontend_tests/node_tests/people.js index e10ed32292..ca717c2483 100644 --- a/frontend_tests/node_tests/people.js +++ b/frontend_tests/node_tests/people.js @@ -6,6 +6,8 @@ const _ = require("lodash"); const moment = require("moment-timezone"); const rewiremock = require("rewiremock/node"); +const {set_global, zrequire} = require("../zjsunit/namespace"); + const people = rewiremock.proxy(() => zrequire("people"), { "moment-timezone": () => moment("20130208T080910"), }); diff --git a/frontend_tests/node_tests/people_errors.js b/frontend_tests/node_tests/people_errors.js index 370238a68d..24b32537f0 100644 --- a/frontend_tests/node_tests/people_errors.js +++ b/frontend_tests/node_tests/people_errors.js @@ -2,6 +2,8 @@ const {strict: assert} = require("assert"); +const {set_global, zrequire} = require("../zjsunit/namespace"); + const people = zrequire("people"); const return_false = function () { diff --git a/frontend_tests/node_tests/pm_conversations.js b/frontend_tests/node_tests/pm_conversations.js index 52849a5483..70e4c14b9e 100644 --- a/frontend_tests/node_tests/pm_conversations.js +++ b/frontend_tests/node_tests/pm_conversations.js @@ -2,6 +2,8 @@ const {strict: assert} = require("assert"); +const {zrequire} = require("../zjsunit/namespace"); + const pmc = zrequire("pm_conversations"); run_test("partners", () => { diff --git a/frontend_tests/node_tests/pm_list.js b/frontend_tests/node_tests/pm_list.js index ec02a4d629..57109d27df 100644 --- a/frontend_tests/node_tests/pm_list.js +++ b/frontend_tests/node_tests/pm_list.js @@ -2,6 +2,8 @@ const {strict: assert} = require("assert"); +const {set_global, with_field, zrequire} = require("../zjsunit/namespace"); + set_global("$", global.make_zjquery()); set_global("narrow_state", {}); diff --git a/frontend_tests/node_tests/poll_widget.js b/frontend_tests/node_tests/poll_widget.js index ff11a0f551..7b5be2bf3c 100644 --- a/frontend_tests/node_tests/poll_widget.js +++ b/frontend_tests/node_tests/poll_widget.js @@ -2,6 +2,8 @@ const {strict: assert} = require("assert"); +const {set_global, zrequire} = require("../zjsunit/namespace"); + zrequire("poll_widget"); set_global("$", global.make_zjquery()); diff --git a/frontend_tests/node_tests/popovers.js b/frontend_tests/node_tests/popovers.js index dec862f8f1..4fbc620fd3 100644 --- a/frontend_tests/node_tests/popovers.js +++ b/frontend_tests/node_tests/popovers.js @@ -4,6 +4,8 @@ const {strict: assert} = require("assert"); const rewiremock = require("rewiremock/node"); +const {set_global, zrequire} = require("../zjsunit/namespace"); + set_global("$", global.make_zjquery()); zrequire("hash_util"); diff --git a/frontend_tests/node_tests/presence.js b/frontend_tests/node_tests/presence.js index 38c92562cf..7079a6f13f 100644 --- a/frontend_tests/node_tests/presence.js +++ b/frontend_tests/node_tests/presence.js @@ -4,6 +4,8 @@ const {strict: assert} = require("assert"); const XDate = require("xdate"); +const {set_global, zrequire} = require("../zjsunit/namespace"); + const people = zrequire("people"); zrequire("presence"); diff --git a/frontend_tests/node_tests/reactions.js b/frontend_tests/node_tests/reactions.js index 32a42953c1..3178ae5ab7 100644 --- a/frontend_tests/node_tests/reactions.js +++ b/frontend_tests/node_tests/reactions.js @@ -2,6 +2,8 @@ const {strict: assert} = require("assert"); +const {set_global, with_field, zrequire} = require("../zjsunit/namespace"); + set_global("document", "document-stub"); set_global("$", global.make_zjquery()); diff --git a/frontend_tests/node_tests/recent_senders.js b/frontend_tests/node_tests/recent_senders.js index ca22bbaee1..48923606bb 100644 --- a/frontend_tests/node_tests/recent_senders.js +++ b/frontend_tests/node_tests/recent_senders.js @@ -2,6 +2,8 @@ const {strict: assert} = require("assert"); +const {set_global, zrequire} = require("../zjsunit/namespace"); + const rs = zrequire("recent_senders"); let next_id = 0; diff --git a/frontend_tests/node_tests/recent_topics.js b/frontend_tests/node_tests/recent_topics.js index b59e9e765d..3d65615273 100644 --- a/frontend_tests/node_tests/recent_topics.js +++ b/frontend_tests/node_tests/recent_topics.js @@ -2,6 +2,8 @@ const {strict: assert} = require("assert"); +const {reset_module, set_global, zrequire} = require("../zjsunit/namespace"); + zrequire("message_util"); const noop = () => {}; diff --git a/frontend_tests/node_tests/rendered_markdown.js b/frontend_tests/node_tests/rendered_markdown.js index d71111b196..0e754059a3 100644 --- a/frontend_tests/node_tests/rendered_markdown.js +++ b/frontend_tests/node_tests/rendered_markdown.js @@ -2,6 +2,8 @@ const {strict: assert} = require("assert"); +const {set_global, zrequire} = require("../zjsunit/namespace"); + const rm = zrequire("rendered_markdown"); const people = zrequire("people"); zrequire("user_groups"); diff --git a/frontend_tests/node_tests/rtl.js b/frontend_tests/node_tests/rtl.js index 79bf8d478d..27425c852a 100644 --- a/frontend_tests/node_tests/rtl.js +++ b/frontend_tests/node_tests/rtl.js @@ -2,6 +2,8 @@ const {strict: assert} = require("assert"); +const {zrequire} = require("../zjsunit/namespace"); + const rtl = zrequire("rtl"); run_test("get_direction", () => { diff --git a/frontend_tests/node_tests/schema.js b/frontend_tests/node_tests/schema.js index c77c4a7f95..135a3a0147 100644 --- a/frontend_tests/node_tests/schema.js +++ b/frontend_tests/node_tests/schema.js @@ -2,6 +2,8 @@ const {strict: assert} = require("assert"); +const {zrequire} = require("../zjsunit/namespace"); + zrequire("schema"); run_test("basics", () => { diff --git a/frontend_tests/node_tests/scroll_util.js b/frontend_tests/node_tests/scroll_util.js index 0e6dc9ad88..7a103a231d 100644 --- a/frontend_tests/node_tests/scroll_util.js +++ b/frontend_tests/node_tests/scroll_util.js @@ -2,6 +2,8 @@ const {strict: assert} = require("assert"); +const {set_global, zrequire} = require("../zjsunit/namespace"); + zrequire("scroll_util"); set_global("ui", { get_scroll_element: (element) => element, diff --git a/frontend_tests/node_tests/search.js b/frontend_tests/node_tests/search.js index d599631dba..57d8ac151d 100644 --- a/frontend_tests/node_tests/search.js +++ b/frontend_tests/node_tests/search.js @@ -2,6 +2,8 @@ const {strict: assert} = require("assert"); +const {set_global, zrequire} = require("../zjsunit/namespace"); + set_global("page_params", { search_pills_enabled: true, }); @@ -28,7 +30,7 @@ set_global("search_pill_widget", { }, }); -global.patch_builtin("setTimeout", (func) => func()); +set_global("setTimeout", (func) => func()); run_test("clear_search_form", () => { $("#search_query").val("noise"); diff --git a/frontend_tests/node_tests/search_legacy.js b/frontend_tests/node_tests/search_legacy.js index b334d9f94c..4892bba131 100644 --- a/frontend_tests/node_tests/search_legacy.js +++ b/frontend_tests/node_tests/search_legacy.js @@ -2,6 +2,8 @@ const {strict: assert} = require("assert"); +const {set_global, zrequire} = require("../zjsunit/namespace"); + set_global("page_params", { search_pills_enabled: false, }); @@ -21,7 +23,7 @@ set_global("ui_util", { set_global("narrow", {}); set_global("Filter", {}); -global.patch_builtin("setTimeout", (func) => func()); +set_global("setTimeout", (func) => func()); run_test("update_button_visibility", () => { const search_query = $("#search_query"); diff --git a/frontend_tests/node_tests/search_pill.js b/frontend_tests/node_tests/search_pill.js index 2eaeef7088..99aee16a93 100644 --- a/frontend_tests/node_tests/search_pill.js +++ b/frontend_tests/node_tests/search_pill.js @@ -2,6 +2,8 @@ const {strict: assert} = require("assert"); +const {zrequire} = require("../zjsunit/namespace"); + zrequire("search_pill"); zrequire("input_pill"); zrequire("Filter", "js/filter"); diff --git a/frontend_tests/node_tests/search_suggestion.js b/frontend_tests/node_tests/search_suggestion.js index 7535360329..826c6c2c9a 100644 --- a/frontend_tests/node_tests/search_suggestion.js +++ b/frontend_tests/node_tests/search_suggestion.js @@ -2,6 +2,8 @@ const {strict: assert} = require("assert"); +const {set_global, zrequire} = require("../zjsunit/namespace"); + set_global("page_params", { search_pills_enabled: true, }); diff --git a/frontend_tests/node_tests/search_suggestion_legacy.js b/frontend_tests/node_tests/search_suggestion_legacy.js index e9eeb717b2..eb713617e4 100644 --- a/frontend_tests/node_tests/search_suggestion_legacy.js +++ b/frontend_tests/node_tests/search_suggestion_legacy.js @@ -2,6 +2,8 @@ const {strict: assert} = require("assert"); +const {set_global, zrequire} = require("../zjsunit/namespace"); + set_global("page_params", { search_pills_enabled: false, }); diff --git a/frontend_tests/node_tests/server_events.js b/frontend_tests/node_tests/server_events.js index 376afcadb8..233822379e 100644 --- a/frontend_tests/node_tests/server_events.js +++ b/frontend_tests/node_tests/server_events.js @@ -2,11 +2,13 @@ const {strict: assert} = require("assert"); +const {set_global, stub_out_jquery, zrequire} = require("../zjsunit/namespace"); + const noop = function () {}; set_global("document", {}); set_global("addEventListener", noop); -global.stub_out_jquery(); +stub_out_jquery(); zrequire("message_store"); zrequire("server_events_dispatch"); diff --git a/frontend_tests/node_tests/settings_bots.js b/frontend_tests/node_tests/settings_bots.js index a00deeef6a..0f7f02473e 100644 --- a/frontend_tests/node_tests/settings_bots.js +++ b/frontend_tests/node_tests/settings_bots.js @@ -4,6 +4,8 @@ const {strict: assert} = require("assert"); const rewiremock = require("rewiremock/node"); +const {set_global, zrequire} = require("../zjsunit/namespace"); + set_global("page_params", { realm_uri: "https://chat.example.com", realm_embedded_bots: [ diff --git a/frontend_tests/node_tests/settings_data.js b/frontend_tests/node_tests/settings_data.js index 35587172df..c42798c97a 100644 --- a/frontend_tests/node_tests/settings_data.js +++ b/frontend_tests/node_tests/settings_data.js @@ -2,6 +2,8 @@ const {strict: assert} = require("assert"); +const {set_global, zrequire} = require("../zjsunit/namespace"); + const settings_data = zrequire("settings_data"); const settings_config = zrequire("settings_config"); diff --git a/frontend_tests/node_tests/settings_emoji.js b/frontend_tests/node_tests/settings_emoji.js index 9cc9d08dd4..111309cc07 100644 --- a/frontend_tests/node_tests/settings_emoji.js +++ b/frontend_tests/node_tests/settings_emoji.js @@ -2,6 +2,8 @@ const {strict: assert} = require("assert"); +const {set_global, zrequire} = require("../zjsunit/namespace"); + set_global("$", global.make_zjquery()); set_global("upload_widget", {}); zrequire("settings_emoji"); diff --git a/frontend_tests/node_tests/settings_muting.js b/frontend_tests/node_tests/settings_muting.js index 512341f7a6..309348f8c6 100644 --- a/frontend_tests/node_tests/settings_muting.js +++ b/frontend_tests/node_tests/settings_muting.js @@ -2,6 +2,8 @@ const {strict: assert} = require("assert"); +const {set_global, zrequire} = require("../zjsunit/namespace"); + set_global("$", global.make_zjquery()); set_global("XDate", zrequire("XDate", "xdate")); diff --git a/frontend_tests/node_tests/settings_org.js b/frontend_tests/node_tests/settings_org.js index 1d34dfa595..693e0a211d 100644 --- a/frontend_tests/node_tests/settings_org.js +++ b/frontend_tests/node_tests/settings_org.js @@ -4,6 +4,8 @@ const {strict: assert} = require("assert"); const rewiremock = require("rewiremock/node"); +const {set_global, zrequire} = require("../zjsunit/namespace"); + set_global("$", global.make_zjquery()); const noop = () => {}; @@ -200,7 +202,7 @@ function test_submit_settings_form(submit_form) { realm_create_stream_policy: settings_config.create_stream_policy_values.by_members.code, }); - global.patch_builtin("setTimeout", (func) => func()); + set_global("setTimeout", (func) => func()); const ev = { preventDefault: noop, stopPropagation: noop, diff --git a/frontend_tests/node_tests/settings_profile_fields.js b/frontend_tests/node_tests/settings_profile_fields.js index 20de9b07bc..1ca6c0ff24 100644 --- a/frontend_tests/node_tests/settings_profile_fields.js +++ b/frontend_tests/node_tests/settings_profile_fields.js @@ -4,6 +4,8 @@ const {strict: assert} = require("assert"); const rewiremock = require("rewiremock/node"); +const {set_global, zrequire} = require("../zjsunit/namespace"); + set_global("page_params", {}); set_global("$", global.make_zjquery()); set_global("loading", {}); diff --git a/frontend_tests/node_tests/settings_user_groups.js b/frontend_tests/node_tests/settings_user_groups.js index eceda65c76..af5ed4e7a2 100644 --- a/frontend_tests/node_tests/settings_user_groups.js +++ b/frontend_tests/node_tests/settings_user_groups.js @@ -4,6 +4,8 @@ const {strict: assert} = require("assert"); const _ = require("lodash"); +const {set_global, zrequire} = require("../zjsunit/namespace"); + zrequire("user_pill"); zrequire("pill_typeahead"); zrequire("settings_user_groups"); @@ -329,7 +331,7 @@ run_test("populate_user_groups", () => { } pills.onPillRemove = function (handler) { - global.patch_builtin("setTimeout", (func) => { + set_global("setTimeout", (func) => { func(); }); realm_user_group.members = new Set([2, 31]); @@ -789,7 +791,7 @@ run_test("on_events", () => { assert.equal(opts.data.description, "translated: All mobile members"); api_endpoint_called = true; (function test_post_success() { - global.patch_builtin("setTimeout", (func) => { + set_global("setTimeout", (func) => { func(); }); opts.success(); diff --git a/frontend_tests/node_tests/spoilers.js b/frontend_tests/node_tests/spoilers.js index 92aa26a805..4839f3d0e4 100644 --- a/frontend_tests/node_tests/spoilers.js +++ b/frontend_tests/node_tests/spoilers.js @@ -2,6 +2,8 @@ const {strict: assert} = require("assert"); +const {set_global, zrequire} = require("../zjsunit/namespace"); + set_global("$", global.make_zjquery()); zrequire("spoilers"); diff --git a/frontend_tests/node_tests/stream_data.js b/frontend_tests/node_tests/stream_data.js index e3e7ba1e8c..3a40d4fe65 100644 --- a/frontend_tests/node_tests/stream_data.js +++ b/frontend_tests/node_tests/stream_data.js @@ -4,6 +4,8 @@ const {strict: assert} = require("assert"); const _ = require("lodash"); +const {set_global, stub_out_jquery, zrequire} = require("../zjsunit/namespace"); + set_global("page_params", { is_admin: false, realm_users: [], @@ -13,7 +15,7 @@ set_global("page_params", { set_global("$", () => {}); set_global("document", null); -global.stub_out_jquery(); +stub_out_jquery(); zrequire("color_data"); zrequire("hash_util"); diff --git a/frontend_tests/node_tests/stream_edit.js b/frontend_tests/node_tests/stream_edit.js index b965f04f90..5eb0285d65 100644 --- a/frontend_tests/node_tests/stream_edit.js +++ b/frontend_tests/node_tests/stream_edit.js @@ -2,6 +2,8 @@ const {strict: assert} = require("assert"); +const {set_global, zrequire} = require("../zjsunit/namespace"); + const {LazySet} = zrequire("lazy_set"); const noop = () => {}; diff --git a/frontend_tests/node_tests/stream_events.js b/frontend_tests/node_tests/stream_events.js index af853fc734..81bf0c61e3 100644 --- a/frontend_tests/node_tests/stream_events.js +++ b/frontend_tests/node_tests/stream_events.js @@ -2,6 +2,8 @@ const {strict: assert} = require("assert"); +const {set_global, zrequire} = require("../zjsunit/namespace"); + const noop = function () {}; const return_true = function () { return true; diff --git a/frontend_tests/node_tests/stream_list.js b/frontend_tests/node_tests/stream_list.js index de2b5ccf2c..eace01957d 100644 --- a/frontend_tests/node_tests/stream_list.js +++ b/frontend_tests/node_tests/stream_list.js @@ -2,6 +2,8 @@ const {strict: assert} = require("assert"); +const {set_global, zrequire} = require("../zjsunit/namespace"); + set_global("document", "document-stub"); set_global("$", global.make_zjquery()); diff --git a/frontend_tests/node_tests/stream_pill.js b/frontend_tests/node_tests/stream_pill.js index 0b103981be..7b946f736c 100644 --- a/frontend_tests/node_tests/stream_pill.js +++ b/frontend_tests/node_tests/stream_pill.js @@ -2,6 +2,8 @@ const {strict: assert} = require("assert"); +const {zrequire} = require("../zjsunit/namespace"); + zrequire("stream_data"); zrequire("stream_pill"); diff --git a/frontend_tests/node_tests/stream_search.js b/frontend_tests/node_tests/stream_search.js index 51a1bb3a78..1bffd71e2a 100644 --- a/frontend_tests/node_tests/stream_search.js +++ b/frontend_tests/node_tests/stream_search.js @@ -1,6 +1,8 @@ "use strict"; const {strict: assert} = require("assert"); + +const {set_global, zrequire} = require("../zjsunit/namespace"); // This tests the stream searching functionality which currently // lives in stream_list.js. diff --git a/frontend_tests/node_tests/stream_sort.js b/frontend_tests/node_tests/stream_sort.js index 41e001589f..a3d42f7dd3 100644 --- a/frontend_tests/node_tests/stream_sort.js +++ b/frontend_tests/node_tests/stream_sort.js @@ -2,6 +2,8 @@ const {strict: assert} = require("assert"); +const {zrequire} = require("../zjsunit/namespace"); + zrequire("stream_data"); zrequire("stream_sort"); diff --git a/frontend_tests/node_tests/stream_topic_history.js b/frontend_tests/node_tests/stream_topic_history.js index ba8a694c5b..236a2f7acd 100644 --- a/frontend_tests/node_tests/stream_topic_history.js +++ b/frontend_tests/node_tests/stream_topic_history.js @@ -2,6 +2,8 @@ const {strict: assert} = require("assert"); +const {set_global, zrequire} = require("../zjsunit/namespace"); + zrequire("unread"); zrequire("stream_data"); zrequire("stream_topic_history"); diff --git a/frontend_tests/node_tests/submessage.js b/frontend_tests/node_tests/submessage.js index 973eabc537..3bac735476 100644 --- a/frontend_tests/node_tests/submessage.js +++ b/frontend_tests/node_tests/submessage.js @@ -2,6 +2,8 @@ const {strict: assert} = require("assert"); +const {set_global, zrequire} = require("../zjsunit/namespace"); + zrequire("submessage"); set_global("channel", {}); diff --git a/frontend_tests/node_tests/subs.js b/frontend_tests/node_tests/subs.js index a5e614d00e..ebd551456c 100644 --- a/frontend_tests/node_tests/subs.js +++ b/frontend_tests/node_tests/subs.js @@ -2,7 +2,9 @@ const {strict: assert} = require("assert"); -global.stub_out_jquery(); +const {set_global, stub_out_jquery, zrequire} = require("../zjsunit/namespace"); + +stub_out_jquery(); set_global("ui", { get_content_element: (element) => element, diff --git a/frontend_tests/node_tests/support.js b/frontend_tests/node_tests/support.js index 7584e47f25..cc3f966698 100644 --- a/frontend_tests/node_tests/support.js +++ b/frontend_tests/node_tests/support.js @@ -5,6 +5,8 @@ const fs = require("fs"); const {JSDOM} = require("jsdom"); +const {set_global, zrequire} = require("../zjsunit/namespace"); + const template = fs.readFileSync("templates/analytics/realm_details.html", "utf-8"); const dom = new JSDOM(template, {pretendToBeVisual: true}); const document = dom.window.document; diff --git a/frontend_tests/node_tests/timerender.js b/frontend_tests/node_tests/timerender.js index dc3e080433..c7b8cab5f5 100644 --- a/frontend_tests/node_tests/timerender.js +++ b/frontend_tests/node_tests/timerender.js @@ -5,6 +5,8 @@ const {strict: assert} = require("assert"); const moment = require("moment"); const XDate = require("xdate"); +const {set_global, zrequire} = require("../zjsunit/namespace"); + set_global("$", global.make_zjquery()); set_global("page_params", { twenty_four_hour_time: true, diff --git a/frontend_tests/node_tests/top_left_corner.js b/frontend_tests/node_tests/top_left_corner.js index 6fd6827dd4..794f9d9859 100644 --- a/frontend_tests/node_tests/top_left_corner.js +++ b/frontend_tests/node_tests/top_left_corner.js @@ -2,6 +2,8 @@ const {strict: assert} = require("assert"); +const {set_global, zrequire} = require("../zjsunit/namespace"); + set_global("$", global.make_zjquery()); zrequire("Filter", "js/filter"); diff --git a/frontend_tests/node_tests/topic_generator.js b/frontend_tests/node_tests/topic_generator.js index f646ea6d2a..26e1f92211 100644 --- a/frontend_tests/node_tests/topic_generator.js +++ b/frontend_tests/node_tests/topic_generator.js @@ -2,6 +2,8 @@ const {strict: assert} = require("assert"); +const {zrequire} = require("../zjsunit/namespace"); + const pm_conversations = zrequire("pm_conversations"); pm_conversations.recent = {}; diff --git a/frontend_tests/node_tests/topic_list_data.js b/frontend_tests/node_tests/topic_list_data.js index 3730dc5b14..05610f24c6 100644 --- a/frontend_tests/node_tests/topic_list_data.js +++ b/frontend_tests/node_tests/topic_list_data.js @@ -4,6 +4,8 @@ const {strict: assert} = require("assert"); const _ = require("lodash"); +const {set_global, zrequire} = require("../zjsunit/namespace"); + set_global("narrow_state", {}); set_global("unread", {}); set_global("muting", {}); diff --git a/frontend_tests/node_tests/transmit.js b/frontend_tests/node_tests/transmit.js index 37baa5c7ea..69f2d5b1d8 100644 --- a/frontend_tests/node_tests/transmit.js +++ b/frontend_tests/node_tests/transmit.js @@ -2,6 +2,8 @@ const {strict: assert} = require("assert"); +const {set_global, zrequire} = require("../zjsunit/namespace"); + const noop = function () {}; set_global("$", global.make_zjquery()); diff --git a/frontend_tests/node_tests/typeahead.js b/frontend_tests/node_tests/typeahead.js index 51fadcf921..9a65a6aeb8 100644 --- a/frontend_tests/node_tests/typeahead.js +++ b/frontend_tests/node_tests/typeahead.js @@ -2,6 +2,8 @@ const {strict: assert} = require("assert"); +const {zrequire} = require("../zjsunit/namespace"); + const typeahead = zrequire("typeahead", "shared/js/typeahead"); // The data structures here may be different for diff --git a/frontend_tests/node_tests/typeahead_helper.js b/frontend_tests/node_tests/typeahead_helper.js index a7ca2414f3..068d8d774d 100644 --- a/frontend_tests/node_tests/typeahead_helper.js +++ b/frontend_tests/node_tests/typeahead_helper.js @@ -2,6 +2,8 @@ const {strict: assert} = require("assert"); +const {set_global, zrequire} = require("../zjsunit/namespace"); + set_global("page_params", {realm_is_zephyr_mirror_realm: false}); set_global("md5", (s) => "md5-" + s); diff --git a/frontend_tests/node_tests/typing_data.js b/frontend_tests/node_tests/typing_data.js index 82f1daec43..4dbb039906 100644 --- a/frontend_tests/node_tests/typing_data.js +++ b/frontend_tests/node_tests/typing_data.js @@ -2,6 +2,8 @@ const {strict: assert} = require("assert"); +const {set_global, zrequire} = require("../zjsunit/namespace"); + zrequire("typing_data"); run_test("basics", () => { @@ -85,8 +87,8 @@ run_test("timers", () => { typing_data.clear_inbound_timer(stub_group); } - global.patch_builtin("setTimeout", set_timeout); - global.patch_builtin("clearTimeout", clear_timeout); + set_global("setTimeout", set_timeout); + set_global("clearTimeout", clear_timeout); // first time, we set kickstart(); diff --git a/frontend_tests/node_tests/typing_status.js b/frontend_tests/node_tests/typing_status.js index b8bd5abf14..4cb360a475 100644 --- a/frontend_tests/node_tests/typing_status.js +++ b/frontend_tests/node_tests/typing_status.js @@ -2,6 +2,8 @@ const {strict: assert} = require("assert"); +const {set_global, zrequire} = require("../zjsunit/namespace"); + zrequire("typing"); zrequire("people"); zrequire("compose_pm_pill"); @@ -38,8 +40,8 @@ run_test("basics", () => { events.timer_cleared = true; } - global.patch_builtin("setTimeout", set_timeout); - global.patch_builtin("clearTimeout", clear_timeout); + set_global("setTimeout", set_timeout); + set_global("clearTimeout", clear_timeout); function notify_server_start(recipient) { assert.equal(recipient, "alice"); diff --git a/frontend_tests/node_tests/ui.js b/frontend_tests/node_tests/ui.js index e0efa634b4..31ab1202a0 100644 --- a/frontend_tests/node_tests/ui.js +++ b/frontend_tests/node_tests/ui.js @@ -2,6 +2,8 @@ const {strict: assert} = require("assert"); +const {set_global, zrequire} = require("../zjsunit/namespace"); + const ui = zrequire("ui"); set_global("navigator", { diff --git a/frontend_tests/node_tests/ui_init.js b/frontend_tests/node_tests/ui_init.js index 7389300c8b..d2c1af2d91 100644 --- a/frontend_tests/node_tests/ui_init.js +++ b/frontend_tests/node_tests/ui_init.js @@ -2,6 +2,8 @@ const rewiremock = require("rewiremock/node"); +const {set_global, zrequire} = require("../zjsunit/namespace"); + /* This test suite is designed to find errors in our initialization sequence. It doesn't diff --git a/frontend_tests/node_tests/unread.js b/frontend_tests/node_tests/unread.js index 0559a7b17d..f0aa8487ad 100644 --- a/frontend_tests/node_tests/unread.js +++ b/frontend_tests/node_tests/unread.js @@ -4,6 +4,8 @@ const {strict: assert} = require("assert"); const _ = require("lodash"); +const {set_global, zrequire} = require("../zjsunit/namespace"); + zrequire("muting"); const people = zrequire("people"); zrequire("stream_data"); diff --git a/frontend_tests/node_tests/upgrade.js b/frontend_tests/node_tests/upgrade.js index 44c69d9baf..1f9807d0d2 100644 --- a/frontend_tests/node_tests/upgrade.js +++ b/frontend_tests/node_tests/upgrade.js @@ -5,6 +5,8 @@ const fs = require("fs"); const {JSDOM} = require("jsdom"); +const {set_global, zrequire} = require("../zjsunit/namespace"); + const noop = () => {}; const template = fs.readFileSync("templates/corporate/upgrade.html", "utf-8"); const dom = new JSDOM(template, {pretendToBeVisual: true}); diff --git a/frontend_tests/node_tests/upload.js b/frontend_tests/node_tests/upload.js index fb887827a3..437c788ae9 100644 --- a/frontend_tests/node_tests/upload.js +++ b/frontend_tests/node_tests/upload.js @@ -4,6 +4,8 @@ const {strict: assert} = require("assert"); const rewiremock = require("rewiremock/node"); +const {set_global, zrequire} = require("../zjsunit/namespace"); + set_global("$", global.make_zjquery()); set_global("document", { location: {}, @@ -273,7 +275,7 @@ run_test("upload_files", () => { upload.upload_files(uppy, config, files); assert.equal(add_file_counter, 1); - global.patch_builtin("setTimeout", (func) => { + set_global("setTimeout", (func) => { func(); }); hide_upload_status_called = false; @@ -542,7 +544,7 @@ run_test("uppy_events", () => { assert.equal(compose_ui_autosize_textarea_called, false); const on_complete_callback = callbacks.complete; - global.patch_builtin("setTimeout", (func) => { + set_global("setTimeout", (func) => { func(); }); let hide_upload_status_called = false; diff --git a/frontend_tests/node_tests/user_events.js b/frontend_tests/node_tests/user_events.js index 61c232c1fb..2acebd5be2 100644 --- a/frontend_tests/node_tests/user_events.js +++ b/frontend_tests/node_tests/user_events.js @@ -2,6 +2,8 @@ const {strict: assert} = require("assert"); +const {set_global, zrequire} = require("../zjsunit/namespace"); + set_global("$", global.make_zjquery()); const people = zrequire("people"); diff --git a/frontend_tests/node_tests/user_groups.js b/frontend_tests/node_tests/user_groups.js index 888cff1516..a86b28d2da 100644 --- a/frontend_tests/node_tests/user_groups.js +++ b/frontend_tests/node_tests/user_groups.js @@ -2,6 +2,8 @@ const {strict: assert} = require("assert"); +const {zrequire} = require("../zjsunit/namespace"); + zrequire("user_groups"); run_test("user_groups", () => { diff --git a/frontend_tests/node_tests/user_pill.js b/frontend_tests/node_tests/user_pill.js index 6388a36d22..6e1168f4bc 100644 --- a/frontend_tests/node_tests/user_pill.js +++ b/frontend_tests/node_tests/user_pill.js @@ -2,6 +2,8 @@ const {strict: assert} = require("assert"); +const {set_global, zrequire} = require("../zjsunit/namespace"); + const people = zrequire("people"); set_global("md5", (s) => "md5-" + s); zrequire("user_pill"); diff --git a/frontend_tests/node_tests/user_status.js b/frontend_tests/node_tests/user_status.js index 2bf9c7a003..82e6171504 100644 --- a/frontend_tests/node_tests/user_status.js +++ b/frontend_tests/node_tests/user_status.js @@ -2,6 +2,8 @@ const {strict: assert} = require("assert"); +const {set_global, zrequire} = require("../zjsunit/namespace"); + set_global("channel", {}); zrequire("user_status"); diff --git a/frontend_tests/node_tests/util.js b/frontend_tests/node_tests/util.js index 23130b9fb4..35749dcbea 100644 --- a/frontend_tests/node_tests/util.js +++ b/frontend_tests/node_tests/util.js @@ -5,6 +5,8 @@ const {strict: assert} = require("assert"); const {JSDOM} = require("jsdom"); const _ = require("lodash"); +const {set_global, with_field, zrequire} = require("../zjsunit/namespace"); + set_global("$", global.make_zjquery()); set_global("DOMParser", new JSDOM().window.DOMParser); set_global("document", {}); diff --git a/frontend_tests/node_tests/vdom.js b/frontend_tests/node_tests/vdom.js index 4e2b9a5d47..f20e18b3c6 100644 --- a/frontend_tests/node_tests/vdom.js +++ b/frontend_tests/node_tests/vdom.js @@ -2,6 +2,8 @@ const {strict: assert} = require("assert"); +const {zrequire} = require("../zjsunit/namespace"); + zrequire("vdom"); run_test("basics", () => { diff --git a/frontend_tests/node_tests/widgetize.js b/frontend_tests/node_tests/widgetize.js index 1ec8d7261f..28a9e5fb2c 100644 --- a/frontend_tests/node_tests/widgetize.js +++ b/frontend_tests/node_tests/widgetize.js @@ -2,6 +2,8 @@ const {strict: assert} = require("assert"); +const {set_global, zrequire} = require("../zjsunit/namespace"); + set_global("$", global.make_zjquery()); set_global("poll_widget", {}); set_global("todo_widget", {}); diff --git a/frontend_tests/node_tests/zjquery.js b/frontend_tests/node_tests/zjquery.js index 0b45e211b2..7345f8d1bb 100644 --- a/frontend_tests/node_tests/zjquery.js +++ b/frontend_tests/node_tests/zjquery.js @@ -2,6 +2,8 @@ const {strict: assert} = require("assert"); +const {set_global} = require("../zjsunit/namespace"); + /* This test module actually tests our test code, particularly zjquery, and diff --git a/frontend_tests/zjsunit/index.js b/frontend_tests/zjsunit/index.js index bfd6b50e8d..3e442c8c48 100644 --- a/frontend_tests/zjsunit/index.js +++ b/frontend_tests/zjsunit/index.js @@ -37,14 +37,6 @@ if (files.length === 0) { } // Set up our namespace helpers. -global.with_field = namespace.with_field; -global.set_global = namespace.set_global; -global.patch_builtin = namespace.set_global; -global.zrequire = namespace.zrequire; -global.reset_module = namespace.reset_module; -global.stub_out_jquery = namespace.stub_out_jquery; -global.with_overrides = namespace.with_overrides; - global.window = new Proxy(global, { set: (obj, prop, value) => { namespace.set_global(prop, value); @@ -107,7 +99,7 @@ global.run_test = (label, f) => { console.info(" test: " + label); } try { - global.with_overrides(f); + namespace.with_overrides(f); } catch (error) { console.info("-".repeat(50)); console.info(`test failed: ${current_file_name} > ${label}`); @@ -120,16 +112,16 @@ global.run_test = (label, f) => { try { files.forEach((file) => { - set_global("location", { + namespace.set_global("location", { hash: "#", }); - global.patch_builtin("setTimeout", noop); - global.patch_builtin("setInterval", noop); + namespace.set_global("setTimeout", noop); + namespace.set_global("setInterval", noop); _.throttle = immediate; _.debounce = immediate; - set_global("blueslip", make_zblueslip()); - set_global("i18n", stub_i18n); + namespace.set_global("blueslip", make_zblueslip()); + namespace.set_global("i18n", stub_i18n); namespace.clear_zulip_refs(); run_one_module(file); diff --git a/frontend_tests/zjsunit/namespace.js b/frontend_tests/zjsunit/namespace.js index 2eb8f010eb..10cafc89fe 100644 --- a/frontend_tests/zjsunit/namespace.js +++ b/frontend_tests/zjsunit/namespace.js @@ -73,7 +73,7 @@ exports.restore = function () { }; exports.stub_out_jquery = function () { - set_global("$", () => ({ + exports.set_global("$", () => ({ on() {}, trigger() {}, hide() {},