Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
node_tests: Skip unnecessary explicit uses of global.
Anders Kaseorgce42d1194dcd
diff --git a/.eslintrc.json b/.eslintrc.jsonindex fc52b7310fa..5257cf274b4 100644--- a/.eslintrc.json+++ b/.eslintrc.json@@ -361,6 +361,7 @@"files": ["frontend_tests/**"],"globals": {"document": false,+ "navigator": false,"window": false},"rules": {diff --git a/frontend_tests/node_tests/compose.js b/frontend_tests/node_tests/compose.jsindex b6b2705d94f..cca359455ca 100644--- a/frontend_tests/node_tests/compose.js+++ b/frontend_tests/node_tests/compose.js@@ -70,8 +70,8 @@ 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.-global.document.location.protocol = "https:";-global.document.location.host = "foo.com";+document.location.protocol = "https:";+document.location.host = "foo.com";zrequire("zcommand");zrequire("compose_ui");@@ -542,10 +542,10 @@ run_test("markdown_shortcuts", () => {let compose_value = $("#compose_textarea").val();let selected_word = "";- global.document.queryCommandEnabled = function () {+ document.queryCommandEnabled = function () {return queryCommandEnabled;};- global.document.execCommand = function (cmd, bool, markdown) {+ document.execCommand = function (cmd, bool, markdown) {const compose_textarea = $("#compose-textarea");const value = compose_textarea.val();$("#compose-textarea").val(@@ -1856,7 +1856,7 @@ run_test("create_message_object", () => {},}));- global.compose_state.get_message_type = function () {+ compose_state.get_message_type = function () {return "stream";};@@ -1873,7 +1873,7 @@ run_test("create_message_object", () => {assert.equal(message.topic, "lunch");assert.equal(message.content, "burrito");- global.compose_state.get_message_type = function () {+ compose_state.get_message_type = function () {return "private";};compose_state.private_message_recipient = function () {diff --git a/frontend_tests/node_tests/compose_actions.js b/frontend_tests/node_tests/compose_actions.jsindex 16dcf226191..e9457b89d71 100644--- a/frontend_tests/node_tests/compose_actions.js+++ b/frontend_tests/node_tests/compose_actions.js@@ -44,8 +44,6 @@ const respond_to_message = compose_actions.respond_to_message;const reply_with_mention = compose_actions.reply_with_mention;const quote_and_reply = compose_actions.quote_and_reply;-const compose_state = global.compose_state;-compose_state.private_message_recipient = (function () {let recipient;@@ -129,7 +127,7 @@ run_test("start", () => {compose_actions.clear_textarea = noop;// Start stream message- global.narrow_state.set_compose_defaults = function () {+ narrow_state.set_compose_defaults = function () {const opts = {};opts.stream = "stream1";opts.topic = "topic1";@@ -156,7 +154,7 @@ run_test("start", () => {};stream_data.add_sub(denmark);- global.narrow_state.set_compose_defaults = function () {+ narrow_state.set_compose_defaults = function () {const opts = {};opts.trigger = "new topic button";return opts;@@ -167,7 +165,7 @@ run_test("start", () => {assert.equal($("#stream_message_recipient_stream").val(), "Denmark");assert.equal($("#stream_message_recipient_topic").val(), "");- global.narrow_state.set_compose_defaults = function () {+ narrow_state.set_compose_defaults = function () {const opts = {};opts.trigger = "compose_hotkey";return opts;@@ -194,7 +192,7 @@ run_test("start", () => {stream_data.clear_subscriptions();// Start PM- global.narrow_state.set_compose_defaults = function () {+ narrow_state.set_compose_defaults = function () {const opts = {};opts.private_message_recipient = "[email protected]";return opts;diff --git a/frontend_tests/node_tests/composebox_typeahead.js b/frontend_tests/node_tests/composebox_typeahead.jsindex f1d3b57ea54..52e84ff3cb1 100644--- a/frontend_tests/node_tests/composebox_typeahead.js+++ b/frontend_tests/node_tests/composebox_typeahead.js@@ -285,9 +285,9 @@ const call_center = {members: [],};-global.user_groups.add(hamletcharacters);-global.user_groups.add(backend);-global.user_groups.add(call_center);+user_groups.add(hamletcharacters);+user_groups.add(backend);+user_groups.add(call_center);const make_emoji = function (emoji_dict) {return {emoji_name: emoji_dict.name, emoji_code: emoji_dict.emoji_code};@@ -1100,7 +1100,7 @@ run_test("initialize", () => {$("#compose-send-button").fadeOut = noop;$("#compose-send-button").fadeIn = noop;let channel_post_called = false;- global.channel.post = function (params) {+ channel.post = function (params) {assert.equal(params.url, "/json/users/me/enter-sends");assert.equal(params.idempotent, true);assert.deepEqual(params.data, {enter_sends: page_params.enter_sends});diff --git a/frontend_tests/node_tests/dispatch.js b/frontend_tests/node_tests/dispatch.jsindex 22ab5a244aa..5da120f7419 100644--- a/frontend_tests/node_tests/dispatch.js+++ b/frontend_tests/node_tests/dispatch.js@@ -74,7 +74,6 @@ set_global("page_params", {is_admin: true,realm_description: "already set description",});-const page_params = global.page_params;// For data-oriented modules, just use them, don't stub them.zrequire("alert_words");@@ -181,7 +180,7 @@ run_test("custom profile fields", (override) => {override("settings_profile_fields.populate_profile_fields", noop);override("settings_account.add_custom_profile_fields_to_settings", noop);dispatch(event);- assert_same(global.page_params.custom_profile_fields, event.fields);+ assert_same(page_params.custom_profile_fields, event.fields);});run_test("default_streams", (override) => {diff --git a/frontend_tests/node_tests/drafts.js b/frontend_tests/node_tests/drafts.jsindex feb1cddd634..7429e71c06f 100644--- a/frontend_tests/node_tests/drafts.js+++ b/frontend_tests/node_tests/drafts.js@@ -148,22 +148,22 @@ run_test("draft_model", () => {run_test("snapshot_message", () => {function stub_draft(draft) {- global.compose_state.get_message_type = function () {+ compose_state.get_message_type = function () {return draft.type;};- global.compose_state.composing = function () {+ compose_state.composing = function () {return Boolean(draft.type);};- global.compose_state.message_content = function () {+ compose_state.message_content = function () {return draft.content;};- global.compose_state.private_message_recipient = function () {+ compose_state.private_message_recipient = function () {return draft.private_message_recipient;};- global.compose_state.stream_name = function () {+ compose_state.stream_name = function () {return draft.stream;};- global.compose_state.topic = function () {+ compose_state.topic = function () {return draft.topic;};}@@ -182,7 +182,7 @@ run_test("snapshot_message", () => {});run_test("initialize", () => {- global.window.addEventListener = function (event_name, f) {+ window.addEventListener = function (event_name, f) {assert.equal(event_name, "beforeunload");let called = false;drafts.update_draft = function () {diff --git a/frontend_tests/node_tests/filter.js b/frontend_tests/node_tests/filter.jsindex 8b8f6dee3d2..ca835fa85fb 100644--- a/frontend_tests/node_tests/filter.js+++ b/frontend_tests/node_tests/filter.js@@ -448,7 +448,7 @@ run_test("public_operators", () => {assert_same_operators(filter.public_operators(), operators);assert(filter.can_bucket_by("stream"));- global.page_params.narrow_stream = "default";+ page_params.narrow_stream = "default";operators = [{operator: "stream", operand: "default"}];filter = new Filter(operators);assert_same_operators(filter.public_operators(), []);@@ -534,7 +534,7 @@ function make_sub(name, stream_id) {name,stream_id,};- global.stream_data.add_sub(sub);+ stream_data.add_sub(sub);}run_test("predicate_basics", () => {@@ -604,7 +604,7 @@ run_test("predicate_basics", () => {predicate = get_predicate([["in", "home"]]);assert(!predicate({stream_id: unknown_stream_id, stream: "unknown"}));assert(predicate({type: "private"}));- global.page_params.narrow_stream = "kiosk";+ page_params.narrow_stream = "kiosk";assert(predicate({stream: "kiosk"}));predicate = get_predicate([["near", 5]]);@@ -782,7 +782,7 @@ run_test("negated_predicates", () => {});run_test("mit_exceptions", () => {- global.page_params.realm_is_zephyr_mirror_realm = true;+ page_params.realm_is_zephyr_mirror_realm = true;let predicate = get_predicate([["stream", "Foo"],@@ -1294,7 +1294,7 @@ function make_private_sub(name, stream_id) {stream_id,invite_only: true,};- global.stream_data.add_sub(sub);+ stream_data.add_sub(sub);}function make_web_public_sub(name, stream_id) {@@ -1303,7 +1303,7 @@ function make_web_public_sub(name, stream_id) {stream_id,is_web_public: true,};- global.stream_data.add_sub(sub);+ stream_data.add_sub(sub);}run_test("navbar_helpers", () => {diff --git a/frontend_tests/node_tests/hashchange.js b/frontend_tests/node_tests/hashchange.jsindex a9cf225f788..1b39f11e5c8 100644--- a/frontend_tests/node_tests/hashchange.js+++ b/frontend_tests/node_tests/hashchange.js@@ -275,7 +275,7 @@ run_test("save_narrow", () => {assert.equal(window.location.hash, "#narrow/is/private");let url_pushed;- global.history.pushState = (state, title, url) => {+ history.pushState = (state, title, url) => {url_pushed = url;};diff --git a/frontend_tests/node_tests/hotkey.js b/frontend_tests/node_tests/hotkey.jsindex f2654137321..69d253a1ef0 100644--- a/frontend_tests/node_tests/hotkey.js+++ b/frontend_tests/node_tests/hotkey.js@@ -159,7 +159,7 @@ run_test("mappings", () => {assert.equal(map_down(219, true, true, false), undefined); // Shift + Ctrl + [// Cmd tests for MacOS- global.navigator.platform = "MacIntel";+ navigator.platform = "MacIntel";assert.equal(map_down(219, false, true, false).name, "escape"); // Ctrl + [assert.equal(map_down(219, false, false, true), undefined); // Cmd + [assert.equal(map_down(67, false, true, true).name, "copy_with_c"); // Ctrl + C@@ -171,7 +171,7 @@ run_test("mappings", () => {assert.equal(map_down(190, false, false, true).name, "narrow_to_compose_target"); // Cmd + .assert.equal(map_down(190, false, true, false), undefined); // Ctrl + .// Reset platform- global.navigator.platform = "";+ navigator.platform = "";});run_test("basic_chars", () => {@@ -314,10 +314,10 @@ run_test("basic_chars", () => {const message_view_only_keys = "@+>RjJkKsSuvi:GM";// Check that they do nothing without a selected message- global.current_msg_list.empty = return_true;+ current_msg_list.empty = return_true;assert_unmapped(message_view_only_keys);- global.current_msg_list.empty = return_false;+ current_msg_list.empty = return_false;// Check that they do nothing while in the settings overlayoverlays.settings_open = return_true;@@ -351,9 +351,9 @@ run_test("basic_chars", () => {overlays.is_active = return_false;assert_mapping("v", "lightbox.show_from_selected_message");- global.emoji_picker.reactions_popped = return_true;+ emoji_picker.reactions_popped = return_true;assert_mapping(":", "emoji_picker.navigate", true);- global.emoji_picker.reactions_popped = return_false;+ emoji_picker.reactions_popped = return_false;assert_mapping("G", "navigate.to_end");assert_mapping("M", "muting_ui.toggle_mute");@@ -363,9 +363,9 @@ run_test("basic_chars", () => {assert_mapping("n", "narrow.narrow_to_next_topic");assert_mapping("p", "narrow.narrow_to_next_pm_string");- global.current_msg_list.empty = return_true;+ current_msg_list.empty = return_true;assert_mapping("n", "narrow.narrow_to_next_topic");- global.current_msg_list.empty = return_false;+ current_msg_list.empty = return_false;});run_test("motion_keys", () => {@@ -412,7 +412,7 @@ run_test("motion_keys", () => {}list_util.inside_list = return_false;- global.current_msg_list.empty = return_true;+ current_msg_list.empty = return_true;overlays.settings_open = return_false;overlays.streams_open = return_false;overlays.lightbox_open = return_false;@@ -425,12 +425,12 @@ run_test("motion_keys", () => {assert_unmapped("spacebar");assert_unmapped("up_arrow");- global.list_util.inside_list = return_true;+ list_util.inside_list = return_true;assert_mapping("up_arrow", "list_util.go_up");assert_mapping("down_arrow", "list_util.go_down");list_util.inside_list = return_false;- global.current_msg_list.empty = return_false;+ current_msg_list.empty = return_false;assert_mapping("down_arrow", "navigate.down");assert_mapping("end", "navigate.to_end");assert_mapping("home", "navigate.to_home");diff --git a/frontend_tests/node_tests/markdown.js b/frontend_tests/node_tests/markdown.jsindex b93e0218a62..b5d5b5fa36d 100644--- a/frontend_tests/node_tests/markdown.js+++ b/frontend_tests/node_tests/markdown.js@@ -137,12 +137,11 @@ const amp_group = {members: [],};-global.user_groups.add(hamletcharacters);-global.user_groups.add(backend);-global.user_groups.add(edgecase_group);-global.user_groups.add(amp_group);+user_groups.add(hamletcharacters);+user_groups.add(backend);+user_groups.add(edgecase_group);+user_groups.add(amp_group);-const stream_data = global.stream_data;const denmark = {subscribed: false,color: "blue",diff --git a/frontend_tests/node_tests/message_edit.js b/frontend_tests/node_tests/message_edit.jsindex 237c6343eef..e4bea2a9e27 100644--- a/frontend_tests/node_tests/message_edit.js+++ b/frontend_tests/node_tests/message_edit.js@@ -102,19 +102,19 @@ run_test("get_editability", () => {assert.equal(message_edit.is_topic_editable(message), true);message.sent_by_me = true;- global.page_params.realm_allow_community_topic_editing = false;+ page_params.realm_allow_community_topic_editing = false;assert.equal(message_edit.is_topic_editable(message), true);message.sent_by_me = false;- global.page_params.realm_allow_community_topic_editing = false;+ page_params.realm_allow_community_topic_editing = false;assert.equal(message_edit.is_topic_editable(message), false);message.sent_by_me = false;- global.page_params.realm_allow_community_topic_editing = false;- global.page_params.is_admin = true;+ page_params.realm_allow_community_topic_editing = false;+ page_params.is_admin = true;assert.equal(message_edit.is_topic_editable(message), true);- global.page_params.realm_allow_message_editing = false;+ page_params.realm_allow_message_editing = false;assert.equal(message_edit.is_topic_editable(message), false);});@@ -133,7 +133,7 @@ run_test("get_deletability", () => {assert.equal(message_edit.get_deletability(message), true);// Non-admin can't delete message sent by others- global.page_params.is_admin = false;+ page_params.is_admin = false;assert.equal(message_edit.get_deletability(message), false);// Locally echoed messages are not deletable@@ -143,14 +143,14 @@ run_test("get_deletability", () => {message.locally_echoed = false;assert.equal(message_edit.get_deletability(message), false);- global.page_params.realm_allow_message_deleting = true;+ page_params.realm_allow_message_deleting = true;assert.equal(message_edit.get_deletability(message), true);const now = new Date();const current_timestamp = now / 1000;message.timestamp = current_timestamp - 5;- global.page_params.realm_message_content_delete_limit_seconds = 10;+ page_params.realm_message_content_delete_limit_seconds = 10;assert.equal(message_edit.get_deletability(message), true);message.timestamp = current_timestamp - 60;diff --git a/frontend_tests/node_tests/message_list.js b/frontend_tests/node_tests/message_list.jsindex 43c2edda518..6231f9e58c0 100644--- a/frontend_tests/node_tests/message_list.js+++ b/frontend_tests/node_tests/message_list.js@@ -74,7 +74,7 @@ run_test("basics", () => {assert.deepEqual(list.all_messages(), messages);- global.$.Event = function (ev) {+ $.Event = function (ev) {assert.equal(ev, "message_selected.zulip");};list.select_id(50);diff --git a/frontend_tests/node_tests/narrow.js b/frontend_tests/node_tests/narrow.jsindex 93a14ae0958..c1ca30c9cf8 100644--- a/frontend_tests/node_tests/narrow.js+++ b/frontend_tests/node_tests/narrow.js@@ -64,13 +64,13 @@ run_test("uris", () => {uri = hash_util.by_sender_uri(ray.email);assert.equal(uri, "#narrow/sender/22-ray");- let emails = global.hash_util.decode_operand("pm-with", "22,23-group");+ let emails = hash_util.decode_operand("pm-with", "22,23-group");assert.equal(emails, "[email protected],[email protected]");- emails = global.hash_util.decode_operand("pm-with", "5,22,23-group");+ emails = hash_util.decode_operand("pm-with", "5,22,23-group");assert.equal(emails, "[email protected],[email protected]");- emails = global.hash_util.decode_operand("pm-with", "5-group");+ emails = hash_util.decode_operand("pm-with", "5-group");assert.equal(emails, "[email protected]");});@@ -260,26 +260,26 @@ run_test("narrow_to_compose_target", () => {};// No-op when not composing.- global.compose_state.composing = () => false;+ compose_state.composing = () => false;narrow.to_compose_target();assert.equal(args.called, false);- global.compose_state.composing = () => true;+ compose_state.composing = () => true;// No-op when empty stream.- global.compose_state.get_message_type = () => "stream";- global.compose_state.stream_name = () => "";+ compose_state.get_message_type = () => "stream";+ compose_state.stream_name = () => "";args.called = false;narrow.to_compose_target();assert.equal(args.called, false);// --- Tests for stream messages ---- global.compose_state.get_message_type = () => "stream";+ compose_state.get_message_type = () => "stream";stream_data.add_sub({name: "ROME", stream_id: 99});- global.compose_state.stream_name = () => "ROME";- global.stream_topic_history.get_recent_topic_names = () => ["one", "two", "three"];+ compose_state.stream_name = () => "ROME";+ stream_topic_history.get_recent_topic_names = () => ["one", "two", "three"];// Test with existing topic- global.compose_state.topic = () => "one";+ compose_state.topic = () => "one";args.called = false;narrow.to_compose_target();assert.equal(args.called, true);@@ -290,41 +290,41 @@ run_test("narrow_to_compose_target", () => {]);// Test with new topic- global.compose_state.topic = () => "four";+ compose_state.topic = () => "four";args.called = false;narrow.to_compose_target();assert.equal(args.called, true);assert.deepEqual(args.operators, [{operator: "stream", operand: "ROME"}]);// Test with blank topic- global.compose_state.topic = () => "";+ compose_state.topic = () => "";args.called = false;narrow.to_compose_target();assert.equal(args.called, true);assert.deepEqual(args.operators, [{operator: "stream", operand: "ROME"}]);// Test with no topic- global.compose_state.topic = () => {};+ compose_state.topic = () => {};args.called = false;narrow.to_compose_target();assert.equal(args.called, true);assert.deepEqual(args.operators, [{operator: "stream", operand: "ROME"}]);// --- Tests for PMs ---- global.compose_state.get_message_type = () => "private";+ compose_state.get_message_type = () => "private";people.add_active_user(ray);people.add_active_user(alice);people.add_active_user(me);// Test with valid person- global.compose_state.private_message_recipient = () => "[email protected]";+ compose_state.private_message_recipient = () => "[email protected]";args.called = false;narrow.to_compose_target();assert.equal(args.called, true);assert.deepEqual(args.operators, [{operator: "pm-with", operand: "[email protected]"}]);// Test with valid persons- global.compose_state.private_message_recipient = () => "[email protected],[email protected]";+ compose_state.private_message_recipient = () => "[email protected],[email protected]";args.called = false;narrow.to_compose_target();assert.equal(args.called, true);@@ -333,22 +333,21 @@ run_test("narrow_to_compose_target", () => {]);// Test with some invalid persons- global.compose_state.private_message_recipient = () =>- "[email protected],random,[email protected]";+ compose_state.private_message_recipient = () => "[email protected],random,[email protected]";args.called = false;narrow.to_compose_target();assert.equal(args.called, true);assert.deepEqual(args.operators, [{operator: "is", operand: "private"}]);// Test with all invalid persons- global.compose_state.private_message_recipient = () => "alice,random,ray";+ compose_state.private_message_recipient = () => "alice,random,ray";args.called = false;narrow.to_compose_target();assert.equal(args.called, true);assert.deepEqual(args.operators, [{operator: "is", operand: "private"}]);// Test with no persons- global.compose_state.private_message_recipient = () => "";+ compose_state.private_message_recipient = () => "";args.called = false;narrow.to_compose_target();assert.equal(args.called, true);diff --git a/frontend_tests/node_tests/people.js b/frontend_tests/node_tests/people.jsindex b04ef093c88..6bda83c0dd6 100644--- a/frontend_tests/node_tests/people.js+++ b/frontend_tests/node_tests/people.js@@ -396,18 +396,18 @@ run_test("user_timezone", () => {format: "H:mm",};- global.page_params.twenty_four_hour_time = true;+ page_params.twenty_four_hour_time = true;assert.deepEqual(people.get_user_time_preferences(me.user_id), expected_pref);expected_pref.format = "h:mm A";- global.page_params.twenty_four_hour_time = false;+ page_params.twenty_four_hour_time = false;assert.deepEqual(people.get_user_time_preferences(me.user_id), expected_pref);- global.page_params.twenty_four_hour_time = true;+ page_params.twenty_four_hour_time = true;assert.equal(people.get_user_time(me.user_id), "0:09");expected_pref.format = "h:mm A";- global.page_params.twenty_four_hour_time = false;+ page_params.twenty_four_hour_time = false;assert.equal(people.get_user_time(me.user_id), "12:09 AM");});@@ -1004,9 +1004,9 @@ run_test("initialize", () => {const fetched_retiree = people.get_by_user_id(15);assert.equal(fetched_retiree.full_name, "Retiree");- assert.equal(global.page_params.realm_users, undefined);- assert.equal(global.page_params.cross_realm_bots, undefined);- assert.equal(global.page_params.realm_non_active_users, undefined);+ assert.equal(page_params.realm_users, undefined);+ assert.equal(page_params.cross_realm_bots, undefined);+ assert.equal(page_params.realm_non_active_users, undefined);});run_test("filter_for_user_settings_search", () => {diff --git a/frontend_tests/node_tests/pm_list.js b/frontend_tests/node_tests/pm_list.jsindex 46caf52601e..7cf7da0ee21 100644--- a/frontend_tests/node_tests/pm_list.js+++ b/frontend_tests/node_tests/pm_list.js@@ -71,7 +71,7 @@ run_test("build_private_messages_list", () => {const timestamp = 0;pm_conversations.recent.insert([101, 102], timestamp);- global.unread.num_unread_for_person = function () {+ unread.num_unread_for_person = function () {return 1;};@@ -100,7 +100,7 @@ run_test("build_private_messages_list", () => {assert.deepEqual(pm_data, expected_data);- global.unread.num_unread_for_person = function () {+ unread.num_unread_for_person = function () {return 0;};pm_list._build_private_messages_list();@@ -117,7 +117,7 @@ run_test("build_private_messages_list_bot", () => {const timestamp = 0;pm_conversations.recent.insert([314], timestamp);- global.unread.num_unread_for_person = function () {+ unread.num_unread_for_person = function () {return 1;};diff --git a/frontend_tests/node_tests/reactions.js b/frontend_tests/node_tests/reactions.jsindex d2383be758b..08204ce4241 100644--- a/frontend_tests/node_tests/reactions.js+++ b/frontend_tests/node_tests/reactions.js@@ -265,7 +265,7 @@ run_test("sending", (override) => {override("reactions.remove_reaction", () => {});with_stub((stub) => {- global.channel.del = stub.f;+ channel.del = stub.f;reactions.toggle_emoji_reaction(message_id, emoji_name);const args = stub.get_args("args").args;assert.equal(args.url, "/json/messages/1001/reactions");@@ -280,14 +280,14 @@ run_test("sending", (override) => {// similarly, we only exercise the failure codepath// Since this path calls blueslip.warn, we need to handle it.blueslip.expect("warn", "XHR Error Message.");- global.channel.xhr_error_message = function () {+ channel.xhr_error_message = function () {return "XHR Error Message.";};args.error();});emoji_name = "alien"; // not set yetwith_stub((stub) => {- global.channel.post = stub.f;+ channel.post = stub.f;reactions.toggle_emoji_reaction(message_id, emoji_name);const args = stub.get_args("args").args;assert.equal(args.url, "/json/messages/1001/reactions");@@ -304,7 +304,7 @@ run_test("sending", (override) => {// deactivated realm emoji only by clicking on a reaction, hence, only// `process_reaction_click()` codepath supports deleting/adding a deactivated// realm emoji.- global.channel.del = stub.f;+ channel.del = stub.f;reactions.process_reaction_click(message_id, "realm_emoji,992");const args = stub.get_args("args").args;assert.equal(args.url, "/json/messages/1001/reactions");@@ -317,7 +317,7 @@ run_test("sending", (override) => {emoji_name = "zulip"; // Test adding zulip emoji.with_stub((stub) => {- global.channel.post = stub.f;+ channel.post = stub.f;reactions.toggle_emoji_reaction(message_id, emoji_name);const args = stub.get_args("args").args;assert.equal(args.url, "/json/messages/1001/reactions");@@ -679,7 +679,7 @@ run_test("with_view_stubs", () => {});run_test("error_handling", () => {- global.message_store.get = function () {+ message_store.get = function () {return;};@@ -768,7 +768,7 @@ run_test("process_reaction_click", () => {reaction_type: "unicode_emoji",emoji_code: "1f3b1",};- global.message_store.get = function (message_id) {+ message_store.get = function (message_id) {assert.equal(message_id, 1001);return message;};@@ -779,7 +779,7 @@ run_test("process_reaction_click", () => {emoji_code: "1f642",};with_stub((stub) => {- global.channel.del = stub.f;+ channel.del = stub.f;reactions.process_reaction_click(message_id, "unicode_emoji,1f642");const args = stub.get_args("args").args;assert.equal(args.url, "/json/messages/1001/reactions");@@ -834,12 +834,12 @@ run_test("duplicates", () => {});run_test("process_reaction_click errors", () => {- global.message_store.get = () => undefined;+ message_store.get = () => undefined;blueslip.expect("error", "reactions: Bad message id: 55");blueslip.expect("error", "message_id for reaction click is unknown: 55");reactions.process_reaction_click(55, "whatever");- global.message_store.get = () => message;+ message_store.get = () => message;blueslip.expect("error","Data integrity problem for reaction bad-local-id (message some-msg-id)",diff --git a/frontend_tests/node_tests/rendered_markdown.js b/frontend_tests/node_tests/rendered_markdown.jsindex 6ff50cf72e6..e5acec1efab 100644--- a/frontend_tests/node_tests/rendered_markdown.js+++ b/frontend_tests/node_tests/rendered_markdown.js@@ -196,7 +196,7 @@ run_test("timestamp-twenty-four-hour-time", () => {$content.set_find_results("time", $array([$timestamp]));// We will temporarily change the 24h setting for this test.- const old_page_params = global.page_params;+ const old_page_params = page_params;set_global("page_params", {...old_page_params, twenty_four_hour_time: true});rm.update_elements($content);diff --git a/frontend_tests/node_tests/search_suggestion.js b/frontend_tests/node_tests/search_suggestion.jsindex d173a090fd9..91e7206b6a3 100644--- a/frontend_tests/node_tests/search_suggestion.js+++ b/frontend_tests/node_tests/search_suggestion.js@@ -87,11 +87,11 @@ function get_suggestions(base_query, query) {run_test("basic_get_suggestions", () => {const query = "fred";- global.stream_data.subscribed_streams = function () {+ stream_data.subscribed_streams = function () {return [];};- global.narrow_state.stream = function () {+ narrow_state.stream = function () {return "office";};@@ -105,11 +105,11 @@ run_test("subset_suggestions", () => {const query = "shakespeare";const base_query = "stream:Denmark topic:Hamlet";- global.stream_data.subscribed_streams = function () {+ stream_data.subscribed_streams = function () {return [];};- global.narrow_state.stream = function () {+ narrow_state.stream = function () {return;};@@ -121,11 +121,11 @@ run_test("subset_suggestions", () => {});run_test("private_suggestions", () => {- global.stream_data.subscribed_streams = function () {+ stream_data.subscribed_streams = function () {return [];};- global.narrow_state.stream = function () {+ narrow_state.stream = function () {return;};@@ -242,11 +242,11 @@ run_test("private_suggestions", () => {});run_test("group_suggestions", () => {- global.stream_data.subscribed_streams = function () {+ stream_data.subscribed_streams = function () {return [];};- global.narrow_state.stream = function () {+ narrow_state.stream = function () {return;};@@ -387,11 +387,11 @@ init();run_test("empty_query_suggestions", () => {const query = "";- global.stream_data.subscribed_streams = function () {+ stream_data.subscribed_streams = function () {return ["devel", "office"];};- global.narrow_state.stream = function () {+ narrow_state.stream = function () {return;};@@ -433,10 +433,10 @@ run_test("has_suggestions", () => {// Checks that category wise suggestions are displayed instead of a single// default suggestion when suggesting `has` operator.let query = "h";- global.stream_data.subscribed_streams = function () {+ stream_data.subscribed_streams = function () {return ["devel", "office"];};- global.narrow_state.stream = function () {+ narrow_state.stream = function () {return;};@@ -491,10 +491,10 @@ run_test("has_suggestions", () => {run_test("check_is_suggestions", () => {let query = "i";- global.stream_data.subscribed_streams = function () {+ stream_data.subscribed_streams = function () {return ["devel", "office"];};- global.narrow_state.stream = function () {+ narrow_state.stream = function () {return;};@@ -598,11 +598,11 @@ run_test("check_is_suggestions", () => {});run_test("sent_by_me_suggestions", () => {- global.stream_data.subscribed_streams = function () {+ stream_data.subscribed_streams = function () {return [];};- global.narrow_state.stream = function () {+ narrow_state.stream = function () {return;};@@ -681,18 +681,18 @@ run_test("topic_suggestions", () => {let suggestions;let expected;- global.stream_data.subscribed_streams = function () {+ stream_data.subscribed_streams = function () {return ["office"];};- global.narrow_state.stream = function () {+ narrow_state.stream = function () {return "office";};const devel_id = 44;const office_id = 77;- global.stream_data.get_stream_id = function (stream_name) {+ stream_data.get_stream_id = function (stream_name) {switch (stream_name) {case "office":return office_id;@@ -774,11 +774,11 @@ run_test("topic_suggestions", () => {run_test("whitespace_glitch", () => {const query = "stream:office "; // note trailing space- global.stream_data.subscribed_streams = function () {+ stream_data.subscribed_streams = function () {return ["office"];};- global.narrow_state.stream = function () {+ narrow_state.stream = function () {return;};@@ -792,11 +792,11 @@ run_test("whitespace_glitch", () => {});run_test("stream_completion", () => {- global.stream_data.subscribed_streams = function () {+ stream_data.subscribed_streams = function () {return ["office", "dev help"];};- global.narrow_state.stream = function () {+ narrow_state.stream = function () {return;};@@ -819,8 +819,8 @@ run_test("stream_completion", () => {});function people_suggestion_setup() {- global.stream_data.subscribed_streams = () => [];- global.narrow_state.stream = noop;+ stream_data.subscribed_streams = () => [];+ narrow_state.stream = noop;const ted = {email: "[email protected]",@@ -966,11 +966,11 @@ run_test("operator_suggestions", () => {});run_test("queries_with_spaces", () => {- global.stream_data.subscribed_streams = function () {+ stream_data.subscribed_streams = function () {return ["office", "dev help"];};- global.narrow_state.stream = function () {+ narrow_state.stream = function () {return;};diff --git a/frontend_tests/node_tests/search_suggestion_legacy.js b/frontend_tests/node_tests/search_suggestion_legacy.jsindex 9a391c7b7d4..b2c9f9686d7 100644--- a/frontend_tests/node_tests/search_suggestion_legacy.js+++ b/frontend_tests/node_tests/search_suggestion_legacy.js@@ -85,11 +85,11 @@ function get_suggestions(base_query, query) {run_test("basic_get_suggestions", () => {const query = "fred";- global.stream_data.subscribed_streams = function () {+ stream_data.subscribed_streams = function () {return [];};- global.narrow_state.stream = function () {+ narrow_state.stream = function () {return "office";};@@ -102,11 +102,11 @@ run_test("basic_get_suggestions", () => {run_test("subset_suggestions", () => {const query = "stream:Denmark topic:Hamlet shakespeare";- global.stream_data.subscribed_streams = function () {+ stream_data.subscribed_streams = function () {return [];};- global.narrow_state.stream = function () {+ narrow_state.stream = function () {return;};@@ -122,11 +122,11 @@ run_test("subset_suggestions", () => {});run_test("private_suggestions", () => {- global.stream_data.subscribed_streams = function () {+ stream_data.subscribed_streams = function () {return [];};- global.narrow_state.stream = function () {+ narrow_state.stream = function () {return;};@@ -239,11 +239,11 @@ run_test("private_suggestions", () => {});run_test("group_suggestions", () => {- global.stream_data.subscribed_streams = function () {+ stream_data.subscribed_streams = function () {return [];};- global.narrow_state.stream = function () {+ narrow_state.stream = function () {return;};@@ -391,11 +391,11 @@ init();run_test("empty_query_suggestions", () => {const query = "";- global.stream_data.subscribed_streams = function () {+ stream_data.subscribed_streams = function () {return ["devel", "office"];};- global.narrow_state.stream = function () {+ narrow_state.stream = function () {return;};@@ -437,10 +437,10 @@ run_test("has_suggestions", () => {// Checks that category wise suggestions are displayed instead of a single// default suggestion when suggesting `has` operator.let query = "h";- global.stream_data.subscribed_streams = function () {+ stream_data.subscribed_streams = function () {return ["devel", "office"];};- global.narrow_state.stream = function () {+ narrow_state.stream = function () {return;};@@ -497,10 +497,10 @@ run_test("has_suggestions", () => {});run_test("check_is_suggestions", () => {- global.stream_data.subscribed_streams = function () {+ stream_data.subscribed_streams = function () {return ["devel", "office"];};- global.narrow_state.stream = function () {+ narrow_state.stream = function () {return;};@@ -570,11 +570,11 @@ run_test("check_is_suggestions", () => {});run_test("sent_by_me_suggestions", () => {- global.stream_data.subscribed_streams = function () {+ stream_data.subscribed_streams = function () {return [];};- global.narrow_state.stream = function () {+ narrow_state.stream = function () {return;};@@ -648,18 +648,18 @@ run_test("topic_suggestions", () => {let suggestions;let expected;- global.stream_data.subscribed_streams = function () {+ stream_data.subscribed_streams = function () {return ["office"];};- global.narrow_state.stream = function () {+ narrow_state.stream = function () {return "office";};const devel_id = 44;const office_id = 77;- global.stream_data.get_stream_id = function (stream_name) {+ stream_data.get_stream_id = function (stream_name) {switch (stream_name) {case "office":return office_id;@@ -747,11 +747,11 @@ run_test("topic_suggestions", () => {run_test("whitespace_glitch", () => {const query = "stream:office "; // note trailing space- global.stream_data.subscribed_streams = function () {+ stream_data.subscribed_streams = function () {return ["office"];};- global.narrow_state.stream = function () {+ narrow_state.stream = function () {return;};@@ -765,11 +765,11 @@ run_test("whitespace_glitch", () => {});run_test("stream_completion", () => {- global.stream_data.subscribed_streams = function () {+ stream_data.subscribed_streams = function () {return ["office", "dev help"];};- global.narrow_state.stream = function () {+ narrow_state.stream = function () {return;};@@ -794,11 +794,11 @@ run_test("stream_completion", () => {run_test("people_suggestions", () => {let query = "te";- global.stream_data.subscribed_streams = function () {+ stream_data.subscribed_streams = function () {return [];};- global.narrow_state.stream = function () {+ narrow_state.stream = function () {return;};@@ -912,11 +912,11 @@ run_test("operator_suggestions", () => {});run_test("queries_with_spaces", () => {- global.stream_data.subscribed_streams = function () {+ stream_data.subscribed_streams = function () {return ["office", "dev help"];};- global.narrow_state.stream = function () {+ narrow_state.stream = function () {return;};diff --git a/frontend_tests/node_tests/server_events.js b/frontend_tests/node_tests/server_events.jsindex 312b1a48007..a6e80dfdf21 100644--- a/frontend_tests/node_tests/server_events.js+++ b/frontend_tests/node_tests/server_events.js@@ -94,7 +94,7 @@ run_test("event_dispatch_error", () => {setup();const data = {events: [{type: "stream", op: "update", id: 1, other: "thing"}]};- global.channel.get = function (options) {+ channel.get = function (options) {options.success(data);};@@ -114,7 +114,7 @@ run_test("event_new_message_error", () => {setup();const data = {events: [{type: "message", id: 1, other: "thing", message: {}}]};- global.channel.get = function (options) {+ channel.get = function (options) {options.success(data);};@@ -130,7 +130,7 @@ run_test("event_new_message_error", () => {run_test("event_edit_message_error", () => {setup();const data = {events: [{type: "update_message", id: 1, other: "thing"}]};- global.channel.get = function (options) {+ channel.get = function (options) {options.success(data);};blueslip.expect("error", "Failed to update messages\nupdate error");diff --git a/frontend_tests/node_tests/settings_org.js b/frontend_tests/node_tests/settings_org.jsindex f40cec8e4b5..0c545800dee 100644--- a/frontend_tests/node_tests/settings_org.js+++ b/frontend_tests/node_tests/settings_org.js@@ -653,9 +653,7 @@ function test_parse_time_limit() {const elem = $("#id_realm_message_content_edit_limit_minutes");const test_function = (value, expected_value = value) => {elem.val(value);- global.page_params.realm_message_content_edit_limit_seconds = settings_org.parse_time_limit(- elem,- );+ page_params.realm_message_content_edit_limit_seconds = settings_org.parse_time_limit(elem);assert.equal(settings_org.get_realm_time_limits_in_minutes("realm_message_content_edit_limit_seconds",diff --git a/frontend_tests/node_tests/stream_data.js b/frontend_tests/node_tests/stream_data.jsindex 07a06cc0a7f..652d3701dfe 100644--- a/frontend_tests/node_tests/stream_data.js+++ b/frontend_tests/node_tests/stream_data.js@@ -100,7 +100,7 @@ run_test("basics", () => {assert(!stream_data.get_invite_only("unknown"));assert.equal(stream_data.get_color("social"), "red");- assert.equal(stream_data.get_color("unknown"), global.stream_color.default_color);+ assert.equal(stream_data.get_color("unknown"), stream_color.default_color);assert.equal(stream_data.get_name("denMARK"), "Denmark");assert.equal(stream_data.get_name("unknown Stream"), "unknown Stream");@@ -427,7 +427,7 @@ run_test("admin_options", () => {}// non-admins can't do anything- global.page_params.is_admin = false;+ page_params.is_admin = false;let sub = make_sub();stream_data.update_calculated_fields(sub);assert(!sub.is_realm_admin);@@ -437,7 +437,7 @@ run_test("admin_options", () => {assert.equal(sub.color, "blue");// the remaining cases are for admin users- global.page_params.is_admin = true;+ page_params.is_admin = true;// admins can make public streams become privatesub = make_sub();@@ -530,7 +530,7 @@ run_test("stream_settings", () => {// For guest user only retrieve subscribed streamssub_rows = stream_data.get_updated_unsorted_subs();assert.equal(sub_rows.length, 3);- global.page_params.is_guest = true;+ page_params.is_guest = true;sub_rows = stream_data.get_updated_unsorted_subs();assert.equal(sub_rows[0].name, "c");assert.equal(sub_rows[1].name, "a");diff --git a/frontend_tests/node_tests/stream_list.js b/frontend_tests/node_tests/stream_list.jsindex c842359a332..d30c7eba5a6 100644--- a/frontend_tests/node_tests/stream_list.js+++ b/frontend_tests/node_tests/stream_list.js@@ -57,7 +57,7 @@ run_test("create_sidebar_row", () => {subscribed: true,pin_to_top: true,};- global.stream_data.add_sub(devel);+ stream_data.add_sub(devel);const social = {name: "social",@@ -65,9 +65,9 @@ run_test("create_sidebar_row", () => {color: "green",subscribed: true,};- global.stream_data.add_sub(social);+ stream_data.add_sub(social);- global.unread.num_unread_for_stream = function () {+ unread.num_unread_for_stream = function () {return 42;};@@ -190,7 +190,7 @@ run_test("pinned_streams_never_inactive", () => {subscribed: true,pin_to_top: true,};- global.stream_data.add_sub(devel);+ stream_data.add_sub(devel);const social = {name: "social",@@ -198,7 +198,7 @@ run_test("pinned_streams_never_inactive", () => {color: "green",subscribed: true,};- global.stream_data.add_sub(social);+ stream_data.add_sub(social);// we use social and devel created in create_social_sidebar_row() and create_devel_sidebar_row()@@ -235,7 +235,7 @@ run_test("pinned_streams_never_inactive", () => {set_global("$", make_zjquery());function add_row(sub) {- global.stream_data.add_sub(sub);+ stream_data.add_sub(sub);const row = {update_whether_active() {},get_li() {@@ -468,7 +468,7 @@ run_test("sort_streams", () => {initialize_stream_data();- global.stream_data.is_active = function (sub) {+ stream_data.is_active = function (sub) {return sub.name !== "cars";};@@ -493,7 +493,7 @@ run_test("sort_streams", () => {assert.deepEqual(appended_elems, expected_elems);- const streams = global.stream_sort.get_streams();+ const streams = stream_sort.get_streams();assert.deepEqual(streams, [// three groups: pinned, normal, dormant@@ -550,7 +550,7 @@ run_test("separators_only_pinned_and_dormant", () => {};add_row(DenmarkSub);- global.stream_data.is_active = function (sub) {+ stream_data.is_active = function (sub) {return sub.name !== "Denmark";};diff --git a/frontend_tests/node_tests/topic_generator.js b/frontend_tests/node_tests/topic_generator.jsindex 656363460d2..5398cd2144d 100644--- a/frontend_tests/node_tests/topic_generator.js+++ b/frontend_tests/node_tests/topic_generator.js@@ -200,7 +200,7 @@ run_test("streams", () => {assert.equal(actual, expected);}- global.stream_sort.get_streams = function () {+ stream_sort.get_streams = function () {return ["announce", "muted", "devel", "test here"];};@@ -251,7 +251,7 @@ run_test("topics", () => {// Now test the deeper function that is wired up to// real functions stream_data/stream_sort/unread.- global.stream_sort.get_streams = function () {+ stream_sort.get_streams = function () {return ["announce", "muted", "devel", "test here"];};@@ -274,19 +274,19 @@ run_test("topics", () => {return [];};- global.stream_data.get_stream_id = function (stream_name) {+ stream_data.get_stream_id = function (stream_name) {return stream_id_dct[stream_name];};- global.stream_data.is_stream_muted_by_name = function (stream_name) {+ stream_data.is_stream_muted_by_name = function (stream_name) {return stream_name === "muted";};- global.unread.topic_has_any_unread = function (stream_id) {+ unread.topic_has_any_unread = function (stream_id) {return [devel_stream_id, muted_stream_id].includes(stream_id);};- global.muting.is_topic_muted = function (stream_name, topic) {+ muting.is_topic_muted = function (stream_name, topic) {return topic === "muted";};diff --git a/frontend_tests/node_tests/typeahead_helper.js b/frontend_tests/node_tests/typeahead_helper.jsindex 99f01807667..63efc22ad15 100644--- a/frontend_tests/node_tests/typeahead_helper.js+++ b/frontend_tests/node_tests/typeahead_helper.js@@ -56,7 +56,7 @@ run_test("sort_streams", () => {];test_streams.forEach(stream_data.update_calculated_fields);- global.stream_data.is_active = function (sub) {+ stream_data.is_active = function (sub) {return sub.name !== "dead";};@@ -261,19 +261,19 @@ run_test("sort_recipients", () => {pm_conversations.set_partner(7);// For splitting based on recency- global.recent_senders.process_message_for_senders({+ recent_senders.process_message_for_senders({sender_id: 7,stream_id: 1,topic: "Dev Topic",id: (next_id += 1),});- global.recent_senders.process_message_for_senders({+ recent_senders.process_message_for_senders({sender_id: 5,stream_id: 1,topic: "Dev Topic",id: (next_id += 1),});- global.recent_senders.process_message_for_senders({+ recent_senders.process_message_for_senders({sender_id: 6,stream_id: 1,topic: "Dev Topic",@@ -291,13 +291,13 @@ run_test("sort_recipients", () => {]);- global.recent_senders.process_message_for_senders({+ recent_senders.process_message_for_senders({sender_id: 5,stream_id: 2,topic: "Linux Topic",id: (next_id += 1),});- global.recent_senders.process_message_for_senders({+ recent_senders.process_message_for_senders({sender_id: 7,stream_id: 2,topic: "Linux Topic",diff --git a/frontend_tests/node_tests/ui.js b/frontend_tests/node_tests/ui.jsindex 27962ed349a..af13d17390e 100644--- a/frontend_tests/node_tests/ui.js+++ b/frontend_tests/node_tests/ui.js@@ -19,12 +19,12 @@ run_test("get_hotkey_deprecation_notice", () => {});run_test("get_hotkey_deprecation_notice_mac", () => {- global.navigator.userAgent =+ navigator.userAgent ="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.167 Safari/537.36";const expected ='translated: We\'ve replaced the "*" hotkey with "Cmd + s" to make this common shortcut easier to trigger.';const actual = ui.get_hotkey_deprecation_notice("*", "Cmd + s");assert.equal(actual, expected);// Reset userAgent- global.navigator.userAgent = "";+ navigator.userAgent = "";});diff --git a/frontend_tests/node_tests/upload.js b/frontend_tests/node_tests/upload.jsindex d976b02ffb9..07a9170a367 100644--- a/frontend_tests/node_tests/upload.js+++ b/frontend_tests/node_tests/upload.js@@ -23,8 +23,8 @@ set_global("bridge", false);// Setting these up so that we can test that links to uploads within messages are// automatically converted to server relative links.-global.document.location.protocol = "https:";-global.document.location.host = "foo.com";+document.location.protocol = "https:";+document.location.host = "foo.com";zrequire("compose_ui");zrequire("compose_state");diff --git a/frontend_tests/node_tests/user_events.js b/frontend_tests/node_tests/user_events.jsindex 66c56f36b54..731d44982cd 100644--- a/frontend_tests/node_tests/user_events.js+++ b/frontend_tests/node_tests/user_events.js@@ -113,7 +113,7 @@ run_test("updates", () => {let user_id;let full_name;- global.message_live_update.update_user_full_name = function (user_id_arg, full_name_arg) {+ message_live_update.update_user_full_name = function (user_id_arg, full_name_arg) {user_id = user_id_arg;full_name = full_name_arg;};@@ -129,7 +129,7 @@ run_test("updates", () => {user_id: me.user_id,role: settings_config.user_role_values.member.code,});- assert(!global.page_params.is_admin);+ assert(!page_params.is_admin);user_events.update_person({user_id: me.user_id, full_name: "Me V2"});assert.equal(people.my_full_name(), "Me V2");@@ -147,7 +147,7 @@ run_test("updates", () => {assert.equal(person.full_name, "Me V2");let avatar_url;- global.message_live_update.update_avatar = function (user_id_arg, avatar_url_arg) {+ message_live_update.update_avatar = function (user_id_arg, avatar_url_arg) {user_id = user_id_arg;avatar_url = avatar_url_arg;};diff --git a/frontend_tests/node_tests/util.js b/frontend_tests/node_tests/util.jsindex c7749cadf46..1c23ae1def8 100644--- a/frontend_tests/node_tests/util.js+++ b/frontend_tests/node_tests/util.js@@ -140,10 +140,10 @@ run_test("get_edit_event_prev_topic", () => {});run_test("is_mobile", () => {- global.window.navigator = {userAgent: "Android"};+ window.navigator = {userAgent: "Android"};assert(util.is_mobile());- global.window.navigator = {userAgent: "Not mobile"};+ window.navigator = {userAgent: "Not mobile"};assert(!util.is_mobile());});