From 89aa3155a97f9cd7977766a530787e2a14219091 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Tue, 9 Feb 2021 19:53:22 -0800 Subject: [PATCH] =?UTF-8?q?node=5Ftests:=20Don=E2=80=99t=20read=20from=20m?= =?UTF-8?q?ost=20deprecated=20global=20variables.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We still need to write to these globals with set_global because the code being tested reads from them, but the tests themselves should never need to read from them. Signed-off-by: Anders Kaseorg --- .eslintrc.json | 14 +++++- frontend_tests/node_tests/activity.js | 22 +++++----- frontend_tests/node_tests/alert_words.js | 2 +- frontend_tests/node_tests/alert_words_ui.js | 6 +-- frontend_tests/node_tests/billing.js | 4 +- frontend_tests/node_tests/billing_helpers.js | 6 +-- frontend_tests/node_tests/bot_data.js | 2 +- frontend_tests/node_tests/buddy_data.js | 8 ++-- frontend_tests/node_tests/buddy_list.js | 2 +- frontend_tests/node_tests/channel.js | 4 +- frontend_tests/node_tests/color_data.js | 2 +- frontend_tests/node_tests/colorspace.js | 2 +- frontend_tests/node_tests/common.js | 2 +- frontend_tests/node_tests/components.js | 2 +- frontend_tests/node_tests/compose.js | 44 +++++++++---------- frontend_tests/node_tests/compose_actions.js | 26 ++++++----- frontend_tests/node_tests/compose_fade.js | 4 +- frontend_tests/node_tests/compose_pm_pill.js | 4 +- frontend_tests/node_tests/compose_ui.js | 4 +- .../node_tests/composebox_typeahead.js | 22 +++++----- frontend_tests/node_tests/copy_and_paste.js | 2 +- frontend_tests/node_tests/dispatch.js | 12 ++--- frontend_tests/node_tests/dispatch_subs.js | 4 +- frontend_tests/node_tests/drafts.js | 10 ++--- .../node_tests/dropdown_list_widget.js | 2 +- frontend_tests/node_tests/echo.js | 6 +-- frontend_tests/node_tests/emoji_picker.js | 2 +- frontend_tests/node_tests/filter.js | 6 +-- frontend_tests/node_tests/general.js | 36 +++++++-------- frontend_tests/node_tests/hash_util.js | 10 ++--- frontend_tests/node_tests/hashchange.js | 14 +++--- frontend_tests/node_tests/hotkey.js | 8 ++-- frontend_tests/node_tests/input_pill.js | 2 +- frontend_tests/node_tests/keydown_util.js | 2 +- frontend_tests/node_tests/lightbox.js | 6 +-- frontend_tests/node_tests/list_cursor.js | 2 +- frontend_tests/node_tests/list_widget.js | 4 +- frontend_tests/node_tests/markdown.js | 6 +-- frontend_tests/node_tests/message_edit.js | 2 +- frontend_tests/node_tests/message_events.js | 14 +++--- frontend_tests/node_tests/message_fetch.js | 20 ++++----- frontend_tests/node_tests/message_flags.js | 6 +-- frontend_tests/node_tests/message_list.js | 2 +- .../node_tests/message_list_data.js | 5 +-- .../node_tests/message_list_view.js | 6 +-- frontend_tests/node_tests/message_store.js | 2 +- frontend_tests/node_tests/muting.js | 4 +- frontend_tests/node_tests/narrow.js | 14 +++--- frontend_tests/node_tests/narrow_activate.js | 12 ++--- frontend_tests/node_tests/narrow_local.js | 10 ++--- frontend_tests/node_tests/narrow_state.js | 6 +-- frontend_tests/node_tests/narrow_unread.js | 10 ++--- frontend_tests/node_tests/notifications.js | 8 ++-- frontend_tests/node_tests/password.js | 2 +- frontend_tests/node_tests/peer_data.js | 2 +- frontend_tests/node_tests/people.js | 2 +- frontend_tests/node_tests/people_errors.js | 2 +- frontend_tests/node_tests/pm_list.js | 12 ++--- frontend_tests/node_tests/poll_widget.js | 2 +- frontend_tests/node_tests/popovers.js | 10 ++--- frontend_tests/node_tests/presence.js | 6 +-- frontend_tests/node_tests/reactions.js | 8 ++-- frontend_tests/node_tests/recent_topics.js | 4 +- .../node_tests/rendered_markdown.js | 4 +- frontend_tests/node_tests/schema.js | 2 +- frontend_tests/node_tests/scroll_util.js | 2 +- frontend_tests/node_tests/search.js | 12 ++--- frontend_tests/node_tests/search_legacy.js | 10 ++--- frontend_tests/node_tests/search_pill.js | 4 +- .../node_tests/search_suggestion.js | 6 +-- .../node_tests/search_suggestion_legacy.js | 6 +-- frontend_tests/node_tests/server_events.js | 4 +- frontend_tests/node_tests/settings_bots.js | 6 +-- frontend_tests/node_tests/settings_emoji.js | 4 +- frontend_tests/node_tests/settings_muting.js | 8 ++-- frontend_tests/node_tests/settings_org.js | 17 +++---- .../node_tests/settings_profile_fields.js | 4 +- .../node_tests/settings_user_groups.js | 14 +++--- frontend_tests/node_tests/spoilers.js | 2 +- frontend_tests/node_tests/stream_data.js | 10 ++--- frontend_tests/node_tests/stream_edit.js | 12 ++--- frontend_tests/node_tests/stream_events.js | 16 +++---- frontend_tests/node_tests/stream_list.js | 19 ++++---- frontend_tests/node_tests/stream_pill.js | 4 +- frontend_tests/node_tests/stream_search.js | 6 +-- frontend_tests/node_tests/stream_sort.js | 4 +- .../node_tests/stream_topic_history.js | 10 ++--- frontend_tests/node_tests/submessage.js | 8 ++-- frontend_tests/node_tests/subs.js | 6 +-- frontend_tests/node_tests/timerender.js | 2 +- frontend_tests/node_tests/top_left_corner.js | 4 +- frontend_tests/node_tests/topic_generator.js | 10 ++--- frontend_tests/node_tests/topic_list_data.js | 10 ++--- frontend_tests/node_tests/transmit.js | 10 ++--- frontend_tests/node_tests/typeahead_helper.js | 4 +- frontend_tests/node_tests/typing_data.js | 2 +- frontend_tests/node_tests/typing_status.js | 4 +- frontend_tests/node_tests/ui_init.js | 19 ++++---- frontend_tests/node_tests/unread.js | 8 ++-- frontend_tests/node_tests/upgrade.js | 8 +--- frontend_tests/node_tests/upload.js | 10 ++--- frontend_tests/node_tests/user_events.js | 6 +-- frontend_tests/node_tests/user_groups.js | 2 +- frontend_tests/node_tests/user_pill.js | 2 +- frontend_tests/node_tests/user_status.js | 4 +- frontend_tests/node_tests/vdom.js | 2 +- frontend_tests/node_tests/widgetize.js | 6 +-- frontend_tests/zjsunit/index.js | 2 +- frontend_tests/zjsunit/namespace.js | 2 +- frontend_tests/zjsunit/test.js | 2 +- 110 files changed, 407 insertions(+), 399 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 9e013ccc19..fac84cbe90 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -104,6 +104,18 @@ "yoda": "error" }, "overrides": [ + { + "files": ["frontend_tests/node_tests/**"], + "globals": { + "$": false, + "blueslip": false, + "current_msg_list": false, + "home_msg_list": false, + "i18n": false, + "location": false, + "page_params": false + } + }, { "files": ["frontend_tests/puppeteer_lib/**", "frontend_tests/puppeteer_tests/**"], "globals": { @@ -113,7 +125,7 @@ } }, { - "files": ["frontend_tests/node_tests/**", "frontend_tests/zjsunit/**", "static/js/**"], + "files": ["static/js/**"], "globals": { "$": false, "FetchStatus": false, diff --git a/frontend_tests/node_tests/activity.js b/frontend_tests/node_tests/activity.js index f2cecec9fa..243a427fe9 100644 --- a/frontend_tests/node_tests/activity.js +++ b/frontend_tests/node_tests/activity.js @@ -26,7 +26,7 @@ const _document = { }, }; -const _channel = {}; +const channel = {}; const _ui = { get_content_element: (element) => element, @@ -38,7 +38,7 @@ const _keydown_util = { }, }; -const _compose_state = {}; +const compose_state = {}; const _scroll_util = { scroll_element_into_container: () => {}, @@ -66,8 +66,8 @@ const _resize = { set_global("padded_widget", { update_padding: () => {}, }); -set_global("channel", _channel); -set_global("compose_state", _compose_state); +set_global("channel", channel); +set_global("compose_state", compose_state); set_global("document", _document); set_global("keydown_util", _keydown_util); set_global("page_params", _page_params); @@ -78,18 +78,18 @@ set_global("scroll_util", _scroll_util); set_global("stream_popover", _stream_popover); set_global("ui", _ui); -zrequire("compose_fade"); +const compose_fade = zrequire("compose_fade"); zrequire("unread"); zrequire("hash_util"); -zrequire("narrow"); -zrequire("presence"); +const narrow = zrequire("narrow"); +const presence = zrequire("presence"); const people = zrequire("people"); -zrequire("buddy_data"); -zrequire("buddy_list"); +const buddy_data = zrequire("buddy_data"); +const buddy_list = zrequire("buddy_list"); zrequire("user_search"); -zrequire("user_status"); +const user_status = zrequire("user_status"); zrequire("list_cursor"); -zrequire("activity"); +const activity = zrequire("activity"); const me = { email: "me@zulip.com", diff --git a/frontend_tests/node_tests/alert_words.js b/frontend_tests/node_tests/alert_words.js index 22008f0a3d..0438dd2586 100644 --- a/frontend_tests/node_tests/alert_words.js +++ b/frontend_tests/node_tests/alert_words.js @@ -10,7 +10,7 @@ const params = { }; const people = zrequire("people"); -zrequire("alert_words"); +const alert_words = zrequire("alert_words"); alert_words.initialize(params); diff --git a/frontend_tests/node_tests/alert_words_ui.js b/frontend_tests/node_tests/alert_words_ui.js index ebbadbc041..a06956f67f 100644 --- a/frontend_tests/node_tests/alert_words_ui.js +++ b/frontend_tests/node_tests/alert_words_ui.js @@ -9,10 +9,10 @@ const {make_zjquery} = require("../zjsunit/zjquery"); set_global("$", make_zjquery()); -set_global("channel", {}); +const channel = set_global("channel", {}); -zrequire("alert_words"); -zrequire("alert_words_ui"); +const alert_words = zrequire("alert_words"); +const alert_words_ui = zrequire("alert_words_ui"); alert_words.initialize({ alert_words: ["foo", "bar"], diff --git a/frontend_tests/node_tests/billing.js b/frontend_tests/node_tests/billing.js index 056df8bd5f..8f910d60a0 100644 --- a/frontend_tests/node_tests/billing.js +++ b/frontend_tests/node_tests/billing.js @@ -14,10 +14,10 @@ const template = fs.readFileSync("templates/corporate/billing.html", "utf-8"); const dom = new JSDOM(template, {pretendToBeVisual: true}); const document = dom.window.document; -set_global("helpers", { +const helpers = set_global("helpers", { set_tab: noop, }); -set_global("StripeCheckout", { +const StripeCheckout = set_global("StripeCheckout", { configure: noop, }); diff --git a/frontend_tests/node_tests/billing_helpers.js b/frontend_tests/node_tests/billing_helpers.js index e2c644260d..1c50e5f02b 100644 --- a/frontend_tests/node_tests/billing_helpers.js +++ b/frontend_tests/node_tests/billing_helpers.js @@ -16,8 +16,8 @@ const jquery = jQueryFactory(dom.window); set_global("$", make_zjquery()); set_global("page_params", {}); -set_global("loading", {}); -set_global("history", {}); +const loading = set_global("loading", {}); +const history = set_global("history", {}); set_global("document", { title: "Zulip", }); @@ -27,7 +27,7 @@ set_global("location", { hash: "#billing", }); -zrequire("helpers", "js/billing/helpers"); +const helpers = zrequire("helpers", "js/billing/helpers"); run_test("create_ajax_request", () => { const form_loading_indicator = "#autopay_loading_indicator"; diff --git a/frontend_tests/node_tests/bot_data.js b/frontend_tests/node_tests/bot_data.js index d69866bdc2..93d4708e16 100644 --- a/frontend_tests/node_tests/bot_data.js +++ b/frontend_tests/node_tests/bot_data.js @@ -11,7 +11,7 @@ const _settings_bots = { set_global("settings_bots", _settings_bots); -zrequire("bot_data"); +const bot_data = zrequire("bot_data"); const people = zrequire("people"); const me = { diff --git a/frontend_tests/node_tests/buddy_data.js b/frontend_tests/node_tests/buddy_data.js index 4ee752d65a..acf6bdb6d2 100644 --- a/frontend_tests/node_tests/buddy_data.js +++ b/frontend_tests/node_tests/buddy_data.js @@ -13,11 +13,11 @@ const _page_params = {}; set_global("page_params", _page_params); set_global("$", make_zjquery()); const people = zrequire("people"); -zrequire("presence"); -zrequire("user_status"); +const presence = zrequire("presence"); +const user_status = zrequire("user_status"); -zrequire("buddy_data"); -set_global("timerender", {}); +const buddy_data = zrequire("buddy_data"); +const timerender = set_global("timerender", {}); // The buddy_data module is mostly tested indirectly through // activity.js, but we should feel free to add direct tests diff --git a/frontend_tests/node_tests/buddy_list.js b/frontend_tests/node_tests/buddy_list.js index fbf39c8163..bcac55bb4a 100644 --- a/frontend_tests/node_tests/buddy_list.js +++ b/frontend_tests/node_tests/buddy_list.js @@ -11,7 +11,7 @@ const {make_zjquery} = require("../zjsunit/zjquery"); set_global("$", make_zjquery()); const people = zrequire("people"); zrequire("buddy_data"); -zrequire("buddy_list"); +const buddy_list = zrequire("buddy_list"); zrequire("ui"); set_global("padded_widget", { diff --git a/frontend_tests/node_tests/channel.js b/frontend_tests/node_tests/channel.js index 9f08ed1da1..187a3d9436 100644 --- a/frontend_tests/node_tests/channel.js +++ b/frontend_tests/node_tests/channel.js @@ -9,9 +9,9 @@ const {run_test} = require("../zjsunit/test"); set_global("$", {}); -set_global("reload", {}); +const reload = set_global("reload", {}); zrequire("reload_state"); -zrequire("channel"); +const channel = zrequire("channel"); const default_stub_xhr = "default-stub-xhr"; diff --git a/frontend_tests/node_tests/color_data.js b/frontend_tests/node_tests/color_data.js index 37ba0b9397..40a6b9edbb 100644 --- a/frontend_tests/node_tests/color_data.js +++ b/frontend_tests/node_tests/color_data.js @@ -5,7 +5,7 @@ const {strict: assert} = require("assert"); const {zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -zrequire("color_data"); +const color_data = zrequire("color_data"); run_test("pick_color", () => { color_data.colors = ["blue", "orange", "red", "yellow"]; diff --git a/frontend_tests/node_tests/colorspace.js b/frontend_tests/node_tests/colorspace.js index 4717480ba2..14c5d75f02 100644 --- a/frontend_tests/node_tests/colorspace.js +++ b/frontend_tests/node_tests/colorspace.js @@ -5,7 +5,7 @@ const {strict: assert} = require("assert"); const {zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -zrequire("colorspace"); +const colorspace = zrequire("colorspace"); run_test("sRGB_to_linear", () => { let srgb_color = 0.0042; diff --git a/frontend_tests/node_tests/common.js b/frontend_tests/node_tests/common.js index adf8d26226..1694588a65 100644 --- a/frontend_tests/node_tests/common.js +++ b/frontend_tests/node_tests/common.js @@ -25,7 +25,7 @@ $(input).val = (arg) => { }; }; -zrequire("common"); +const common = zrequire("common"); run_test("basics", () => { common.autofocus("#home"); diff --git a/frontend_tests/node_tests/components.js b/frontend_tests/node_tests/components.js index c35d4b7513..033d5252cb 100644 --- a/frontend_tests/node_tests/components.js +++ b/frontend_tests/node_tests/components.js @@ -8,7 +8,7 @@ const {set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); zrequire("keydown_util"); -zrequire("components"); +const components = zrequire("components"); const noop = function () {}; diff --git a/frontend_tests/node_tests/compose.js b/frontend_tests/node_tests/compose.js index 4f77af7bff..61c7cb5711 100644 --- a/frontend_tests/node_tests/compose.js +++ b/frontend_tests/node_tests/compose.js @@ -38,14 +38,14 @@ const _drafts = { delete_draft_after_send: noop, }; -const _sent_messages = { +const sent_messages = { start_tracking_message: noop, }; const _notifications = { notify_above_composebox: noop, clear_compose_notifications: noop, }; -const _reminder = { +const reminder = { is_deferred_delivery: noop, }; @@ -53,19 +53,19 @@ set_global("document", _document); set_global("drafts", _drafts); set_global("navigator", _navigator); set_global("notifications", _notifications); -set_global("reminder", _reminder); -set_global("sent_messages", _sent_messages); +set_global("reminder", reminder); +set_global("sent_messages", sent_messages); -set_global("local_message", {}); -set_global("transmit", {}); -set_global("channel", {}); -set_global("stream_edit", {}); -set_global("markdown", {}); -set_global("loading", {}); +const local_message = set_global("local_message", {}); +const transmit = set_global("transmit", {}); +const channel = set_global("channel", {}); +const stream_edit = set_global("stream_edit", {}); +const markdown = set_global("markdown", {}); +const loading = set_global("loading", {}); set_global("page_params", {}); -set_global("resize", {}); -set_global("subs", {}); -set_global("ui_util", {}); +const resize = set_global("resize", {}); +const subs = set_global("subs", {}); +const ui_util = set_global("ui_util", {}); // Setting these up so that we can test that links to uploads within messages are // automatically converted to server relative links. @@ -76,25 +76,25 @@ const fake_now = 555; MockDate.set(new Date(fake_now * 1000)); zrequire("zcommand"); -zrequire("compose_ui"); +const compose_ui = zrequire("compose_ui"); const peer_data = zrequire("peer_data"); const util = zrequire("util"); -zrequire("rtl"); +const rtl = zrequire("rtl"); zrequire("common"); -zrequire("stream_data"); -zrequire("compose_state"); +const stream_data = zrequire("stream_data"); +const compose_state = zrequire("compose_state"); const people = zrequire("people"); zrequire("input_pill"); zrequire("user_pill"); -zrequire("compose_pm_pill"); -zrequire("echo"); -rewiremock.proxy(() => zrequire("compose"), { +const compose_pm_pill = zrequire("compose_pm_pill"); +const echo = zrequire("echo"); +const compose = rewiremock.proxy(() => zrequire("compose"), { "../../static/js/rendered_markdown": { update_elements: () => {}, }, }); -zrequire("upload"); -zrequire("server_events_dispatch"); +const upload = zrequire("upload"); +const server_events_dispatch = zrequire("server_events_dispatch"); const settings_config = zrequire("settings_config"); people.small_avatar_url_for_person = function () { diff --git a/frontend_tests/node_tests/compose_actions.js b/frontend_tests/node_tests/compose_actions.js index 63ca90080b..3cdb01f706 100644 --- a/frontend_tests/node_tests/compose_actions.js +++ b/frontend_tests/node_tests/compose_actions.js @@ -22,16 +22,16 @@ set_global("page_params", {}); set_global("$", make_zjquery()); -set_global("compose_pm_pill", {}); +const compose_pm_pill = set_global("compose_pm_pill", {}); -set_global("hash_util", {}); +const hash_util = set_global("hash_util", {}); const people = zrequire("people"); -zrequire("compose_ui"); -zrequire("compose"); -zrequire("compose_state"); -zrequire("compose_actions"); -zrequire("stream_data"); +const compose_ui = zrequire("compose_ui"); +const compose = zrequire("compose"); +const compose_state = zrequire("compose_state"); +const compose_actions = zrequire("compose_actions"); +const stream_data = zrequire("stream_data"); set_global("document", "document-stub"); @@ -65,7 +65,7 @@ set_global("notifications", { clear_compose_notifications: noop, }); -set_global("compose_fade", { +const compose_fade = set_global("compose_fade", { clear_compose: noop, }); @@ -73,7 +73,7 @@ set_global("drafts", { update_draft: noop, }); -set_global("narrow_state", { +const narrow_state = set_global("narrow_state", { set_compose_defaults: noop, }); @@ -367,9 +367,11 @@ run_test("quote_and_reply", () => { }; }; - channel.get = function () { - assert.fail("channel.get should not be used if raw_content is present"); - }; + set_global("channel", { + get() { + assert.fail("channel.get should not be used if raw_content is present"); + }, + }); quote_and_reply(opts); diff --git a/frontend_tests/node_tests/compose_fade.js b/frontend_tests/node_tests/compose_fade.js index 5bd4aaf472..3d71a2e282 100644 --- a/frontend_tests/node_tests/compose_fade.js +++ b/frontend_tests/node_tests/compose_fade.js @@ -5,10 +5,10 @@ const {strict: assert} = require("assert"); const {set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -zrequire("stream_data"); +const stream_data = zrequire("stream_data"); const peer_data = zrequire("peer_data"); const people = zrequire("people"); -zrequire("compose_fade"); +const compose_fade = zrequire("compose_fade"); const me = { email: "me@example.com", diff --git a/frontend_tests/node_tests/compose_pm_pill.js b/frontend_tests/node_tests/compose_pm_pill.js index 0dd47675cc..713289ca83 100644 --- a/frontend_tests/node_tests/compose_pm_pill.js +++ b/frontend_tests/node_tests/compose_pm_pill.js @@ -10,8 +10,8 @@ set_global("$", make_zjquery()); const people = zrequire("people"); -zrequire("compose_pm_pill"); -zrequire("input_pill"); +const compose_pm_pill = zrequire("compose_pm_pill"); +const input_pill = zrequire("input_pill"); zrequire("user_pill"); let pills = { diff --git a/frontend_tests/node_tests/compose_ui.js b/frontend_tests/node_tests/compose_ui.js index 08c745c6c0..ecf51605b3 100644 --- a/frontend_tests/node_tests/compose_ui.js +++ b/frontend_tests/node_tests/compose_ui.js @@ -8,9 +8,9 @@ const {set_global, with_field, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); const {make_zjquery} = require("../zjsunit/zjquery"); -zrequire("compose_ui"); +const compose_ui = zrequire("compose_ui"); const people = zrequire("people"); -zrequire("user_status"); +const user_status = zrequire("user_status"); set_global("document", { execCommand() { diff --git a/frontend_tests/node_tests/composebox_typeahead.js b/frontend_tests/node_tests/composebox_typeahead.js index af560f35bb..67f5e92887 100644 --- a/frontend_tests/node_tests/composebox_typeahead.js +++ b/frontend_tests/node_tests/composebox_typeahead.js @@ -8,15 +8,15 @@ const {make_zjquery} = require("../zjsunit/zjquery"); const emoji = zrequire("emoji", "shared/js/emoji"); const typeahead = zrequire("typeahead", "shared/js/typeahead"); -zrequire("compose_state"); +const compose_state = zrequire("compose_state"); zrequire("templates"); -zrequire("typeahead_helper"); +const typeahead_helper = zrequire("typeahead_helper"); const people = zrequire("people"); -zrequire("user_groups"); -zrequire("stream_data"); -zrequire("user_pill"); -zrequire("compose_pm_pill"); -zrequire("composebox_typeahead"); +const user_groups = zrequire("user_groups"); +const stream_data = zrequire("stream_data"); +const user_pill = zrequire("user_pill"); +const compose_pm_pill = zrequire("compose_pm_pill"); +const composebox_typeahead = zrequire("composebox_typeahead"); zrequire("recent_senders"); zrequire("settings_org"); const settings_config = zrequire("settings_config"); @@ -25,9 +25,9 @@ const settings_config = zrequire("settings_config"); stream_data.update_calculated_fields = () => {}; stream_data.set_filter_out_inactives = () => false; -set_global("stream_topic_history", {}); +const stream_topic_history = set_global("stream_topic_history", {}); -set_global("message_store", { +const message_store = set_global("message_store", { user_ids: () => [], }); @@ -174,8 +174,8 @@ stream_data.add_sub(netherland_stream); set_global("$", make_zjquery()); set_global("page_params", {}); -set_global("channel", {}); -set_global("compose", { +const channel = set_global("channel", {}); +const compose = set_global("compose", { finish: noop, }); diff --git a/frontend_tests/node_tests/copy_and_paste.js b/frontend_tests/node_tests/copy_and_paste.js index cbf5098701..9c1d4f4c0b 100644 --- a/frontend_tests/node_tests/copy_and_paste.js +++ b/frontend_tests/node_tests/copy_and_paste.js @@ -10,7 +10,7 @@ const {run_test} = require("../zjsunit/test"); set_global("page_params", { development_environment: true, }); -set_global("compose_ui", {}); +const compose_ui = set_global("compose_ui", {}); const {window} = new JSDOM("

Hello world

"); const {DOMParser, document} = window; diff --git a/frontend_tests/node_tests/dispatch.js b/frontend_tests/node_tests/dispatch.js index 7756debb59..4266cc8050 100644 --- a/frontend_tests/node_tests/dispatch.js +++ b/frontend_tests/node_tests/dispatch.js @@ -35,9 +35,9 @@ set_global("hotspots", {}); set_global("markdown", {}); set_global("message_edit", {}); set_global("message_events", {}); -set_global("message_list", {}); +const message_list = set_global("message_list", {}); set_global("muting_ui", {}); -set_global("narrow_state", {}); +const narrow_state = set_global("narrow_state", {}); set_global("night_mode", {}); set_global("notifications", {}); set_global("overlays", {}); @@ -76,20 +76,20 @@ set_global("page_params", { }); // For data-oriented modules, just use them, don't stub them. -zrequire("alert_words"); +const alert_words = zrequire("alert_words"); zrequire("unread"); zrequire("stream_topic_history"); zrequire("stream_list"); zrequire("message_flags"); -zrequire("message_store"); +const message_store = zrequire("message_store"); const people = zrequire("people"); zrequire("starred_messages"); -zrequire("user_status"); +const user_status = zrequire("user_status"); zrequire("subs"); const emoji = zrequire("emoji", "shared/js/emoji"); -zrequire("server_events_dispatch"); +const server_events_dispatch = zrequire("server_events_dispatch"); zrequire("panels"); function dispatch(ev) { diff --git a/frontend_tests/node_tests/dispatch_subs.js b/frontend_tests/node_tests/dispatch_subs.js index f0cddd5bd7..d2d3235205 100644 --- a/frontend_tests/node_tests/dispatch_subs.js +++ b/frontend_tests/node_tests/dispatch_subs.js @@ -18,8 +18,8 @@ set_global("subs", {}); const peer_data = zrequire("peer_data"); const people = zrequire("people"); -zrequire("stream_data"); -zrequire("server_events_dispatch"); +const stream_data = zrequire("stream_data"); +const server_events_dispatch = zrequire("server_events_dispatch"); people.add_active_user(test_user); diff --git a/frontend_tests/node_tests/drafts.js b/frontend_tests/node_tests/drafts.js index af6cd3969b..1b0263c0db 100644 --- a/frontend_tests/node_tests/drafts.js +++ b/frontend_tests/node_tests/drafts.js @@ -9,9 +9,9 @@ const {make_zjquery} = require("../zjsunit/zjquery"); set_global("$", make_zjquery()); -zrequire("localstorage"); -zrequire("drafts"); -zrequire("timerender"); +const localstorage = zrequire("localstorage"); +const drafts = zrequire("drafts"); +const timerender = zrequire("timerender"); zrequire("stream_color"); zrequire("colorspace"); @@ -20,7 +20,7 @@ const noop = function () { return; }; -set_global("localStorage", { +const localStorage = set_global("localStorage", { getItem(key) { return ls_container.get(key); }, @@ -35,7 +35,7 @@ set_global("localStorage", { }, }); set_global("compose", {}); -set_global("compose_state", {}); +const compose_state = set_global("compose_state", {}); set_global("stream_data", { get_color() { return "#FFFFFF"; diff --git a/frontend_tests/node_tests/dropdown_list_widget.js b/frontend_tests/node_tests/dropdown_list_widget.js index 680b61a652..9dd972232c 100644 --- a/frontend_tests/node_tests/dropdown_list_widget.js +++ b/frontend_tests/node_tests/dropdown_list_widget.js @@ -6,7 +6,7 @@ const {set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); const {make_zjquery} = require("../zjsunit/zjquery"); -zrequire("dropdown_list_widget"); +const dropdown_list_widget = zrequire("dropdown_list_widget"); zrequire("scroll_util"); set_global("$", make_zjquery()); diff --git a/frontend_tests/node_tests/echo.js b/frontend_tests/node_tests/echo.js index 3d36b72e0f..5df5fc4be4 100644 --- a/frontend_tests/node_tests/echo.js +++ b/frontend_tests/node_tests/echo.js @@ -9,14 +9,14 @@ const {run_test} = require("../zjsunit/test"); const {make_zjquery} = require("../zjsunit/zjquery"); set_global("$", make_zjquery()); -set_global("local_message", {}); -set_global("markdown", {}); +const local_message = set_global("local_message", {}); +const markdown = set_global("markdown", {}); set_global("page_params", {}); const fake_now = 555; MockDate.set(new Date(fake_now * 1000)); -zrequire("echo"); +const echo = zrequire("echo"); const people = zrequire("people"); let disparities = []; diff --git a/frontend_tests/node_tests/emoji_picker.js b/frontend_tests/node_tests/emoji_picker.js index ccb6bfc380..cf9198ef19 100644 --- a/frontend_tests/node_tests/emoji_picker.js +++ b/frontend_tests/node_tests/emoji_picker.js @@ -8,7 +8,7 @@ const {zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); const emoji = zrequire("emoji", "shared/js/emoji"); -zrequire("emoji_picker"); +const emoji_picker = zrequire("emoji_picker"); const emoji_codes = zrequire("emoji_codes", "generated/emoji/emoji_codes.json"); diff --git a/frontend_tests/node_tests/filter.js b/frontend_tests/node_tests/filter.js index 57b1ef4275..145d16b4a9 100644 --- a/frontend_tests/node_tests/filter.js +++ b/frontend_tests/node_tests/filter.js @@ -7,13 +7,13 @@ const {run_test} = require("../zjsunit/test"); const {make_zjquery} = require("../zjsunit/zjquery"); zrequire("unread"); -zrequire("stream_data"); +const stream_data = zrequire("stream_data"); const people = zrequire("people"); set_global("$", make_zjquery()); zrequire("message_util", "js/message_util"); -zrequire("Filter", "js/filter"); +const Filter = zrequire("Filter", "js/filter"); -set_global("message_store", {}); +const message_store = set_global("message_store", {}); set_global("page_params", {}); const me = { diff --git a/frontend_tests/node_tests/general.js b/frontend_tests/node_tests/general.js index 9a7acf7970..4766fedd3c 100644 --- a/frontend_tests/node_tests/general.js +++ b/frontend_tests/node_tests/general.js @@ -80,7 +80,7 @@ const denmark_stream = { set_global("page_params", {}); -zrequire("stream_data"); +const stream_data = zrequire("stream_data"); run_test("verify stream_data persists stream color", () => { assert.equal(stream_data.get_sub_by_name("Denmark"), undefined); @@ -114,19 +114,19 @@ const messages = { const noop = () => undefined; -set_global("alert_words", {}); +const alert_words = set_global("alert_words", {}); alert_words.process_message = noop; // We can also bring in real code: zrequire("recent_senders"); -zrequire("unread"); -zrequire("stream_topic_history"); +const unread = zrequire("unread"); +const stream_topic_history = zrequire("stream_topic_history"); zrequire("recent_topics"); zrequire("overlays"); // And finally require the module that we will test directly: -zrequire("message_store"); +const message_store = zrequire("message_store"); run_test("message_store", () => { const in_message = {...messages.isaac_to_denmark_stream}; @@ -170,7 +170,7 @@ run_test("unread", () => { // We use the second argument of zrequire to find the location of the // Filter class. -zrequire("Filter", "js/filter"); +const Filter = zrequire("Filter", "js/filter"); run_test("filter", () => { const filter_terms = [ @@ -210,7 +210,7 @@ run_test("filter", () => { // "filter" abstraction. If you are in a narrow, we track the // state with the narrow_state module. -zrequire("narrow_state"); +const narrow_state = zrequire("narrow_state"); run_test("narrow_state", () => { // As we often do, first make assertions about the starting @@ -308,7 +308,7 @@ run_test("narrow_state", () => { */ -zrequire("server_events_dispatch"); +const server_events_dispatch = zrequire("server_events_dispatch"); // We will use Bob in several tests. const bob = { @@ -429,16 +429,16 @@ function test_helper() { */ -set_global("home_msg_list", {}); -set_global("message_list", {}); +const home_msg_list = set_global("home_msg_list", {}); +const message_list = set_global("message_list", {}); set_global("message_util", {}); -set_global("notifications", {}); +const notifications = set_global("notifications", {}); set_global("resize", {}); set_global("stream_list", {}); set_global("unread_ops", {}); set_global("unread_ui", {}); -zrequire("message_events"); +const message_events = zrequire("message_events"); run_test("insert_message", (override) => { override("pm_list.update_private_messages", noop); @@ -522,13 +522,11 @@ run_test("insert_message", (override) => { */ -set_global("channel", {}); -set_global("home_msg_list", {}); -set_global("message_list", {}); -set_global("message_viewport", {}); +const channel = set_global("channel", {}); +const message_viewport = set_global("message_viewport", {}); zrequire("message_flags"); -zrequire("unread_ops"); +const unread_ops = zrequire("unread_ops"); run_test("unread_ops", () => { (function set_up() { @@ -608,10 +606,10 @@ run_test("unread_ops", () => { */ -set_global("topic_list", {}); +const topic_list = set_global("topic_list", {}); zrequire("stream_sort"); -zrequire("stream_list"); +const stream_list = zrequire("stream_list"); const social_stream = { color: "red", diff --git a/frontend_tests/node_tests/hash_util.js b/frontend_tests/node_tests/hash_util.js index 45af680614..bfcad46f03 100644 --- a/frontend_tests/node_tests/hash_util.js +++ b/frontend_tests/node_tests/hash_util.js @@ -6,11 +6,11 @@ const {set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); const {make_zjquery} = require("../zjsunit/zjquery"); -zrequire("hash_util"); -zrequire("stream_data"); +const hash_util = zrequire("hash_util"); +const stream_data = zrequire("stream_data"); const people = zrequire("people"); -zrequire("Filter", "js/filter"); -zrequire("narrow_state"); +const Filter = zrequire("Filter", "js/filter"); +const narrow_state = zrequire("narrow_state"); set_global( "$", @@ -18,7 +18,7 @@ set_global( silent: true, }), ); -set_global("ui_report", { +const ui_report = set_global("ui_report", { displayed_error: false, error: () => { ui_report.displayed_error = true; diff --git a/frontend_tests/node_tests/hashchange.js b/frontend_tests/node_tests/hashchange.js index 17998c0a08..55254ece8d 100644 --- a/frontend_tests/node_tests/hashchange.js +++ b/frontend_tests/node_tests/hashchange.js @@ -15,28 +15,28 @@ set_global("location", { set_global("to_$", () => window_stub); const people = zrequire("people"); -zrequire("hash_util"); -zrequire("hashchange"); -zrequire("stream_data"); +const hash_util = zrequire("hash_util"); +const hashchange = zrequire("hashchange"); +const stream_data = zrequire("stream_data"); zrequire("navigate"); set_global("search", { update_button_visibility: () => {}, }); set_global("document", "document-stub"); -set_global("history", {}); +const history = set_global("history", {}); set_global("admin", {}); set_global("drafts", {}); set_global("favicon", {}); set_global("floating_recipient_bar", {}); -set_global("info_overlay", {}); +const info_overlay = set_global("info_overlay", {}); set_global("message_viewport", {}); -set_global("narrow", {}); +const narrow = set_global("narrow", {}); set_global("overlays", {}); set_global("settings", {}); set_global("subs", {}); -set_global("ui_util", {}); +const ui_util = set_global("ui_util", {}); run_test("operators_round_trip", () => { let operators; diff --git a/frontend_tests/node_tests/hotkey.js b/frontend_tests/node_tests/hotkey.js index d23c703a8e..c4396f53ab 100644 --- a/frontend_tests/node_tests/hotkey.js +++ b/frontend_tests/node_tests/hotkey.js @@ -28,7 +28,7 @@ set_global("navigator", { set_global("page_params", {}); -set_global("overlays", {}); +let overlays = set_global("overlays", {}); // jQuery stuff should go away if we make an initialize() method. set_global("document", "document-stub"); @@ -51,7 +51,7 @@ set_global("drafts", {}); set_global("hashchange", {}); set_global("info_overlay", {}); set_global("lightbox", {}); -set_global("list_util", {}); +const list_util = set_global("list_util", {}); set_global("message_edit", {}); set_global("muting_ui", {}); set_global("narrow", {}); @@ -225,7 +225,7 @@ run_test("basic_chars", () => { all_messages_popped: return_false, starred_messages_popped: return_false, }); - set_global("emoji_picker", { + const emoji_picker = set_global("emoji_picker", { reactions_popped: return_false, }); set_global("hotspots", { @@ -249,7 +249,7 @@ run_test("basic_chars", () => { for (const settings_open of [return_true, return_false]) { for (const is_active of [return_true, return_false]) { for (const info_overlay_open of [return_true, return_false]) { - set_global("overlays", { + overlays = set_global("overlays", { is_active, settings_open, info_overlay_open, diff --git a/frontend_tests/node_tests/input_pill.js b/frontend_tests/node_tests/input_pill.js index 109f34e933..ea1bcf9f71 100644 --- a/frontend_tests/node_tests/input_pill.js +++ b/frontend_tests/node_tests/input_pill.js @@ -7,7 +7,7 @@ const {run_test} = require("../zjsunit/test"); const {make_zjquery} = require("../zjsunit/zjquery"); set_global("$", make_zjquery()); -zrequire("input_pill"); +const input_pill = zrequire("input_pill"); zrequire("templates"); diff --git a/frontend_tests/node_tests/keydown_util.js b/frontend_tests/node_tests/keydown_util.js index 782419b7ae..42b98deffc 100644 --- a/frontend_tests/node_tests/keydown_util.js +++ b/frontend_tests/node_tests/keydown_util.js @@ -6,7 +6,7 @@ const {make_zjquery} = require("../zjsunit/zjquery"); set_global("$", make_zjquery()); -zrequire("keydown_util"); +const keydown_util = zrequire("keydown_util"); run_test("test_early_returns", () => { const stub = $.create("stub"); diff --git a/frontend_tests/node_tests/lightbox.js b/frontend_tests/node_tests/lightbox.js index fb1b8bedda..c3bbab239c 100644 --- a/frontend_tests/node_tests/lightbox.js +++ b/frontend_tests/node_tests/lightbox.js @@ -6,10 +6,10 @@ const {set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); const {make_zjquery} = require("../zjsunit/zjquery"); -zrequire("rows"); -zrequire("lightbox"); +const rows = zrequire("rows"); +const lightbox = zrequire("lightbox"); -set_global("message_store", {}); +const message_store = set_global("message_store", {}); set_global("Image", class Image {}); set_global("overlays", { close_overlay: () => {}, diff --git a/frontend_tests/node_tests/list_cursor.js b/frontend_tests/node_tests/list_cursor.js index cac0fe6583..098d619aea 100644 --- a/frontend_tests/node_tests/list_cursor.js +++ b/frontend_tests/node_tests/list_cursor.js @@ -5,7 +5,7 @@ const {strict: assert} = require("assert"); const {zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -zrequire("list_cursor"); +const ListCursor = zrequire("list_cursor"); run_test("config errors", () => { blueslip.expect("error", "Programming error"); diff --git a/frontend_tests/node_tests/list_widget.js b/frontend_tests/node_tests/list_widget.js index 31094b784f..ad92a801ef 100644 --- a/frontend_tests/node_tests/list_widget.js +++ b/frontend_tests/node_tests/list_widget.js @@ -5,7 +5,7 @@ const {strict: assert} = require("assert"); const {set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -zrequire("list_widget"); +const ListWidget = zrequire("list_widget"); // We need these stubs to get by instanceof checks. // The ListWidget library allows you to insert objects @@ -16,7 +16,7 @@ function Element() { return {}; } set_global("Element", Element); -set_global("ui", {}); +const ui = set_global("ui", {}); // We only need very simple jQuery wrappers for when the // "real" code wraps html or sets up click handlers. diff --git a/frontend_tests/node_tests/markdown.js b/frontend_tests/node_tests/markdown.js index d666077796..c2ca7ee1a9 100644 --- a/frontend_tests/node_tests/markdown.js +++ b/frontend_tests/node_tests/markdown.js @@ -17,11 +17,11 @@ const fenced_code = zrequire("fenced_code", "shared/js/fenced_code"); const markdown_config = zrequire("markdown_config"); const marked = zrequire("marked", "third/marked/lib/marked"); -zrequire("markdown"); +const markdown = zrequire("markdown"); zrequire("message_store"); const people = zrequire("people"); -zrequire("stream_data"); -zrequire("user_groups"); +const stream_data = zrequire("stream_data"); +const user_groups = zrequire("user_groups"); set_global("location", { origin: "http://zulip.zulipdev.com", diff --git a/frontend_tests/node_tests/message_edit.js b/frontend_tests/node_tests/message_edit.js index f31466ed63..38619a2d64 100644 --- a/frontend_tests/node_tests/message_edit.js +++ b/frontend_tests/node_tests/message_edit.js @@ -12,7 +12,7 @@ set_global("page_params", { stub_out_jquery(); -zrequire("message_edit"); +const message_edit = zrequire("message_edit"); const get_editability = message_edit.get_editability; const editability_types = message_edit.editability_types; diff --git a/frontend_tests/node_tests/message_events.js b/frontend_tests/node_tests/message_events.js index 2886c230cf..e270ec4026 100644 --- a/frontend_tests/node_tests/message_events.js +++ b/frontend_tests/node_tests/message_events.js @@ -6,21 +6,21 @@ const {set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); const {make_zjquery} = require("../zjsunit/zjquery"); -zrequire("message_events"); -zrequire("message_store"); +const message_events = zrequire("message_events"); +const message_store = zrequire("message_store"); zrequire("muting"); const people = zrequire("people"); zrequire("recent_senders"); -zrequire("stream_data"); -zrequire("stream_topic_history"); -zrequire("unread"); +const stream_data = zrequire("stream_data"); +const stream_topic_history = zrequire("stream_topic_history"); +const unread = zrequire("unread"); set_global("$", make_zjquery()); -set_global("alert_words", {}); +const alert_words = set_global("alert_words", {}); set_global("condense", {}); set_global("current_msg_list", {}); set_global("message_edit", {}); -set_global("message_list", {}); +const message_list = set_global("message_list", {}); set_global("notifications", {}); set_global("page_params", {}); set_global("pm_list", {}); diff --git a/frontend_tests/node_tests/message_fetch.js b/frontend_tests/node_tests/message_fetch.js index ad9a8c8b51..bdd6d29543 100644 --- a/frontend_tests/node_tests/message_fetch.js +++ b/frontend_tests/node_tests/message_fetch.js @@ -11,7 +11,7 @@ const {make_zjquery} = require("../zjsunit/zjquery"); set_global("$", make_zjquery()); set_global("document", "document-stub"); -zrequire("message_fetch"); +const message_fetch = zrequire("message_fetch"); const noop = () => {}; @@ -21,9 +21,9 @@ function MessageListView() { set_global("MessageListView", MessageListView); zrequire("FetchStatus", "js/fetch_status"); -zrequire("Filter", "js/filter"); +const Filter = zrequire("Filter", "js/filter"); zrequire("MessageListData", "js/message_list_data"); -zrequire("message_list"); +const message_list = zrequire("message_list"); const people = zrequire("people"); set_global("recent_topics", { @@ -35,7 +35,7 @@ set_global("ui_report", { hide_error: noop, }); -set_global("channel", {}); +const channel = set_global("channel", {}); set_global("document", "document-stub"); set_global("message_scroll", { show_loading_older: noop, @@ -44,12 +44,12 @@ set_global("message_scroll", { hide_loading_newer: noop, update_top_of_narrow_notices: () => {}, }); -set_global("message_util", {}); -set_global("message_store", {}); -set_global("narrow_state", {}); -set_global("pm_list", {}); -set_global("server_events", {}); -set_global("stream_list", { +const message_util = set_global("message_util", {}); +const message_store = set_global("message_store", {}); +const narrow_state = set_global("narrow_state", {}); +const pm_list = set_global("pm_list", {}); +const server_events = set_global("server_events", {}); +const stream_list = set_global("stream_list", { maybe_scroll_narrow_into_view: () => {}, }); diff --git a/frontend_tests/node_tests/message_flags.js b/frontend_tests/node_tests/message_flags.js index c4cafc26c7..18ad3bb099 100644 --- a/frontend_tests/node_tests/message_flags.js +++ b/frontend_tests/node_tests/message_flags.js @@ -7,10 +7,10 @@ const {run_test} = require("../zjsunit/test"); zrequire("unread"); zrequire("unread_ops"); -zrequire("message_flags"); +const message_flags = zrequire("message_flags"); -set_global("ui", {}); -set_global("channel", {}); +const ui = set_global("ui", {}); +const channel = set_global("channel", {}); set_global("starred_messages", { add: () => {}, remove: () => {}, diff --git a/frontend_tests/node_tests/message_list.js b/frontend_tests/node_tests/message_list.js index b62de671cf..57c5aac498 100644 --- a/frontend_tests/node_tests/message_list.js +++ b/frontend_tests/node_tests/message_list.js @@ -18,7 +18,7 @@ set_global("narrow_state", {}); set_global("stream_data", {}); zrequire("FetchStatus", "js/fetch_status"); -zrequire("muting"); +const muting = zrequire("muting"); zrequire("MessageListData", "js/message_list_data"); zrequire("MessageListView", "js/message_list_view"); const {MessageList} = zrequire("message_list"); diff --git a/frontend_tests/node_tests/message_list_data.js b/frontend_tests/node_tests/message_list_data.js index 2eae91634d..e7cfc7d1e6 100644 --- a/frontend_tests/node_tests/message_list_data.js +++ b/frontend_tests/node_tests/message_list_data.js @@ -2,16 +2,15 @@ const {strict: assert} = require("assert"); -const MessageListData = require("../../static/js/message_list_data"); const {set_global, with_field, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -zrequire("muting"); +const muting = zrequire("muting"); zrequire("unread"); zrequire("Filter", "js/filter"); zrequire("FetchStatus", "js/fetch_status"); -zrequire("MessageListData", "js/message_list_data"); +const MessageListData = zrequire("MessageListData", "js/message_list_data"); set_global("page_params", {}); diff --git a/frontend_tests/node_tests/message_list_view.js b/frontend_tests/node_tests/message_list_view.js index 9dbe475513..3c2746f7b5 100644 --- a/frontend_tests/node_tests/message_list_view.js +++ b/frontend_tests/node_tests/message_list_view.js @@ -11,11 +11,11 @@ const {make_zjquery} = require("../zjsunit/zjquery"); set_global("$", make_zjquery()); set_global("document", "document-stub"); -zrequire("Filter", "js/filter"); +const Filter = zrequire("Filter", "js/filter"); zrequire("FetchStatus", "js/fetch_status"); zrequire("MessageListData", "js/message_list_data"); -zrequire("MessageListView", "js/message_list_view"); -zrequire("message_list"); +const MessageListView = zrequire("MessageListView", "js/message_list_view"); +const message_list = zrequire("message_list"); const noop = function () {}; diff --git a/frontend_tests/node_tests/message_store.js b/frontend_tests/node_tests/message_store.js index 2fd5beacdf..4a11bc0476 100644 --- a/frontend_tests/node_tests/message_store.js +++ b/frontend_tests/node_tests/message_store.js @@ -9,7 +9,7 @@ const {make_zjquery} = require("../zjsunit/zjquery"); const util = zrequire("util"); const people = zrequire("people"); -zrequire("message_store"); +const message_store = zrequire("message_store"); const noop = function () {}; diff --git a/frontend_tests/node_tests/muting.js b/frontend_tests/node_tests/muting.js index 8e124c65e1..799faf1b1c 100644 --- a/frontend_tests/node_tests/muting.js +++ b/frontend_tests/node_tests/muting.js @@ -6,8 +6,8 @@ const {set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); zrequire("timerender"); -zrequire("muting"); -zrequire("stream_data"); +const muting = zrequire("muting"); +const stream_data = zrequire("stream_data"); set_global("page_params", {}); run_test("edge_cases", () => { diff --git a/frontend_tests/node_tests/narrow.js b/frontend_tests/node_tests/narrow.js index c1ca30c9cf..12815c6530 100644 --- a/frontend_tests/node_tests/narrow.js +++ b/frontend_tests/node_tests/narrow.js @@ -7,12 +7,12 @@ const {run_test} = require("../zjsunit/test"); const {make_zjquery} = require("../zjsunit/zjquery"); set_global("$", make_zjquery()); -zrequire("hash_util"); +const hash_util = zrequire("hash_util"); zrequire("hashchange"); -zrequire("narrow_state"); +const narrow_state = zrequire("narrow_state"); const people = zrequire("people"); -zrequire("stream_data"); -zrequire("Filter", "js/filter"); +const stream_data = zrequire("stream_data"); +const Filter = zrequire("Filter", "js/filter"); set_global("page_params", { stop_words: ["what", "about"], }); @@ -21,7 +21,7 @@ set_global("resize", { resize_stream_filters_container: () => {}, }); -zrequire("narrow"); +const narrow = zrequire("narrow"); function set_filter(operators) { operators = operators.map((op) => ({ @@ -249,8 +249,8 @@ run_test("show_invalid_narrow_message", () => { }); run_test("narrow_to_compose_target", () => { - set_global("compose_state", {}); - set_global("stream_topic_history", {}); + const compose_state = set_global("compose_state", {}); + const stream_topic_history = set_global("stream_topic_history", {}); const args = {called: false}; const activate_backup = narrow.activate; narrow.activate = function (operators, opts) { diff --git a/frontend_tests/node_tests/narrow_activate.js b/frontend_tests/node_tests/narrow_activate.js index bd5646ef9d..e44e783dbf 100644 --- a/frontend_tests/node_tests/narrow_activate.js +++ b/frontend_tests/node_tests/narrow_activate.js @@ -9,26 +9,26 @@ const {make_zjquery} = require("../zjsunit/zjquery"); const util = zrequire("util"); set_global("$", make_zjquery()); -zrequire("narrow_state"); +const narrow_state = zrequire("narrow_state"); set_global("resize", { resize_stream_filters_container: () => {}, }); -zrequire("stream_data"); +const stream_data = zrequire("stream_data"); zrequire("Filter", "js/filter"); zrequire("FetchStatus", "js/fetch_status"); zrequire("MessageListData", "js/message_list_data"); zrequire("unread"); -zrequire("narrow"); +const narrow = zrequire("narrow"); zrequire("search_pill"); -set_global("channel", {}); +const channel = set_global("channel", {}); set_global("compose", {}); set_global("compose_actions", {}); set_global("current_msg_list", {}); set_global("hashchange", {}); set_global("home_msg_list", {}); -set_global("message_fetch", {}); -set_global("message_list", { +const message_fetch = set_global("message_fetch", {}); +const message_list = set_global("message_list", { set_narrowed(value) { this.narrowed = value; }, diff --git a/frontend_tests/node_tests/narrow_local.js b/frontend_tests/node_tests/narrow_local.js index 9dd2a5c73d..e60572184d 100644 --- a/frontend_tests/node_tests/narrow_local.js +++ b/frontend_tests/node_tests/narrow_local.js @@ -5,14 +5,14 @@ const {strict: assert} = require("assert"); const {set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -zrequire("Filter", "js/filter"); +const Filter = zrequire("Filter", "js/filter"); zrequire("FetchStatus", "js/fetch_status"); -zrequire("MessageListData", "js/message_list_data"); -zrequire("narrow_state"); -zrequire("narrow"); +const MessageListData = zrequire("MessageListData", "js/message_list_data"); +const narrow_state = zrequire("narrow_state"); +const narrow = zrequire("narrow"); zrequire("stream_data"); -set_global("message_list", {}); +const message_list = set_global("message_list", {}); set_global("muting", { is_topic_muted: () => false, }); diff --git a/frontend_tests/node_tests/narrow_state.js b/frontend_tests/node_tests/narrow_state.js index d7a2e345e9..a3820bbb4d 100644 --- a/frontend_tests/node_tests/narrow_state.js +++ b/frontend_tests/node_tests/narrow_state.js @@ -6,9 +6,9 @@ const {set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); const people = zrequire("people"); -zrequire("Filter", "js/filter"); -zrequire("stream_data"); -zrequire("narrow_state"); +const Filter = zrequire("Filter", "js/filter"); +const stream_data = zrequire("stream_data"); +const narrow_state = zrequire("narrow_state"); set_global("page_params", {}); diff --git a/frontend_tests/node_tests/narrow_unread.js b/frontend_tests/node_tests/narrow_unread.js index 55c415df0a..b1e1d5a0d9 100644 --- a/frontend_tests/node_tests/narrow_unread.js +++ b/frontend_tests/node_tests/narrow_unread.js @@ -5,12 +5,12 @@ const {strict: assert} = require("assert"); const {set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -zrequire("Filter", "js/filter"); +const Filter = zrequire("Filter", "js/filter"); const people = zrequire("people"); -zrequire("stream_data"); -zrequire("unread"); +const stream_data = zrequire("stream_data"); +const unread = zrequire("unread"); -set_global("message_store", {}); +const message_store = set_global("message_store", {}); set_global("page_params", {}); set_global("muting", { @@ -18,7 +18,7 @@ set_global("muting", { }); // The main code we are testing lives here. -zrequire("narrow_state"); +const narrow_state = zrequire("narrow_state"); const alice = { email: "alice@example.com", diff --git a/frontend_tests/node_tests/notifications.js b/frontend_tests/node_tests/notifications.js index 970df4abd2..44524542f6 100644 --- a/frontend_tests/node_tests/notifications.js +++ b/frontend_tests/node_tests/notifications.js @@ -33,13 +33,13 @@ const _navigator = { set_global("navigator", _navigator); zrequire("alert_words"); -zrequire("muting"); -zrequire("stream_data"); +const muting = zrequire("muting"); +const stream_data = zrequire("stream_data"); zrequire("ui"); -zrequire("spoilers"); +const spoilers = zrequire("spoilers"); spoilers.hide_spoilers_in_notification = () => {}; -rewiremock.proxy(() => zrequire("notifications"), { +const notifications = rewiremock.proxy(() => zrequire("notifications"), { "../../static/js/favicon": {}, }); diff --git a/frontend_tests/node_tests/password.js b/frontend_tests/node_tests/password.js index d205e4cb44..3f2be0cd45 100644 --- a/frontend_tests/node_tests/password.js +++ b/frontend_tests/node_tests/password.js @@ -6,7 +6,7 @@ const {set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); set_global("zxcvbn", zrequire("zxcvbn", "zxcvbn")); -zrequire("common"); +const common = zrequire("common"); run_test("basics", () => { let accepted; diff --git a/frontend_tests/node_tests/peer_data.js b/frontend_tests/node_tests/peer_data.js index 86e2463d69..f3e7ca844f 100644 --- a/frontend_tests/node_tests/peer_data.js +++ b/frontend_tests/node_tests/peer_data.js @@ -14,7 +14,7 @@ const {run_test} = require("../zjsunit/test"); const peer_data = zrequire("peer_data"); const people = zrequire("people"); zrequire("hash_util"); -zrequire("stream_data"); +const stream_data = zrequire("stream_data"); set_global("page_params", { is_admin: false, diff --git a/frontend_tests/node_tests/people.js b/frontend_tests/node_tests/people.js index c08c5e8eba..10c1fc3d3b 100644 --- a/frontend_tests/node_tests/people.js +++ b/frontend_tests/node_tests/people.js @@ -9,7 +9,7 @@ const MockDate = require("mockdate"); const {set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -set_global("message_store", {}); +const message_store = set_global("message_store", {}); set_global("page_params", {}); set_global("settings_data", {}); diff --git a/frontend_tests/node_tests/people_errors.js b/frontend_tests/node_tests/people_errors.js index 771fa82ee6..cd0ab5cc62 100644 --- a/frontend_tests/node_tests/people_errors.js +++ b/frontend_tests/node_tests/people_errors.js @@ -13,7 +13,7 @@ const return_false = function () { const return_true = function () { return true; }; -set_global("reload_state", { +const reload_state = set_global("reload_state", { is_in_progress: return_false, }); diff --git a/frontend_tests/node_tests/pm_list.js b/frontend_tests/node_tests/pm_list.js index 7cf7da0ee2..0684045d6e 100644 --- a/frontend_tests/node_tests/pm_list.js +++ b/frontend_tests/node_tests/pm_list.js @@ -8,19 +8,19 @@ const {make_zjquery} = require("../zjsunit/zjquery"); set_global("$", make_zjquery()); -set_global("narrow_state", {}); +const narrow_state = set_global("narrow_state", {}); set_global("ui", { get_content_element: (element) => element, }); set_global("stream_popover", { hide_topic_popover() {}, }); -set_global("unread", {}); -set_global("unread_ui", {}); -set_global("vdom", { +const unread = set_global("unread", {}); +const unread_ui = set_global("unread_ui", {}); +const vdom = set_global("vdom", { render: () => "fake-dom-for-pm-list", }); -set_global("pm_list_dom", {}); +const pm_list_dom = set_global("pm_list_dom", {}); zrequire("user_status"); zrequire("presence"); @@ -28,7 +28,7 @@ zrequire("buddy_data"); zrequire("hash_util"); const people = zrequire("people"); const pm_conversations = zrequire("pm_conversations"); -zrequire("pm_list"); +const pm_list = zrequire("pm_list"); const alice = { email: "alice@zulip.com", diff --git a/frontend_tests/node_tests/poll_widget.js b/frontend_tests/node_tests/poll_widget.js index 79118cc8e9..c38c61b82c 100644 --- a/frontend_tests/node_tests/poll_widget.js +++ b/frontend_tests/node_tests/poll_widget.js @@ -7,7 +7,7 @@ const {set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); const {make_zjquery} = require("../zjsunit/zjquery"); -zrequire("poll_widget"); +const poll_widget = zrequire("poll_widget"); set_global("$", make_zjquery()); diff --git a/frontend_tests/node_tests/popovers.js b/frontend_tests/node_tests/popovers.js index 6bbf0db438..0e31e83ba3 100644 --- a/frontend_tests/node_tests/popovers.js +++ b/frontend_tests/node_tests/popovers.js @@ -17,9 +17,9 @@ zrequire("narrow_state"); const people = zrequire("people"); zrequire("presence"); zrequire("buddy_data"); -zrequire("user_status"); +const user_status = zrequire("user_status"); zrequire("feature_flags"); -zrequire("message_edit"); +const message_edit = zrequire("message_edit"); const noop = function () {}; $.fn.popover = noop; // this will get wrapped by our code @@ -30,7 +30,7 @@ set_global("page_params", { realm_email_address_visibility: 3, custom_profile_fields: [], }); -set_global("rows", {}); +const rows = set_global("rows", {}); set_global("message_viewport", { height: () => 500, @@ -48,11 +48,11 @@ set_global("stream_popover", { hide_streamlist_sidebar: noop, }); -set_global("stream_data", {}); +const stream_data = set_global("stream_data", {}); const ClipboardJS = noop; -rewiremock.proxy(() => zrequire("popovers"), { +const popovers = rewiremock.proxy(() => zrequire("popovers"), { clipboard: ClipboardJS, }); diff --git a/frontend_tests/node_tests/presence.js b/frontend_tests/node_tests/presence.js index b44ed69d40..b6831123a2 100644 --- a/frontend_tests/node_tests/presence.js +++ b/frontend_tests/node_tests/presence.js @@ -6,14 +6,14 @@ const {set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); const people = zrequire("people"); -zrequire("presence"); +const presence = zrequire("presence"); const return_false = function () { return false; }; -set_global("server_events", {}); -set_global("reload_state", { +const server_events = set_global("server_events", {}); +const reload_state = set_global("reload_state", { is_in_progress: return_false, }); diff --git a/frontend_tests/node_tests/reactions.js b/frontend_tests/node_tests/reactions.js index 9809fda2cd..d0df3b9bce 100644 --- a/frontend_tests/node_tests/reactions.js +++ b/frontend_tests/node_tests/reactions.js @@ -15,7 +15,7 @@ const emoji_codes = zrequire("emoji_codes", "generated/emoji/emoji_codes.json"); const emoji = zrequire("emoji", "shared/js/emoji"); const people = zrequire("people"); -zrequire("reactions"); +const reactions = zrequire("reactions"); set_global("page_params", { user_id: 5, @@ -47,8 +47,8 @@ const emoji_params = { emoji.initialize(emoji_params); -set_global("channel", {}); -set_global("emoji_picker", { +const channel = set_global("channel", {}); +const emoji_picker = set_global("emoji_picker", { hide_emoji_popover() {}, }); @@ -108,7 +108,7 @@ const message = { ], }; -set_global("message_store", { +const message_store = set_global("message_store", { get(message_id) { assert.equal(message_id, 1001); return message; diff --git a/frontend_tests/node_tests/recent_topics.js b/frontend_tests/node_tests/recent_topics.js index 506dacac65..bcdc9b7856 100644 --- a/frontend_tests/node_tests/recent_topics.js +++ b/frontend_tests/node_tests/recent_topics.js @@ -19,7 +19,7 @@ set_global( set_global("hashchange", { exit_overlay: noop, }); -set_global("overlays", { +const overlays = set_global("overlays", { open_overlay: (opts) => { overlays.close_callback = opts.on_close; }, @@ -55,7 +55,7 @@ set_global("hash_util", { set_global("recent_senders", { get_topic_recent_senders: () => [1, 2], }); -set_global("ListWidget", { +const ListWidget = set_global("ListWidget", { modifier: noop, create: (container, mapped_topic_values, opts) => { const formatted_topics = []; diff --git a/frontend_tests/node_tests/rendered_markdown.js b/frontend_tests/node_tests/rendered_markdown.js index d5dd517ce3..c854783884 100644 --- a/frontend_tests/node_tests/rendered_markdown.js +++ b/frontend_tests/node_tests/rendered_markdown.js @@ -8,8 +8,8 @@ const {make_zjquery} = require("../zjsunit/zjquery"); const rm = zrequire("rendered_markdown"); const people = zrequire("people"); -zrequire("user_groups"); -zrequire("stream_data"); +const user_groups = zrequire("user_groups"); +const stream_data = zrequire("stream_data"); zrequire("timerender"); set_global("$", make_zjquery()); diff --git a/frontend_tests/node_tests/schema.js b/frontend_tests/node_tests/schema.js index e72ec55ae6..5b8f3f6dac 100644 --- a/frontend_tests/node_tests/schema.js +++ b/frontend_tests/node_tests/schema.js @@ -5,7 +5,7 @@ const {strict: assert} = require("assert"); const {zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -zrequire("schema"); +const schema = zrequire("schema"); run_test("basics", () => { assert.equal(schema.check_string("x", "fred"), undefined); diff --git a/frontend_tests/node_tests/scroll_util.js b/frontend_tests/node_tests/scroll_util.js index 3d522840c4..81215c13cb 100644 --- a/frontend_tests/node_tests/scroll_util.js +++ b/frontend_tests/node_tests/scroll_util.js @@ -5,7 +5,7 @@ const {strict: assert} = require("assert"); const {set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -zrequire("scroll_util"); +const scroll_util = 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 dc0cc29b09..edf32ec509 100644 --- a/frontend_tests/node_tests/search.js +++ b/frontend_tests/node_tests/search.js @@ -9,9 +9,9 @@ const {make_zjquery} = require("../zjsunit/zjquery"); set_global("page_params", { search_pills_enabled: true, }); -zrequire("search"); -zrequire("search_pill"); -zrequire("Filter", "js/filter"); +const search = zrequire("search"); +const search_pill = zrequire("search_pill"); +const Filter = zrequire("Filter", "js/filter"); zrequire("message_view_header"); const noop = () => {}; @@ -19,13 +19,13 @@ const return_true = () => true; const return_false = () => false; set_global("$", make_zjquery()); -set_global("narrow_state", {filter: return_false}); -set_global("search_suggestion", {}); +const narrow_state = set_global("narrow_state", {filter: return_false}); +const search_suggestion = set_global("search_suggestion", {}); set_global("ui_util", { change_tab_to: noop, place_caret_at_end: noop, }); -set_global("narrow", {}); +const narrow = set_global("narrow", {}); set_global("search_pill_widget", { widget: { getByID: return_true, diff --git a/frontend_tests/node_tests/search_legacy.js b/frontend_tests/node_tests/search_legacy.js index 4181c3b060..eeb5b3dbc4 100644 --- a/frontend_tests/node_tests/search_legacy.js +++ b/frontend_tests/node_tests/search_legacy.js @@ -9,7 +9,7 @@ const {make_zjquery} = require("../zjsunit/zjquery"); set_global("page_params", { search_pills_enabled: false, }); -zrequire("search"); +const search = zrequire("search"); zrequire("message_view_header"); const noop = () => {}; @@ -17,13 +17,13 @@ const return_true = () => true; const return_false = () => false; set_global("$", make_zjquery()); -set_global("narrow_state", {}); -set_global("search_suggestion", {}); +const narrow_state = set_global("narrow_state", {}); +const search_suggestion = set_global("search_suggestion", {}); set_global("ui_util", { change_tab_to: noop, }); -set_global("narrow", {}); -set_global("Filter", {}); +const narrow = set_global("narrow", {}); +const Filter = set_global("Filter", {}); set_global("setTimeout", (func) => func()); diff --git a/frontend_tests/node_tests/search_pill.js b/frontend_tests/node_tests/search_pill.js index ce4b7e614a..077a23b498 100644 --- a/frontend_tests/node_tests/search_pill.js +++ b/frontend_tests/node_tests/search_pill.js @@ -5,8 +5,8 @@ const {strict: assert} = require("assert"); const {zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -zrequire("search_pill"); -zrequire("input_pill"); +const search_pill = zrequire("search_pill"); +const input_pill = zrequire("input_pill"); zrequire("Filter", "js/filter"); const is_starred_item = { diff --git a/frontend_tests/node_tests/search_suggestion.js b/frontend_tests/node_tests/search_suggestion.js index 91e7206b6a..d07a4236e4 100644 --- a/frontend_tests/node_tests/search_suggestion.js +++ b/frontend_tests/node_tests/search_suggestion.js @@ -21,9 +21,9 @@ const huddle_data = zrequire("huddle_data"); zrequire("typeahead_helper"); zrequire("Filter", "js/filter"); -zrequire("narrow_state"); -zrequire("stream_data"); -zrequire("stream_topic_history"); +const narrow_state = zrequire("narrow_state"); +const stream_data = zrequire("stream_data"); +const stream_topic_history = zrequire("stream_topic_history"); const people = zrequire("people"); zrequire("unread"); zrequire("common"); diff --git a/frontend_tests/node_tests/search_suggestion_legacy.js b/frontend_tests/node_tests/search_suggestion_legacy.js index b2c9f9686d..41766debf7 100644 --- a/frontend_tests/node_tests/search_suggestion_legacy.js +++ b/frontend_tests/node_tests/search_suggestion_legacy.js @@ -20,9 +20,9 @@ const huddle_data = zrequire("huddle_data"); zrequire("typeahead_helper"); zrequire("Filter", "js/filter"); -zrequire("narrow_state"); -zrequire("stream_data"); -zrequire("stream_topic_history"); +const narrow_state = zrequire("narrow_state"); +const stream_data = zrequire("stream_data"); +const stream_topic_history = zrequire("stream_topic_history"); const people = zrequire("people"); zrequire("unread"); zrequire("common"); diff --git a/frontend_tests/node_tests/server_events.js b/frontend_tests/node_tests/server_events.js index a6e80dfdf2..6ad23e59bf 100644 --- a/frontend_tests/node_tests/server_events.js +++ b/frontend_tests/node_tests/server_events.js @@ -13,10 +13,10 @@ stub_out_jquery(); zrequire("message_store"); zrequire("server_events_dispatch"); -zrequire("server_events"); +const server_events = zrequire("server_events"); zrequire("sent_messages"); -set_global("channel", {}); +const channel = set_global("channel", {}); set_global("home_msg_list", { select_id: noop, selected_id() { diff --git a/frontend_tests/node_tests/settings_bots.js b/frontend_tests/node_tests/settings_bots.js index a115e309dc..c0e5c2a445 100644 --- a/frontend_tests/node_tests/settings_bots.js +++ b/frontend_tests/node_tests/settings_bots.js @@ -29,17 +29,17 @@ const bot_data_params = { ], }; -set_global("avatar", {}); +const avatar = set_global("avatar", {}); set_global("$", make_zjquery()); -zrequire("bot_data"); +const bot_data = zrequire("bot_data"); function ClipboardJS(sel) { assert.equal(sel, "#copy_zuliprc"); } -rewiremock.proxy(() => zrequire("settings_bots"), { +const settings_bots = rewiremock.proxy(() => zrequire("settings_bots"), { clipboard: ClipboardJS, }); diff --git a/frontend_tests/node_tests/settings_emoji.js b/frontend_tests/node_tests/settings_emoji.js index d9f9bd61e6..98418a2c90 100644 --- a/frontend_tests/node_tests/settings_emoji.js +++ b/frontend_tests/node_tests/settings_emoji.js @@ -7,8 +7,8 @@ const {run_test} = require("../zjsunit/test"); const {make_zjquery} = require("../zjsunit/zjquery"); set_global("$", make_zjquery()); -set_global("upload_widget", {}); -zrequire("settings_emoji"); +const upload_widget = set_global("upload_widget", {}); +const settings_emoji = zrequire("settings_emoji"); run_test("build_emoji_upload_widget", () => { let build_widget_stub = false; diff --git a/frontend_tests/node_tests/settings_muting.js b/frontend_tests/node_tests/settings_muting.js index c03dfe2936..98e65038c2 100644 --- a/frontend_tests/node_tests/settings_muting.js +++ b/frontend_tests/node_tests/settings_muting.js @@ -9,10 +9,10 @@ const {make_zjquery} = require("../zjsunit/zjquery"); set_global("$", make_zjquery()); zrequire("timerender"); -zrequire("settings_muting"); -zrequire("stream_data"); -zrequire("muting"); -set_global("muting_ui", {}); +const settings_muting = zrequire("settings_muting"); +const stream_data = zrequire("stream_data"); +const muting = zrequire("muting"); +const muting_ui = set_global("muting_ui", {}); const noop = function () {}; diff --git a/frontend_tests/node_tests/settings_org.js b/frontend_tests/node_tests/settings_org.js index 051f2525c6..c75d790421 100644 --- a/frontend_tests/node_tests/settings_org.js +++ b/frontend_tests/node_tests/settings_org.js @@ -41,8 +41,8 @@ const _page_params = { realm_authentication_methods: {}, }; -const _realm_icon = {}; -const _channel = {}; +const realm_icon = set_global("realm_icon", {}); +const channel = set_global("channel", {}); stub_templates((name, data) => { if (name === "settings/admin_realm_domains_list") { @@ -52,7 +52,7 @@ stub_templates((name, data) => { throw new Error(`Unknown template ${name}`); }); -const _overlays = {}; +const overlays = set_global("overlays", {}); const _ui_report = { success(msg, elem) { @@ -72,29 +72,26 @@ const _ListWidget = { create: () => ({init: noop}), }; -set_global("channel", _channel); set_global("csrf_token", "token-stub"); set_global("FormData", _FormData); set_global("jQuery", _jQuery); set_global("loading", _loading); -set_global("overlays", _overlays); set_global("page_params", _page_params); -set_global("realm_icon", _realm_icon); set_global("realm_logo", _realm_logo); set_global("ui_report", _ui_report); set_global("ListWidget", _ListWidget); const settings_config = zrequire("settings_config"); const settings_bots = zrequire("settings_bots"); -zrequire("stream_data"); -rewiremock.proxy(() => zrequire("settings_account"), { +const stream_data = zrequire("stream_data"); +const settings_account = rewiremock.proxy(() => zrequire("settings_account"), { // Setup is only imported to set the // setup.password_change_in_progress flag. "../../static/js/setup": {}, }); -zrequire("settings_org"); +const settings_org = zrequire("settings_org"); zrequire("settings_ui"); -zrequire("dropdown_list_widget"); +const dropdown_list_widget = zrequire("dropdown_list_widget"); run_test("unloaded", () => { // This test mostly gets us line coverage, and makes diff --git a/frontend_tests/node_tests/settings_profile_fields.js b/frontend_tests/node_tests/settings_profile_fields.js index 9b761149fb..f814d13fa2 100644 --- a/frontend_tests/node_tests/settings_profile_fields.js +++ b/frontend_tests/node_tests/settings_profile_fields.js @@ -11,7 +11,7 @@ const {make_zjquery} = require("../zjsunit/zjquery"); set_global("page_params", {}); set_global("$", make_zjquery()); -set_global("loading", {}); +const loading = set_global("loading", {}); const SHORT_TEXT_ID = 1; const CHOICE_ID = 3; @@ -39,7 +39,7 @@ page_params.custom_profile_field_types = { }, }; -rewiremock.proxy(() => zrequire("settings_profile_fields"), { +const settings_profile_fields = rewiremock.proxy(() => zrequire("settings_profile_fields"), { sortablejs: {default: {create: () => {}}}, }); diff --git a/frontend_tests/node_tests/settings_user_groups.js b/frontend_tests/node_tests/settings_user_groups.js index 17db804d95..d72613503f 100644 --- a/frontend_tests/node_tests/settings_user_groups.js +++ b/frontend_tests/node_tests/settings_user_groups.js @@ -9,12 +9,12 @@ const {set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); const {make_zjquery} = require("../zjsunit/zjquery"); -zrequire("user_pill"); +const user_pill = zrequire("user_pill"); zrequire("pill_typeahead"); -zrequire("settings_user_groups"); +const settings_user_groups = zrequire("settings_user_groups"); set_global("$", make_zjquery()); -set_global("confirm_dialog", {}); +const confirm_dialog = set_global("confirm_dialog", {}); const noop = function () {}; @@ -25,14 +25,14 @@ const settings_config = zrequire("settings_config"); let create_item_handler; -set_global("channel", {}); -set_global("typeahead_helper", {}); -set_global("user_groups", { +const channel = set_global("channel", {}); +const typeahead_helper = set_global("typeahead_helper", {}); +const user_groups = set_global("user_groups", { get_user_group_from_id: noop, remove: noop, add: noop, }); -set_global("ui_report", {}); +const ui_report = set_global("ui_report", {}); const people = zrequire("people"); diff --git a/frontend_tests/node_tests/spoilers.js b/frontend_tests/node_tests/spoilers.js index 4632f329fc..32d9410a06 100644 --- a/frontend_tests/node_tests/spoilers.js +++ b/frontend_tests/node_tests/spoilers.js @@ -7,7 +7,7 @@ const {run_test} = require("../zjsunit/test"); const {make_zjquery} = require("../zjsunit/zjquery"); set_global("$", make_zjquery()); -zrequire("spoilers"); +const spoilers = zrequire("spoilers"); // This function is taken from rendered_markdown.js and slightly modified. const $array = (array) => { diff --git a/frontend_tests/node_tests/stream_data.js b/frontend_tests/node_tests/stream_data.js index b2d45a4546..7f470541dc 100644 --- a/frontend_tests/node_tests/stream_data.js +++ b/frontend_tests/node_tests/stream_data.js @@ -13,17 +13,17 @@ set_global("page_params", { is_guest: false, }); -zrequire("color_data"); +const color_data = zrequire("color_data"); zrequire("hash_util"); -zrequire("stream_topic_history"); +const stream_topic_history = zrequire("stream_topic_history"); const people = zrequire("people"); -zrequire("stream_color"); -zrequire("stream_data"); +const stream_color = zrequire("stream_color"); +const stream_data = zrequire("stream_data"); zrequire("FetchStatus", "js/fetch_status"); zrequire("Filter", "js/filter"); zrequire("MessageListData", "js/message_list_data"); zrequire("MessageListView", "js/message_list_view"); -zrequire("message_list"); +const message_list = zrequire("message_list"); const settings_config = zrequire("settings_config"); const me = { diff --git a/frontend_tests/node_tests/stream_edit.js b/frontend_tests/node_tests/stream_edit.js index bf6119c341..086a0afa01 100644 --- a/frontend_tests/node_tests/stream_edit.js +++ b/frontend_tests/node_tests/stream_edit.js @@ -29,8 +29,8 @@ set_global("stream_color", { set_global("stream_ui_updates", { update_add_subscriptions_elements: noop, }); -set_global("typeahead_helper", {}); -set_global("ui", { +const typeahead_helper = set_global("typeahead_helper", {}); +const ui = set_global("ui", { get_scroll_element: noop, }); set_global("$", make_zjquery()); @@ -40,10 +40,10 @@ const peer_data = zrequire("peer_data"); const people = zrequire("people"); zrequire("pill_typeahead"); zrequire("subs"); -zrequire("stream_edit"); -zrequire("stream_data"); -zrequire("stream_pill"); -zrequire("user_pill"); +const stream_edit = zrequire("stream_edit"); +const stream_data = zrequire("stream_data"); +const stream_pill = zrequire("stream_pill"); +const user_pill = zrequire("user_pill"); stream_edit.sort_but_pin_current_user_on_top = noop; diff --git a/frontend_tests/node_tests/stream_events.js b/frontend_tests/node_tests/stream_events.js index cd028d3a22..7d110e3bd7 100644 --- a/frontend_tests/node_tests/stream_events.js +++ b/frontend_tests/node_tests/stream_events.js @@ -19,18 +19,18 @@ set_global("settings_notifications", _settings_notifications); set_global("color_data", {}); set_global("current_msg_list", {}); -set_global("message_util", {}); +const message_util = set_global("message_util", {}); set_global("stream_color", {}); -set_global("stream_list", {}); +const stream_list = set_global("stream_list", {}); set_global("stream_muting", {}); -set_global("subs", {}); +let subs = set_global("subs", {}); const peer_data = zrequire("peer_data"); const people = zrequire("people"); -zrequire("stream_data"); -zrequire("stream_events"); -zrequire("Filter", "js/filter"); -zrequire("narrow_state"); +const stream_data = zrequire("stream_data"); +const stream_events = zrequire("stream_events"); +const Filter = zrequire("Filter", "js/filter"); +const narrow_state = zrequire("narrow_state"); zrequire("message_view_header"); const george = { @@ -243,7 +243,7 @@ run_test("marked_subscribed", (override) => { }, }); - set_global("subs", {update_settings_for_subscribed: noop}); + subs = set_global("subs", {update_settings_for_subscribed: noop}); set_global("overlays", {streams_open: return_true}); // Test basic dispatching and updating stream color diff --git a/frontend_tests/node_tests/stream_list.js b/frontend_tests/node_tests/stream_list.js index 3ba9dd433a..1e021e58ae 100644 --- a/frontend_tests/node_tests/stream_list.js +++ b/frontend_tests/node_tests/stream_list.js @@ -11,16 +11,16 @@ set_global("document", "document-stub"); set_global("$", make_zjquery()); zrequire("unread_ui"); -zrequire("Filter", "js/filter"); -zrequire("stream_sort"); +const Filter = zrequire("Filter", "js/filter"); +const stream_sort = zrequire("stream_sort"); zrequire("colorspace"); -zrequire("stream_color"); +const stream_color = zrequire("stream_color"); zrequire("hash_util"); -zrequire("unread"); -zrequire("stream_data"); -zrequire("scroll_util"); +const unread = zrequire("unread"); +const stream_data = zrequire("stream_data"); +const scroll_util = zrequire("scroll_util"); zrequire("list_cursor"); -zrequire("stream_list"); +const stream_list = zrequire("stream_list"); zrequire("topic_zoom"); zrequire("ui"); set_global("page_params", { @@ -38,7 +38,7 @@ const return_true = function () { return true; }; -set_global("topic_list", {}); +const topic_list = set_global("topic_list", {}); set_global("overlays", {}); set_global("popovers", {}); @@ -387,10 +387,11 @@ run_test("zoom_in_and_zoom_out", () => { set_global("$", make_zjquery()); +let narrow_state; run_test("narrowing", () => { initialize_stream_data(); - set_global("narrow_state", { + narrow_state = set_global("narrow_state", { stream() { return "devel"; }, diff --git a/frontend_tests/node_tests/stream_pill.js b/frontend_tests/node_tests/stream_pill.js index 430f3a2aa3..f9404b8bc9 100644 --- a/frontend_tests/node_tests/stream_pill.js +++ b/frontend_tests/node_tests/stream_pill.js @@ -6,8 +6,8 @@ const {zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); const peer_data = zrequire("peer_data"); -zrequire("stream_data"); -zrequire("stream_pill"); +const stream_data = zrequire("stream_data"); +const stream_pill = zrequire("stream_pill"); const denmark = { stream_id: 1, diff --git a/frontend_tests/node_tests/stream_search.js b/frontend_tests/node_tests/stream_search.js index bd2b3d8233..40126d8bca 100644 --- a/frontend_tests/node_tests/stream_search.js +++ b/frontend_tests/node_tests/stream_search.js @@ -9,7 +9,7 @@ const {make_zjquery} = require("../zjsunit/zjquery"); // lives in stream_list.js. set_global("$", make_zjquery()); -zrequire("stream_list"); +const stream_list = zrequire("stream_list"); const noop = () => {}; @@ -18,8 +18,8 @@ set_global("resize", { resize_stream_filters_container: noop, }); -set_global("popovers", {}); -set_global("stream_popover", {}); +const popovers = set_global("popovers", {}); +const stream_popover = set_global("stream_popover", {}); function expand_sidebar() { $(".app-main .column-left").addClass("expanded"); diff --git a/frontend_tests/node_tests/stream_sort.js b/frontend_tests/node_tests/stream_sort.js index a1c059f1ec..eef94f6f1b 100644 --- a/frontend_tests/node_tests/stream_sort.js +++ b/frontend_tests/node_tests/stream_sort.js @@ -5,8 +5,8 @@ const {strict: assert} = require("assert"); const {zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -zrequire("stream_data"); -zrequire("stream_sort"); +const stream_data = zrequire("stream_data"); +const stream_sort = zrequire("stream_sort"); run_test("no_subscribed_streams", () => { assert.equal(stream_sort.sort_groups([]), undefined); diff --git a/frontend_tests/node_tests/stream_topic_history.js b/frontend_tests/node_tests/stream_topic_history.js index aaac339290..a61bd28043 100644 --- a/frontend_tests/node_tests/stream_topic_history.js +++ b/frontend_tests/node_tests/stream_topic_history.js @@ -5,12 +5,12 @@ const {strict: assert} = require("assert"); const {set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -zrequire("unread"); -zrequire("stream_data"); -zrequire("stream_topic_history"); +const unread = zrequire("unread"); +const stream_data = zrequire("stream_data"); +const stream_topic_history = zrequire("stream_topic_history"); -set_global("channel", {}); -set_global("message_list", {}); +const channel = set_global("channel", {}); +const message_list = set_global("message_list", {}); run_test("basics", () => { const stream_id = 55; diff --git a/frontend_tests/node_tests/submessage.js b/frontend_tests/node_tests/submessage.js index 1d716d26a9..e08e1e6642 100644 --- a/frontend_tests/node_tests/submessage.js +++ b/frontend_tests/node_tests/submessage.js @@ -5,11 +5,11 @@ const {strict: assert} = require("assert"); const {set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -zrequire("submessage"); +const submessage = zrequire("submessage"); -set_global("channel", {}); -set_global("widgetize", {}); -set_global("message_store", {}); +const channel = set_global("channel", {}); +const widgetize = set_global("widgetize", {}); +const message_store = set_global("message_store", {}); run_test("get_message_events", () => { let msg = {}; diff --git a/frontend_tests/node_tests/subs.js b/frontend_tests/node_tests/subs.js index 0185078146..2444c80c33 100644 --- a/frontend_tests/node_tests/subs.js +++ b/frontend_tests/node_tests/subs.js @@ -7,11 +7,11 @@ const {set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); const {make_zjquery} = require("../zjsunit/zjquery"); -set_global("ui", { +const ui = set_global("ui", { get_content_element: (element) => element, get_scroll_element: (element) => element, }); -zrequire("stream_data"); +const stream_data = zrequire("stream_data"); zrequire("search_util"); set_global("page_params", {}); @@ -21,7 +21,7 @@ set_global("location", { hash: `#streams/${denmark_stream_id}/announce`, }); -zrequire("subs"); +const subs = zrequire("subs"); set_global("$", make_zjquery()); set_global("hash_util", { diff --git a/frontend_tests/node_tests/timerender.js b/frontend_tests/node_tests/timerender.js index 0f72b15849..d2f9fc1505 100644 --- a/frontend_tests/node_tests/timerender.js +++ b/frontend_tests/node_tests/timerender.js @@ -14,7 +14,7 @@ set_global("page_params", { twenty_four_hour_time: true, }); -zrequire("timerender"); +const timerender = zrequire("timerender"); run_test("render_now_returns_today", () => { const today = new Date(1555091573000); // Friday 4/12/2019 5:52:53 PM (UTC+0) diff --git a/frontend_tests/node_tests/top_left_corner.js b/frontend_tests/node_tests/top_left_corner.js index 6c8794400f..9532b2542a 100644 --- a/frontend_tests/node_tests/top_left_corner.js +++ b/frontend_tests/node_tests/top_left_corner.js @@ -8,11 +8,11 @@ const {make_zjquery} = require("../zjsunit/zjquery"); set_global("$", make_zjquery()); -zrequire("Filter", "js/filter"); +const Filter = zrequire("Filter", "js/filter"); zrequire("unread_ui"); const people = zrequire("people"); -zrequire("top_left_corner"); +const top_left_corner = zrequire("top_left_corner"); run_test("narrowing", () => { // activating narrow diff --git a/frontend_tests/node_tests/topic_generator.js b/frontend_tests/node_tests/topic_generator.js index bab245f22b..0ebaa33f6d 100644 --- a/frontend_tests/node_tests/topic_generator.js +++ b/frontend_tests/node_tests/topic_generator.js @@ -8,11 +8,11 @@ const {run_test} = require("../zjsunit/test"); const pm_conversations = zrequire("pm_conversations"); pm_conversations.recent = {}; -zrequire("muting"); -zrequire("unread"); -zrequire("stream_data"); -zrequire("stream_topic_history"); -zrequire("stream_sort"); +const muting = zrequire("muting"); +const unread = zrequire("unread"); +const stream_data = zrequire("stream_data"); +const stream_topic_history = zrequire("stream_topic_history"); +const stream_sort = zrequire("stream_sort"); const tg = zrequire("topic_generator"); run_test("streams", () => { diff --git a/frontend_tests/node_tests/topic_list_data.js b/frontend_tests/node_tests/topic_list_data.js index ee510c8298..b022c97a94 100644 --- a/frontend_tests/node_tests/topic_list_data.js +++ b/frontend_tests/node_tests/topic_list_data.js @@ -7,15 +7,15 @@ const _ = require("lodash"); const {set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -set_global("narrow_state", {}); +const narrow_state = set_global("narrow_state", {}); set_global("unread", {}); -set_global("muting", {}); +const muting = set_global("muting", {}); set_global("message_list", {}); zrequire("hash_util"); -zrequire("stream_data"); -zrequire("unread"); -zrequire("stream_topic_history"); +const stream_data = zrequire("stream_data"); +const unread = zrequire("unread"); +const stream_topic_history = zrequire("stream_topic_history"); const topic_list_data = zrequire("topic_list_data"); const general = { diff --git a/frontend_tests/node_tests/transmit.js b/frontend_tests/node_tests/transmit.js index 88770b6ed3..09ce8d82a7 100644 --- a/frontend_tests/node_tests/transmit.js +++ b/frontend_tests/node_tests/transmit.js @@ -10,16 +10,16 @@ const noop = function () {}; set_global("$", make_zjquery()); set_global("page_params", {}); -set_global("channel", {}); -set_global("reload", {}); -set_global("reload_state", {}); -set_global("sent_messages", { +const channel = set_global("channel", {}); +const reload = set_global("reload", {}); +const reload_state = set_global("reload_state", {}); +const sent_messages = set_global("sent_messages", { start_tracking_message: noop, report_server_ack: noop, }); const people = zrequire("people"); -zrequire("transmit"); +const transmit = zrequire("transmit"); run_test("transmit_message_ajax", () => { let success_func_called; diff --git a/frontend_tests/node_tests/typeahead_helper.js b/frontend_tests/node_tests/typeahead_helper.js index 3cfd461a42..f3e899ac9e 100644 --- a/frontend_tests/node_tests/typeahead_helper.js +++ b/frontend_tests/node_tests/typeahead_helper.js @@ -14,10 +14,10 @@ const pm_conversations = zrequire("pm_conversations"); page_params.realm_email_address_visibility = settings_config.email_address_visibility_values.admins_only.code; -zrequire("recent_senders"); +const recent_senders = zrequire("recent_senders"); const peer_data = zrequire("peer_data"); const people = zrequire("people"); -zrequire("stream_data"); +const stream_data = zrequire("stream_data"); zrequire("narrow"); zrequire("hash_util"); diff --git a/frontend_tests/node_tests/typing_data.js b/frontend_tests/node_tests/typing_data.js index 809a5a98b8..318fd789a8 100644 --- a/frontend_tests/node_tests/typing_data.js +++ b/frontend_tests/node_tests/typing_data.js @@ -5,7 +5,7 @@ const {strict: assert} = require("assert"); const {set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -zrequire("typing_data"); +const typing_data = zrequire("typing_data"); run_test("basics", () => { // The typing_data needs to be robust with lists of diff --git a/frontend_tests/node_tests/typing_status.js b/frontend_tests/node_tests/typing_status.js index 31d6c32e62..da3b0a1a3d 100644 --- a/frontend_tests/node_tests/typing_status.js +++ b/frontend_tests/node_tests/typing_status.js @@ -5,8 +5,8 @@ const {strict: assert} = require("assert"); const {set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -zrequire("typing"); -zrequire("compose_pm_pill"); +const typing = zrequire("typing"); +const compose_pm_pill = zrequire("compose_pm_pill"); const typing_status = zrequire("typing_status", "shared/js/typing_status"); function make_time(secs) { diff --git a/frontend_tests/node_tests/ui_init.js b/frontend_tests/node_tests/ui_init.js index a29c93f4a8..59a32b045d 100644 --- a/frontend_tests/node_tests/ui_init.js +++ b/frontend_tests/node_tests/ui_init.js @@ -38,7 +38,7 @@ set_global("document", { set_global("csrf_token", "whatever"); set_global("$", () => {}); -set_global("resize", {}); +const resize = set_global("resize", {}); set_global("page_params", {}); const ignore_modules = [ @@ -69,11 +69,14 @@ const ignore_modules = [ "unread_ui", ]; -for (const mod of ignore_modules) { - set_global(mod, { - initialize: () => {}, - }); -} +const {server_events, ui} = Object.fromEntries( + ignore_modules.map((mod) => [ + mod, + set_global(mod, { + initialize: () => {}, + }), + ]), +); util.is_mobile = () => false; stub_templates(() => "some-html"); @@ -101,8 +104,8 @@ zrequire("user_groups"); zrequire("unread"); zrequire("bot_data"); zrequire("markdown"); -zrequire("upload"); -zrequire("compose"); +const upload = zrequire("upload"); +const compose = zrequire("compose"); zrequire("composebox_typeahead"); zrequire("narrow"); zrequire("search_suggestion"); diff --git a/frontend_tests/node_tests/unread.js b/frontend_tests/node_tests/unread.js index 49e8bb3dec..5ec0ef09b9 100644 --- a/frontend_tests/node_tests/unread.js +++ b/frontend_tests/node_tests/unread.js @@ -7,10 +7,10 @@ const _ = require("lodash"); const {set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -zrequire("muting"); +const muting = zrequire("muting"); const people = zrequire("people"); -zrequire("stream_data"); -zrequire("unread"); +const stream_data = zrequire("stream_data"); +const unread = zrequire("unread"); set_global("page_params", { realm_push_notifications_enabled: false, @@ -22,7 +22,7 @@ const {FoldDict} = zrequire("fold_dict"); set_global("narrow_state", {}); set_global("current_msg_list", {}); set_global("home_msg_list", {}); -set_global("message_store", {}); +const message_store = set_global("message_store", {}); const me = { email: "me@example.com", diff --git a/frontend_tests/node_tests/upgrade.js b/frontend_tests/node_tests/upgrade.js index e25186793d..6b909be045 100644 --- a/frontend_tests/node_tests/upgrade.js +++ b/frontend_tests/node_tests/upgrade.js @@ -14,11 +14,7 @@ const template = fs.readFileSync("templates/corporate/upgrade.html", "utf-8"); const dom = new JSDOM(template, {pretendToBeVisual: true}); const document = dom.window.document; -set_global("helpers", { - set_tab: noop, -}); - -set_global("StripeCheckout", { +const StripeCheckout = set_global("StripeCheckout", { configure: noop, }); @@ -29,7 +25,7 @@ set_global("page_params", { percent_off: 20, }); -zrequire("helpers", "js/billing/helpers"); +const helpers = zrequire("helpers", "js/billing/helpers"); set_global("$", make_zjquery()); run_test("initialize", () => { diff --git a/frontend_tests/node_tests/upload.js b/frontend_tests/node_tests/upload.js index 23a8a1c2d3..112417e1c8 100644 --- a/frontend_tests/node_tests/upload.js +++ b/frontend_tests/node_tests/upload.js @@ -26,10 +26,10 @@ set_global("bridge", false); document.location.protocol = "https:"; document.location.host = "foo.com"; -zrequire("compose_ui"); +const compose_ui = zrequire("compose_ui"); zrequire("compose_state"); zrequire("compose"); -zrequire("compose_actions"); +const compose_actions = zrequire("compose_actions"); const plugin_stub = { prototype: { @@ -37,7 +37,7 @@ const plugin_stub = { }, }; -zrequire("upload"); +let upload = zrequire("upload"); run_test("make_upload_absolute", () => { let uri = "/user_uploads/5/d4/6lSlfIPIg9nDI2Upj0Mq_EbE/kerala.png"; @@ -358,7 +358,7 @@ run_test("uppy_config", () => { }; } uppy_stub.Plugin = plugin_stub; - rewiremock.proxy(() => require("../../static/js/upload"), {"@uppy/core": uppy_stub}); + upload = rewiremock.proxy(() => require("../../static/js/upload"), {"@uppy/core": uppy_stub}); upload.setup_upload({mode: "compose"}); assert.equal(uppy_stub_called, true); @@ -502,7 +502,7 @@ run_test("uppy_events", () => { }; } uppy_stub.Plugin = plugin_stub; - rewiremock.proxy(() => require("../../static/js/upload"), {"@uppy/core": uppy_stub}); + upload = rewiremock.proxy(() => require("../../static/js/upload"), {"@uppy/core": uppy_stub}); upload.setup_upload({mode: "compose"}); assert.equal(Object.keys(callbacks).length, 5); diff --git a/frontend_tests/node_tests/user_events.js b/frontend_tests/node_tests/user_events.js index 731d44982c..972aa1684f 100644 --- a/frontend_tests/node_tests/user_events.js +++ b/frontend_tests/node_tests/user_events.js @@ -10,7 +10,7 @@ set_global("$", make_zjquery()); const people = zrequire("people"); const settings_config = zrequire("settings_config"); -zrequire("user_events"); +const user_events = zrequire("user_events"); set_global("activity", { redraw() {}, @@ -51,12 +51,12 @@ set_global("compose", { update_email() {}, }); -set_global("settings_account", { +const settings_account = set_global("settings_account", { update_email() {}, update_full_name() {}, }); -set_global("message_live_update", {}); +const message_live_update = set_global("message_live_update", {}); const me = { email: "me@example.com", diff --git a/frontend_tests/node_tests/user_groups.js b/frontend_tests/node_tests/user_groups.js index 5be9713179..902d0d83d4 100644 --- a/frontend_tests/node_tests/user_groups.js +++ b/frontend_tests/node_tests/user_groups.js @@ -5,7 +5,7 @@ const {strict: assert} = require("assert"); const {zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -zrequire("user_groups"); +const user_groups = zrequire("user_groups"); run_test("user_groups", () => { const students = { diff --git a/frontend_tests/node_tests/user_pill.js b/frontend_tests/node_tests/user_pill.js index d0d1f61eb2..e8b676be01 100644 --- a/frontend_tests/node_tests/user_pill.js +++ b/frontend_tests/node_tests/user_pill.js @@ -6,7 +6,7 @@ const {set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); const people = zrequire("people"); -zrequire("user_pill"); +const user_pill = zrequire("user_pill"); zrequire("pill_typeahead"); set_global("page_params", {}); diff --git a/frontend_tests/node_tests/user_status.js b/frontend_tests/node_tests/user_status.js index 4339c94a3f..aa81ba53ca 100644 --- a/frontend_tests/node_tests/user_status.js +++ b/frontend_tests/node_tests/user_status.js @@ -5,8 +5,8 @@ const {strict: assert} = require("assert"); const {set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -set_global("channel", {}); -zrequire("user_status"); +const channel = set_global("channel", {}); +const user_status = zrequire("user_status"); function initialize() { const params = { diff --git a/frontend_tests/node_tests/vdom.js b/frontend_tests/node_tests/vdom.js index eaf438250b..37d967ac98 100644 --- a/frontend_tests/node_tests/vdom.js +++ b/frontend_tests/node_tests/vdom.js @@ -5,7 +5,7 @@ const {strict: assert} = require("assert"); const {zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -zrequire("vdom"); +const vdom = zrequire("vdom"); run_test("basics", () => { const opts = { diff --git a/frontend_tests/node_tests/widgetize.js b/frontend_tests/node_tests/widgetize.js index 8b7009228d..651748b01f 100644 --- a/frontend_tests/node_tests/widgetize.js +++ b/frontend_tests/node_tests/widgetize.js @@ -7,7 +7,7 @@ const {run_test} = require("../zjsunit/test"); const {make_zjquery} = require("../zjsunit/zjquery"); set_global("$", make_zjquery()); -set_global("poll_widget", {}); +const poll_widget = set_global("poll_widget", {}); set_global("todo_widget", {}); set_global("zform", {}); set_global("document", "document-stub"); @@ -15,9 +15,9 @@ set_global("document", "document-stub"); const return_true = () => true; const return_false = () => false; -zrequire("widgetize"); +const widgetize = zrequire("widgetize"); -set_global("narrow_state", {}); +const narrow_state = set_global("narrow_state", {}); set_global("current_msg_list", {}); run_test("activate", () => { diff --git a/frontend_tests/zjsunit/index.js b/frontend_tests/zjsunit/index.js index 2c840d0718..a95372d1a4 100644 --- a/frontend_tests/zjsunit/index.js +++ b/frontend_tests/zjsunit/index.js @@ -87,7 +87,7 @@ try { _.throttle = immediate; _.debounce = immediate; - namespace.set_global("blueslip", make_zblueslip()); + const blueslip = namespace.set_global("blueslip", make_zblueslip()); namespace.set_global("i18n", stub_i18n); namespace.clear_zulip_refs(); diff --git a/frontend_tests/zjsunit/namespace.js b/frontend_tests/zjsunit/namespace.js index 77a69512e8..1b81133ecc 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 () { - exports.set_global("$", () => ({ + const $ = exports.set_global("$", () => ({ on() {}, trigger() {}, hide() {}, diff --git a/frontend_tests/zjsunit/test.js b/frontend_tests/zjsunit/test.js index ab1e28fc3a..97a8ae45ea 100644 --- a/frontend_tests/zjsunit/test.js +++ b/frontend_tests/zjsunit/test.js @@ -26,5 +26,5 @@ exports.run_test = (label, f) => { throw error; } // defensively reset blueslip after each test. - blueslip.reset(); + window.blueslip.reset(); };