diff --git a/.eslintrc.json b/.eslintrc.json index 7192a3255f..ee141bf507 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -108,7 +108,6 @@ { "files": ["frontend_tests/node_tests/**"], "globals": { - "$": false, "blueslip": false, "current_msg_list": false, "home_msg_list": false, diff --git a/frontend_tests/node_tests/activity.js b/frontend_tests/node_tests/activity.js index 722e59b9c7..69e7f2332b 100644 --- a/frontend_tests/node_tests/activity.js +++ b/frontend_tests/node_tests/activity.js @@ -4,9 +4,8 @@ const {strict: assert} = require("assert"); const {set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -const {make_zjquery} = require("../zjsunit/zjquery"); +const $ = require("../zjsunit/zjquery"); -set_global("$", make_zjquery()); const window_stub = $.create("window-stub"); set_global("to_$", () => window_stub); $(window).idle = () => {}; diff --git a/frontend_tests/node_tests/alert_words_ui.js b/frontend_tests/node_tests/alert_words_ui.js index 5cd219ce1f..2246f48bac 100644 --- a/frontend_tests/node_tests/alert_words_ui.js +++ b/frontend_tests/node_tests/alert_words_ui.js @@ -5,9 +5,7 @@ const {strict: assert} = require("assert"); const {stub_templates} = require("../zjsunit/handlebars"); const {set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -const {make_zjquery} = require("../zjsunit/zjquery"); - -set_global("$", make_zjquery()); +const $ = require("../zjsunit/zjquery"); const channel = set_global("channel", {}); diff --git a/frontend_tests/node_tests/billing.js b/frontend_tests/node_tests/billing.js index 8f910d60a0..c1b245e2e6 100644 --- a/frontend_tests/node_tests/billing.js +++ b/frontend_tests/node_tests/billing.js @@ -7,7 +7,7 @@ const {JSDOM} = require("jsdom"); const {set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -const {make_zjquery} = require("../zjsunit/zjquery"); +const $ = require("../zjsunit/zjquery"); const noop = () => {}; const template = fs.readFileSync("templates/corporate/billing.html", "utf-8"); @@ -21,8 +21,6 @@ const StripeCheckout = set_global("StripeCheckout", { configure: noop, }); -set_global("$", make_zjquery()); - run_test("initialize", () => { let token_func; diff --git a/frontend_tests/node_tests/billing_helpers.js b/frontend_tests/node_tests/billing_helpers.js index 1c50e5f02b..5b7c01496c 100644 --- a/frontend_tests/node_tests/billing_helpers.js +++ b/frontend_tests/node_tests/billing_helpers.js @@ -8,13 +8,12 @@ const {JSDOM} = require("jsdom"); const {set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -const {make_zjquery} = require("../zjsunit/zjquery"); +const $ = require("../zjsunit/zjquery"); const template = fs.readFileSync("templates/corporate/upgrade.html", "utf-8"); const dom = new JSDOM(template, {pretendToBeVisual: true}); const jquery = jQueryFactory(dom.window); -set_global("$", make_zjquery()); set_global("page_params", {}); const loading = set_global("loading", {}); const history = set_global("history", {}); diff --git a/frontend_tests/node_tests/buddy_data.js b/frontend_tests/node_tests/buddy_data.js index 1ab100667b..7678dd6afe 100644 --- a/frontend_tests/node_tests/buddy_data.js +++ b/frontend_tests/node_tests/buddy_data.js @@ -6,12 +6,10 @@ const _ = require("lodash"); const {set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -const {make_zjquery} = require("../zjsunit/zjquery"); const _page_params = {}; set_global("page_params", _page_params); -set_global("$", make_zjquery()); const people = zrequire("people"); const presence = zrequire("presence"); const user_status = zrequire("user_status"); diff --git a/frontend_tests/node_tests/buddy_list.js b/frontend_tests/node_tests/buddy_list.js index ab3f869ea8..c4a49dfeed 100644 --- a/frontend_tests/node_tests/buddy_list.js +++ b/frontend_tests/node_tests/buddy_list.js @@ -6,9 +6,8 @@ const _ = require("lodash"); const {set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -const {make_zjquery} = require("../zjsunit/zjquery"); +const $ = require("../zjsunit/zjquery"); -set_global("$", make_zjquery()); const people = zrequire("people"); zrequire("buddy_data"); const buddy_list = zrequire("buddy_list"); diff --git a/frontend_tests/node_tests/channel.js b/frontend_tests/node_tests/channel.js index 187a3d9436..30d3bd8603 100644 --- a/frontend_tests/node_tests/channel.js +++ b/frontend_tests/node_tests/channel.js @@ -6,8 +6,7 @@ const _ = require("lodash"); const {set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); - -set_global("$", {}); +const $ = require("../zjsunit/zjquery"); const reload = set_global("reload", {}); zrequire("reload_state"); diff --git a/frontend_tests/node_tests/common.js b/frontend_tests/node_tests/common.js index d12bab431b..96d8089f3f 100644 --- a/frontend_tests/node_tests/common.js +++ b/frontend_tests/node_tests/common.js @@ -4,11 +4,10 @@ const {strict: assert} = require("assert"); const {set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -const {make_zjquery} = require("../zjsunit/zjquery"); +const $ = require("../zjsunit/zjquery"); const noop = () => {}; -set_global("$", make_zjquery()); set_global("document", {}); const common = zrequire("common"); diff --git a/frontend_tests/node_tests/compose.js b/frontend_tests/node_tests/compose.js index 93097bb44c..df6d86a5fb 100644 --- a/frontend_tests/node_tests/compose.js +++ b/frontend_tests/node_tests/compose.js @@ -9,7 +9,7 @@ const rewiremock = require("rewiremock/node"); const {stub_templates} = require("../zjsunit/handlebars"); const {set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -const {make_zjquery} = require("../zjsunit/zjquery"); +const $ = require("../zjsunit/zjquery"); const events = require("./lib/events"); @@ -17,7 +17,6 @@ set_global("bridge", false); const noop = function () {}; -set_global("$", make_zjquery()); set_global("DOMParser", new JSDOM().window.DOMParser); set_global("compose_actions", { update_placeholder_text: noop, diff --git a/frontend_tests/node_tests/compose_actions.js b/frontend_tests/node_tests/compose_actions.js index 75053bb696..9fec0b5702 100644 --- a/frontend_tests/node_tests/compose_actions.js +++ b/frontend_tests/node_tests/compose_actions.js @@ -4,7 +4,7 @@ const {strict: assert} = require("assert"); const {set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -const {make_zjquery} = require("../zjsunit/zjquery"); +const $ = require("../zjsunit/zjquery"); const noop = function () {}; const return_false = function () { @@ -20,8 +20,6 @@ set_global("document", { set_global("page_params", {}); -set_global("$", make_zjquery()); - const compose_pm_pill = set_global("compose_pm_pill", {}); const hash_util = set_global("hash_util", {}); diff --git a/frontend_tests/node_tests/compose_pm_pill.js b/frontend_tests/node_tests/compose_pm_pill.js index 713289ca83..ed2c4f79cc 100644 --- a/frontend_tests/node_tests/compose_pm_pill.js +++ b/frontend_tests/node_tests/compose_pm_pill.js @@ -2,11 +2,9 @@ const {strict: assert} = require("assert"); -const {set_global, zrequire} = require("../zjsunit/namespace"); +const {zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -const {make_zjquery} = require("../zjsunit/zjquery"); - -set_global("$", make_zjquery()); +const $ = require("../zjsunit/zjquery"); const people = zrequire("people"); diff --git a/frontend_tests/node_tests/compose_ui.js b/frontend_tests/node_tests/compose_ui.js index da3d71ed8e..87b1250522 100644 --- a/frontend_tests/node_tests/compose_ui.js +++ b/frontend_tests/node_tests/compose_ui.js @@ -6,7 +6,7 @@ const autosize = require("autosize"); const {set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -const {make_zjquery} = require("../zjsunit/zjquery"); +const $ = require("../zjsunit/zjquery"); const compose_ui = zrequire("compose_ui"); const people = zrequire("people"); @@ -18,8 +18,6 @@ set_global("document", { }, }); -set_global("$", make_zjquery()); - const alice = { email: "alice@zulip.com", user_id: 101, diff --git a/frontend_tests/node_tests/composebox_typeahead.js b/frontend_tests/node_tests/composebox_typeahead.js index 67f5e92887..1a6db212dc 100644 --- a/frontend_tests/node_tests/composebox_typeahead.js +++ b/frontend_tests/node_tests/composebox_typeahead.js @@ -4,7 +4,7 @@ const {strict: assert} = require("assert"); const {set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -const {make_zjquery} = require("../zjsunit/zjquery"); +const $ = require("../zjsunit/zjquery"); const emoji = zrequire("emoji", "shared/js/emoji"); const typeahead = zrequire("typeahead", "shared/js/typeahead"); @@ -171,8 +171,6 @@ stream_data.add_sub(sweden_stream); stream_data.add_sub(denmark_stream); stream_data.add_sub(netherland_stream); -set_global("$", make_zjquery()); - set_global("page_params", {}); const channel = set_global("channel", {}); const compose = set_global("compose", { diff --git a/frontend_tests/node_tests/copy_and_paste.js b/frontend_tests/node_tests/copy_and_paste.js index 9c1d4f4c0b..ceeb536462 100644 --- a/frontend_tests/node_tests/copy_and_paste.js +++ b/frontend_tests/node_tests/copy_and_paste.js @@ -2,6 +2,7 @@ const {strict: assert} = require("assert"); +const jquery = require("jquery"); const {JSDOM} = require("jsdom"); const {set_global, zrequire} = require("../zjsunit/namespace"); @@ -14,7 +15,7 @@ const compose_ui = set_global("compose_ui", {}); const {window} = new JSDOM("

Hello world

"); const {DOMParser, document} = window; -set_global("$", require("jquery")(window)); +const $ = set_global("$", jquery(window)); set_global("DOMParser", DOMParser); set_global("document", document); diff --git a/frontend_tests/node_tests/dispatch.js b/frontend_tests/node_tests/dispatch.js index 57a30c8443..607b674a61 100644 --- a/frontend_tests/node_tests/dispatch.js +++ b/frontend_tests/node_tests/dispatch.js @@ -5,7 +5,7 @@ const {strict: assert} = require("assert"); const {set_global, zrequire} = require("../zjsunit/namespace"); const {make_stub} = require("../zjsunit/stub"); const {run_test} = require("../zjsunit/test"); -const {make_zjquery} = require("../zjsunit/zjquery"); +const $ = require("../zjsunit/zjquery"); const noop = function () {}; @@ -16,8 +16,6 @@ const test_message = events.test_message; const test_user = events.test_user; const typing_person1 = events.typing_person1; -set_global("$", make_zjquery()); - set_global("setTimeout", (func) => func()); const activity = set_global("activity", {}); diff --git a/frontend_tests/node_tests/drafts.js b/frontend_tests/node_tests/drafts.js index 29b8a4fc5c..beabb83846 100644 --- a/frontend_tests/node_tests/drafts.js +++ b/frontend_tests/node_tests/drafts.js @@ -5,9 +5,7 @@ const {strict: assert} = require("assert"); const {stub_templates} = require("../zjsunit/handlebars"); const {set_global, zrequire, with_overrides} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -const {make_zjquery} = require("../zjsunit/zjquery"); - -set_global("$", make_zjquery()); +const $ = require("../zjsunit/zjquery"); const localstorage = zrequire("localstorage"); const drafts = zrequire("drafts"); diff --git a/frontend_tests/node_tests/dropdown_list_widget.js b/frontend_tests/node_tests/dropdown_list_widget.js index 9dd972232c..b4fda89b5d 100644 --- a/frontend_tests/node_tests/dropdown_list_widget.js +++ b/frontend_tests/node_tests/dropdown_list_widget.js @@ -4,11 +4,10 @@ const {strict: assert} = require("assert"); const {set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -const {make_zjquery} = require("../zjsunit/zjquery"); +const $ = require("../zjsunit/zjquery"); const dropdown_list_widget = zrequire("dropdown_list_widget"); zrequire("scroll_util"); -set_global("$", make_zjquery()); const noop = () => {}; const _ListWidget = { diff --git a/frontend_tests/node_tests/echo.js b/frontend_tests/node_tests/echo.js index 8fefbf6081..afd1d1cfd8 100644 --- a/frontend_tests/node_tests/echo.js +++ b/frontend_tests/node_tests/echo.js @@ -6,9 +6,7 @@ const MockDate = require("mockdate"); const {set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -const {make_zjquery} = require("../zjsunit/zjquery"); -set_global("$", make_zjquery()); const local_message = set_global("local_message", {}); const markdown = set_global("markdown", {}); set_global("page_params", {}); diff --git a/frontend_tests/node_tests/filter.js b/frontend_tests/node_tests/filter.js index 145d16b4a9..d011f9e70b 100644 --- a/frontend_tests/node_tests/filter.js +++ b/frontend_tests/node_tests/filter.js @@ -4,12 +4,11 @@ const {strict: assert} = require("assert"); const {set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -const {make_zjquery} = require("../zjsunit/zjquery"); +const $ = require("../zjsunit/zjquery"); zrequire("unread"); const stream_data = zrequire("stream_data"); const people = zrequire("people"); -set_global("$", make_zjquery()); zrequire("message_util", "js/message_util"); const Filter = zrequire("Filter", "js/filter"); diff --git a/frontend_tests/node_tests/hash_util.js b/frontend_tests/node_tests/hash_util.js index 95d28342ca..ea35ac9a18 100644 --- a/frontend_tests/node_tests/hash_util.js +++ b/frontend_tests/node_tests/hash_util.js @@ -4,7 +4,6 @@ const {strict: assert} = require("assert"); const {set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -const {make_zjquery} = require("../zjsunit/zjquery"); const hash_util = zrequire("hash_util"); const stream_data = zrequire("stream_data"); @@ -12,8 +11,6 @@ const people = zrequire("people"); const Filter = zrequire("Filter", "js/filter"); const narrow_state = zrequire("narrow_state"); -set_global("$", make_zjquery()); - const ui_report = set_global("ui_report", { displayed_error: false, error: () => { diff --git a/frontend_tests/node_tests/hashchange.js b/frontend_tests/node_tests/hashchange.js index 24fbe85112..a52a67213a 100644 --- a/frontend_tests/node_tests/hashchange.js +++ b/frontend_tests/node_tests/hashchange.js @@ -4,9 +4,8 @@ const {strict: assert} = require("assert"); const {set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -const {make_zjquery} = require("../zjsunit/zjquery"); +const $ = require("../zjsunit/zjquery"); -set_global("$", make_zjquery()); const window_stub = $.create("window-stub"); set_global("location", { protocol: "http:", diff --git a/frontend_tests/node_tests/hotkey.js b/frontend_tests/node_tests/hotkey.js index c0e072d906..262a40e1ea 100644 --- a/frontend_tests/node_tests/hotkey.js +++ b/frontend_tests/node_tests/hotkey.js @@ -5,7 +5,6 @@ const {strict: assert} = require("assert"); const {set_global, with_overrides, zrequire} = require("../zjsunit/namespace"); const {make_stub} = require("../zjsunit/stub"); const {run_test} = require("../zjsunit/test"); -const {make_zjquery} = require("../zjsunit/zjquery"); // Important note on these tests: // @@ -32,7 +31,6 @@ let overlays = set_global("overlays", {}); // jQuery stuff should go away if we make an initialize() method. set_global("document", "document-stub"); -set_global("$", make_zjquery()); const emoji = zrequire("emoji", "shared/js/emoji"); diff --git a/frontend_tests/node_tests/input_pill.js b/frontend_tests/node_tests/input_pill.js index c25863c6de..a73c5b12e3 100644 --- a/frontend_tests/node_tests/input_pill.js +++ b/frontend_tests/node_tests/input_pill.js @@ -4,9 +4,8 @@ const {strict: assert} = require("assert"); const {set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -const {make_zjquery} = require("../zjsunit/zjquery"); +const $ = require("../zjsunit/zjquery"); -set_global("$", make_zjquery()); 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 42b98deffc..7e6d2bbddd 100644 --- a/frontend_tests/node_tests/keydown_util.js +++ b/frontend_tests/node_tests/keydown_util.js @@ -1,10 +1,8 @@ "use strict"; -const {set_global, zrequire} = require("../zjsunit/namespace"); +const {zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -const {make_zjquery} = require("../zjsunit/zjquery"); - -set_global("$", make_zjquery()); +const $ = require("../zjsunit/zjquery"); const keydown_util = zrequire("keydown_util"); diff --git a/frontend_tests/node_tests/lightbox.js b/frontend_tests/node_tests/lightbox.js index c3bbab239c..fe84e24e18 100644 --- a/frontend_tests/node_tests/lightbox.js +++ b/frontend_tests/node_tests/lightbox.js @@ -4,7 +4,7 @@ const {strict: assert} = require("assert"); const {set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -const {make_zjquery} = require("../zjsunit/zjquery"); +const $ = require("../zjsunit/zjquery"); const rows = zrequire("rows"); const lightbox = zrequire("lightbox"); @@ -22,8 +22,6 @@ set_global("popovers", { rows.is_draft_row = () => false; -set_global("$", make_zjquery()); - run_test("pan_and_zoom", () => { $.clear_all_elements(); diff --git a/frontend_tests/node_tests/markdown.js b/frontend_tests/node_tests/markdown.js index 831adb8774..79fd686d8d 100644 --- a/frontend_tests/node_tests/markdown.js +++ b/frontend_tests/node_tests/markdown.js @@ -6,7 +6,6 @@ const markdown_test_cases = require("../../zerver/tests/fixtures/markdown_test_c const markdown_assert = require("../zjsunit/markdown_assert"); const {set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -const {make_zjquery} = require("../zjsunit/zjquery"); zrequire("hash_util"); @@ -62,8 +61,6 @@ fenced_code.initialize(pygments_data); const doc = ""; set_global("document", doc); -set_global("$", make_zjquery()); - const cordelia = { full_name: "Cordelia Lear", user_id: 101, diff --git a/frontend_tests/node_tests/message_events.js b/frontend_tests/node_tests/message_events.js index f5c3d36948..25de0d9d1e 100644 --- a/frontend_tests/node_tests/message_events.js +++ b/frontend_tests/node_tests/message_events.js @@ -4,7 +4,6 @@ const {strict: assert} = require("assert"); const {set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -const {make_zjquery} = require("../zjsunit/zjquery"); const message_events = zrequire("message_events"); const message_store = zrequire("message_store"); @@ -15,7 +14,6 @@ const stream_data = zrequire("stream_data"); const stream_topic_history = zrequire("stream_topic_history"); const unread = zrequire("unread"); -set_global("$", make_zjquery()); const condense = set_global("condense", {}); set_global("current_msg_list", {}); const message_edit = set_global("message_edit", {}); diff --git a/frontend_tests/node_tests/message_fetch.js b/frontend_tests/node_tests/message_fetch.js index bdd6d29543..687fbf9c39 100644 --- a/frontend_tests/node_tests/message_fetch.js +++ b/frontend_tests/node_tests/message_fetch.js @@ -6,9 +6,8 @@ const _ = require("lodash"); const {set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -const {make_zjquery} = require("../zjsunit/zjquery"); +const $ = require("../zjsunit/zjquery"); -set_global("$", make_zjquery()); set_global("document", "document-stub"); const message_fetch = zrequire("message_fetch"); diff --git a/frontend_tests/node_tests/message_list.js b/frontend_tests/node_tests/message_list.js index 94cbb83648..24e06ede13 100644 --- a/frontend_tests/node_tests/message_list.js +++ b/frontend_tests/node_tests/message_list.js @@ -5,6 +5,7 @@ const {strict: assert} = require("assert"); const {set_global, stub_out_jquery, zrequire} = require("../zjsunit/namespace"); const {make_stub} = require("../zjsunit/stub"); const {run_test} = require("../zjsunit/test"); + // These unit tests for static/js/message_list.js emphasize the model-ish // aspects of the MessageList class. We have to stub out a few functions // related to views and events to get the tests working. @@ -31,7 +32,7 @@ function accept_all_filter() { return filter; } -run_test("basics", () => { +run_test("basics", (override) => { const filter = accept_all_filter(); const list = new MessageList({ @@ -74,9 +75,9 @@ run_test("basics", () => { assert.deepEqual(list.all_messages(), messages); - $.Event = function (ev) { + override(global.$, "Event", (ev) => { assert.equal(ev, "message_selected.zulip"); - }; + }); list.select_id(50); assert.equal(list.selected_id(), 50); diff --git a/frontend_tests/node_tests/message_list_view.js b/frontend_tests/node_tests/message_list_view.js index 3ed2f3d52b..f17e46d523 100644 --- a/frontend_tests/node_tests/message_list_view.js +++ b/frontend_tests/node_tests/message_list_view.js @@ -6,9 +6,7 @@ const _ = require("lodash"); const {set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -const {make_zjquery} = require("../zjsunit/zjquery"); -set_global("$", make_zjquery()); set_global("document", "document-stub"); const Filter = zrequire("Filter", "js/filter"); diff --git a/frontend_tests/node_tests/message_store.js b/frontend_tests/node_tests/message_store.js index 60ba333c6e..ed41db3b1e 100644 --- a/frontend_tests/node_tests/message_store.js +++ b/frontend_tests/node_tests/message_store.js @@ -5,7 +5,6 @@ const {strict: assert} = require("assert"); const {set_global, zrequire} = require("../zjsunit/namespace"); const {make_stub} = require("../zjsunit/stub"); const {run_test} = require("../zjsunit/test"); -const {make_zjquery} = require("../zjsunit/zjquery"); const util = zrequire("util"); const people = zrequire("people"); @@ -13,7 +12,6 @@ const message_store = zrequire("message_store"); const noop = function () {}; -set_global("$", make_zjquery()); set_global("document", "document-stub"); set_global("stream_topic_history", { diff --git a/frontend_tests/node_tests/narrow.js b/frontend_tests/node_tests/narrow.js index 12815c6530..13fd4c225c 100644 --- a/frontend_tests/node_tests/narrow.js +++ b/frontend_tests/node_tests/narrow.js @@ -4,9 +4,8 @@ const {strict: assert} = require("assert"); const {set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -const {make_zjquery} = require("../zjsunit/zjquery"); +const $ = require("../zjsunit/zjquery"); -set_global("$", make_zjquery()); const hash_util = zrequire("hash_util"); zrequire("hashchange"); const narrow_state = zrequire("narrow_state"); diff --git a/frontend_tests/node_tests/narrow_activate.js b/frontend_tests/node_tests/narrow_activate.js index e7bf887649..46b5e29a6f 100644 --- a/frontend_tests/node_tests/narrow_activate.js +++ b/frontend_tests/node_tests/narrow_activate.js @@ -4,10 +4,8 @@ const {strict: assert} = require("assert"); const {set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -const {make_zjquery} = require("../zjsunit/zjquery"); const util = zrequire("util"); -set_global("$", make_zjquery()); const narrow_state = zrequire("narrow_state"); set_global("resize", { diff --git a/frontend_tests/node_tests/notifications.js b/frontend_tests/node_tests/notifications.js index 83ffdd6882..702e599724 100644 --- a/frontend_tests/node_tests/notifications.js +++ b/frontend_tests/node_tests/notifications.js @@ -6,10 +6,9 @@ const rewiremock = require("rewiremock/node"); const {set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -const {make_zjquery} = require("../zjsunit/zjquery"); // Dependencies -set_global("$", make_zjquery()); + set_global("document", { hasFocus() { return true; diff --git a/frontend_tests/node_tests/pm_list.js b/frontend_tests/node_tests/pm_list.js index 300a78392e..6dbe91bde7 100644 --- a/frontend_tests/node_tests/pm_list.js +++ b/frontend_tests/node_tests/pm_list.js @@ -4,9 +4,7 @@ const {strict: assert} = require("assert"); const {set_global, with_field, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -const {make_zjquery} = require("../zjsunit/zjquery"); - -set_global("$", make_zjquery()); +const $ = require("../zjsunit/zjquery"); const narrow_state = set_global("narrow_state", {}); set_global("ui", { diff --git a/frontend_tests/node_tests/poll_widget.js b/frontend_tests/node_tests/poll_widget.js index c38c61b82c..b41e061ce9 100644 --- a/frontend_tests/node_tests/poll_widget.js +++ b/frontend_tests/node_tests/poll_widget.js @@ -3,14 +3,12 @@ const {strict: assert} = require("assert"); const {stub_templates} = require("../zjsunit/handlebars"); -const {set_global, zrequire} = require("../zjsunit/namespace"); +const {zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -const {make_zjquery} = require("../zjsunit/zjquery"); +const $ = require("../zjsunit/zjquery"); const poll_widget = zrequire("poll_widget"); -set_global("$", make_zjquery()); - const people = zrequire("people"); const return_false = () => false; diff --git a/frontend_tests/node_tests/popovers.js b/frontend_tests/node_tests/popovers.js index 6db0f8dfc8..bbb8ecab0f 100644 --- a/frontend_tests/node_tests/popovers.js +++ b/frontend_tests/node_tests/popovers.js @@ -7,9 +7,7 @@ const rewiremock = require("rewiremock/node"); const {stub_templates} = require("../zjsunit/handlebars"); const {set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -const {make_zjquery} = require("../zjsunit/zjquery"); - -set_global("$", make_zjquery()); +const $ = require("../zjsunit/zjquery"); zrequire("hash_util"); zrequire("narrow"); diff --git a/frontend_tests/node_tests/reactions.js b/frontend_tests/node_tests/reactions.js index 4a24822c21..217596ed21 100644 --- a/frontend_tests/node_tests/reactions.js +++ b/frontend_tests/node_tests/reactions.js @@ -6,10 +6,9 @@ const {stub_templates} = require("../zjsunit/handlebars"); const {set_global, zrequire} = require("../zjsunit/namespace"); const {make_stub} = require("../zjsunit/stub"); const {run_test} = require("../zjsunit/test"); -const {make_zjquery} = require("../zjsunit/zjquery"); +const $ = require("../zjsunit/zjquery"); set_global("document", "document-stub"); -set_global("$", make_zjquery()); const emoji_codes = zrequire("emoji_codes", "generated/emoji/emoji_codes.json"); const emoji = zrequire("emoji", "shared/js/emoji"); diff --git a/frontend_tests/node_tests/recent_topics.js b/frontend_tests/node_tests/recent_topics.js index 2d1e2a8c91..b4b3c723df 100644 --- a/frontend_tests/node_tests/recent_topics.js +++ b/frontend_tests/node_tests/recent_topics.js @@ -5,12 +5,12 @@ const {strict: assert} = require("assert"); const {stub_templates} = require("../zjsunit/handlebars"); const {reset_module, set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -const {make_zjquery} = require("../zjsunit/zjquery"); +const $ = require("../zjsunit/zjquery"); zrequire("message_util"); const noop = () => {}; -set_global("$", make_zjquery()); + set_global("hashchange", { exit_overlay: noop, }); diff --git a/frontend_tests/node_tests/rendered_markdown.js b/frontend_tests/node_tests/rendered_markdown.js index c854783884..6905666795 100644 --- a/frontend_tests/node_tests/rendered_markdown.js +++ b/frontend_tests/node_tests/rendered_markdown.js @@ -4,14 +4,13 @@ const {strict: assert} = require("assert"); const {set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -const {make_zjquery} = require("../zjsunit/zjquery"); +const $ = require("../zjsunit/zjquery"); const rm = zrequire("rendered_markdown"); const people = zrequire("people"); const user_groups = zrequire("user_groups"); const stream_data = zrequire("stream_data"); zrequire("timerender"); -set_global("$", make_zjquery()); set_global("rtl", { get_direction: () => "ltr", diff --git a/frontend_tests/node_tests/search.js b/frontend_tests/node_tests/search.js index edf32ec509..6437d7138a 100644 --- a/frontend_tests/node_tests/search.js +++ b/frontend_tests/node_tests/search.js @@ -4,7 +4,7 @@ const {strict: assert} = require("assert"); const {set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -const {make_zjquery} = require("../zjsunit/zjquery"); +const $ = require("../zjsunit/zjquery"); set_global("page_params", { search_pills_enabled: true, @@ -18,7 +18,6 @@ const noop = () => {}; const return_true = () => true; const return_false = () => false; -set_global("$", make_zjquery()); const narrow_state = set_global("narrow_state", {filter: return_false}); const search_suggestion = set_global("search_suggestion", {}); set_global("ui_util", { diff --git a/frontend_tests/node_tests/search_legacy.js b/frontend_tests/node_tests/search_legacy.js index eeb5b3dbc4..ca4a3e0fdc 100644 --- a/frontend_tests/node_tests/search_legacy.js +++ b/frontend_tests/node_tests/search_legacy.js @@ -4,7 +4,7 @@ const {strict: assert} = require("assert"); const {set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -const {make_zjquery} = require("../zjsunit/zjquery"); +const $ = require("../zjsunit/zjquery"); set_global("page_params", { search_pills_enabled: false, @@ -16,7 +16,6 @@ const noop = () => {}; const return_true = () => true; const return_false = () => false; -set_global("$", make_zjquery()); const narrow_state = set_global("narrow_state", {}); const search_suggestion = set_global("search_suggestion", {}); set_global("ui_util", { diff --git a/frontend_tests/node_tests/settings_bots.js b/frontend_tests/node_tests/settings_bots.js index 278f399e39..64ff4902ef 100644 --- a/frontend_tests/node_tests/settings_bots.js +++ b/frontend_tests/node_tests/settings_bots.js @@ -6,7 +6,7 @@ const rewiremock = require("rewiremock/node"); const {set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -const {make_zjquery} = require("../zjsunit/zjquery"); +const $ = require("../zjsunit/zjquery"); set_global("page_params", { realm_uri: "https://chat.example.com", @@ -31,8 +31,6 @@ const bot_data_params = { const avatar = set_global("avatar", {}); -set_global("$", make_zjquery()); - const bot_data = zrequire("bot_data"); function ClipboardJS(sel) { diff --git a/frontend_tests/node_tests/settings_emoji.js b/frontend_tests/node_tests/settings_emoji.js index 98418a2c90..97c3699e69 100644 --- a/frontend_tests/node_tests/settings_emoji.js +++ b/frontend_tests/node_tests/settings_emoji.js @@ -4,9 +4,8 @@ const {strict: assert} = require("assert"); const {set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -const {make_zjquery} = require("../zjsunit/zjquery"); +const $ = require("../zjsunit/zjquery"); -set_global("$", make_zjquery()); const upload_widget = set_global("upload_widget", {}); const settings_emoji = zrequire("settings_emoji"); diff --git a/frontend_tests/node_tests/settings_muting.js b/frontend_tests/node_tests/settings_muting.js index 98e65038c2..4a745de15b 100644 --- a/frontend_tests/node_tests/settings_muting.js +++ b/frontend_tests/node_tests/settings_muting.js @@ -4,9 +4,7 @@ const {strict: assert} = require("assert"); const {set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -const {make_zjquery} = require("../zjsunit/zjquery"); - -set_global("$", make_zjquery()); +const $ = require("../zjsunit/zjquery"); zrequire("timerender"); const settings_muting = zrequire("settings_muting"); diff --git a/frontend_tests/node_tests/settings_org.js b/frontend_tests/node_tests/settings_org.js index a488499ae2..ec0d120fd9 100644 --- a/frontend_tests/node_tests/settings_org.js +++ b/frontend_tests/node_tests/settings_org.js @@ -7,9 +7,7 @@ const rewiremock = require("rewiremock/node"); const {stub_templates} = require("../zjsunit/handlebars"); const {set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -const {make_zjquery} = require("../zjsunit/zjquery"); - -set_global("$", make_zjquery()); +const $ = require("../zjsunit/zjquery"); const noop = () => {}; diff --git a/frontend_tests/node_tests/settings_profile_fields.js b/frontend_tests/node_tests/settings_profile_fields.js index f814d13fa2..5f893f3759 100644 --- a/frontend_tests/node_tests/settings_profile_fields.js +++ b/frontend_tests/node_tests/settings_profile_fields.js @@ -7,10 +7,9 @@ const rewiremock = require("rewiremock/node"); const {stub_templates} = require("../zjsunit/handlebars"); const {set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -const {make_zjquery} = require("../zjsunit/zjquery"); +const $ = require("../zjsunit/zjquery"); set_global("page_params", {}); -set_global("$", make_zjquery()); const loading = set_global("loading", {}); const SHORT_TEXT_ID = 1; diff --git a/frontend_tests/node_tests/settings_user_groups.js b/frontend_tests/node_tests/settings_user_groups.js index 95e8210d6f..fb92ac2bd0 100644 --- a/frontend_tests/node_tests/settings_user_groups.js +++ b/frontend_tests/node_tests/settings_user_groups.js @@ -7,12 +7,11 @@ const _ = require("lodash"); const {stub_templates} = require("../zjsunit/handlebars"); const {set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -const {make_zjquery} = require("../zjsunit/zjquery"); +const $ = require("../zjsunit/zjquery"); const user_pill = zrequire("user_pill"); const settings_user_groups = zrequire("settings_user_groups"); -set_global("$", make_zjquery()); const confirm_dialog = set_global("confirm_dialog", {}); const noop = function () {}; diff --git a/frontend_tests/node_tests/spoilers.js b/frontend_tests/node_tests/spoilers.js index 32d9410a06..0d7383b93f 100644 --- a/frontend_tests/node_tests/spoilers.js +++ b/frontend_tests/node_tests/spoilers.js @@ -2,11 +2,10 @@ const {strict: assert} = require("assert"); -const {set_global, zrequire} = require("../zjsunit/namespace"); +const {zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -const {make_zjquery} = require("../zjsunit/zjquery"); +const $ = require("../zjsunit/zjquery"); -set_global("$", make_zjquery()); const spoilers = zrequire("spoilers"); // This function is taken from rendered_markdown.js and slightly modified. diff --git a/frontend_tests/node_tests/stream_edit.js b/frontend_tests/node_tests/stream_edit.js index 10c9e8aeeb..538f58c644 100644 --- a/frontend_tests/node_tests/stream_edit.js +++ b/frontend_tests/node_tests/stream_edit.js @@ -5,7 +5,7 @@ const {strict: assert} = require("assert"); const {stub_templates} = require("../zjsunit/handlebars"); const {set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -const {make_zjquery} = require("../zjsunit/zjquery"); +const $ = require("../zjsunit/zjquery"); const noop = () => {}; stub_templates(() => noop); @@ -30,7 +30,6 @@ const typeahead_helper = set_global("typeahead_helper", {}); const ui = set_global("ui", { get_scroll_element: noop, }); -set_global("$", make_zjquery()); zrequire("input_pill"); const peer_data = zrequire("peer_data"); diff --git a/frontend_tests/node_tests/stream_events.js b/frontend_tests/node_tests/stream_events.js index 8df0fe2483..7c1ec05e07 100644 --- a/frontend_tests/node_tests/stream_events.js +++ b/frontend_tests/node_tests/stream_events.js @@ -5,13 +5,12 @@ const {strict: assert} = require("assert"); const {set_global, zrequire} = require("../zjsunit/namespace"); const {make_stub} = require("../zjsunit/stub"); const {run_test} = require("../zjsunit/test"); -const {make_zjquery} = require("../zjsunit/zjquery"); +const $ = require("../zjsunit/zjquery"); const noop = function () {}; const return_true = function () { return true; }; -set_global("$", make_zjquery()); const _settings_notifications = { update_page: () => {}, }; diff --git a/frontend_tests/node_tests/stream_list.js b/frontend_tests/node_tests/stream_list.js index c1e15b847c..c106aff366 100644 --- a/frontend_tests/node_tests/stream_list.js +++ b/frontend_tests/node_tests/stream_list.js @@ -5,10 +5,9 @@ const {strict: assert} = require("assert"); const {stub_templates} = require("../zjsunit/handlebars"); const {set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -const {make_zjquery} = require("../zjsunit/zjquery"); +const $ = require("../zjsunit/zjquery"); set_global("document", "document-stub"); -set_global("$", make_zjquery()); zrequire("unread_ui"); const Filter = zrequire("Filter", "js/filter"); diff --git a/frontend_tests/node_tests/stream_search.js b/frontend_tests/node_tests/stream_search.js index 40126d8bca..182b8b5438 100644 --- a/frontend_tests/node_tests/stream_search.js +++ b/frontend_tests/node_tests/stream_search.js @@ -4,11 +4,10 @@ const {strict: assert} = require("assert"); const {set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -const {make_zjquery} = require("../zjsunit/zjquery"); -// This tests the stream searching functionality which currently +const $ = require("../zjsunit/zjquery"); + // lives in stream_list.js. -set_global("$", make_zjquery()); const stream_list = zrequire("stream_list"); const noop = () => {}; diff --git a/frontend_tests/node_tests/subs.js b/frontend_tests/node_tests/subs.js index 83d4f65d4e..da6da30452 100644 --- a/frontend_tests/node_tests/subs.js +++ b/frontend_tests/node_tests/subs.js @@ -5,7 +5,7 @@ const {strict: assert} = require("assert"); const {stub_templates} = require("../zjsunit/handlebars"); const {set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -const {make_zjquery} = require("../zjsunit/zjquery"); +const $ = require("../zjsunit/zjquery"); const ui = set_global("ui", { get_content_element: (element) => element, @@ -22,7 +22,6 @@ set_global("location", { const subs = zrequire("subs"); -set_global("$", make_zjquery()); set_global("hash_util", { by_stream_uri: () => {}, }); diff --git a/frontend_tests/node_tests/support.js b/frontend_tests/node_tests/support.js index 5b260e5f1b..86ae2c3bdc 100644 --- a/frontend_tests/node_tests/support.js +++ b/frontend_tests/node_tests/support.js @@ -5,16 +5,14 @@ const fs = require("fs"); const {JSDOM} = require("jsdom"); -const {set_global, zrequire} = require("../zjsunit/namespace"); +const {zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -const {make_zjquery} = require("../zjsunit/zjquery"); +const $ = require("../zjsunit/zjquery"); const template = fs.readFileSync("templates/analytics/realm_details.html", "utf-8"); const dom = new JSDOM(template, {pretendToBeVisual: true}); const document = dom.window.document; -set_global("$", make_zjquery()); - run_test("scrub_realm", () => { zrequire("support", "js/analytics/support"); const click_handler = $("body").get_on_handler("click", ".scrub-realm-button"); diff --git a/frontend_tests/node_tests/timerender.js b/frontend_tests/node_tests/timerender.js index d2f9fc1505..16aa405981 100644 --- a/frontend_tests/node_tests/timerender.js +++ b/frontend_tests/node_tests/timerender.js @@ -7,9 +7,8 @@ const MockDate = require("mockdate"); const {set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -const {make_zjquery} = require("../zjsunit/zjquery"); +const $ = require("../zjsunit/zjquery"); -set_global("$", make_zjquery()); set_global("page_params", { twenty_four_hour_time: true, }); diff --git a/frontend_tests/node_tests/top_left_corner.js b/frontend_tests/node_tests/top_left_corner.js index 9532b2542a..7352a1a39c 100644 --- a/frontend_tests/node_tests/top_left_corner.js +++ b/frontend_tests/node_tests/top_left_corner.js @@ -4,9 +4,7 @@ const {strict: assert} = require("assert"); const {set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -const {make_zjquery} = require("../zjsunit/zjquery"); - -set_global("$", make_zjquery()); +const $ = require("../zjsunit/zjquery"); const Filter = zrequire("Filter", "js/filter"); zrequire("unread_ui"); diff --git a/frontend_tests/node_tests/transmit.js b/frontend_tests/node_tests/transmit.js index 09ce8d82a7..a3bbf03a9f 100644 --- a/frontend_tests/node_tests/transmit.js +++ b/frontend_tests/node_tests/transmit.js @@ -4,11 +4,9 @@ const {strict: assert} = require("assert"); const {set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -const {make_zjquery} = require("../zjsunit/zjquery"); const noop = function () {}; -set_global("$", make_zjquery()); set_global("page_params", {}); const channel = set_global("channel", {}); const reload = set_global("reload", {}); diff --git a/frontend_tests/node_tests/ui_init.js b/frontend_tests/node_tests/ui_init.js index 6b3337d7f1..00c496aca1 100644 --- a/frontend_tests/node_tests/ui_init.js +++ b/frontend_tests/node_tests/ui_init.js @@ -5,7 +5,7 @@ const rewiremock = require("rewiremock/node"); const {stub_templates} = require("../zjsunit/handlebars"); const {set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -const {make_zjquery} = require("../zjsunit/zjquery"); +const $ = require("../zjsunit/zjquery"); /* This test suite is designed to find errors @@ -27,6 +27,7 @@ const {make_zjquery} = require("../zjsunit/zjquery"); some things can happen later in a `launch` method. */ + const util = zrequire("util"); set_global("document", { @@ -118,7 +119,7 @@ const ui_init = rewiremock.proxy(() => zrequire("ui_init"), { }, }); -set_global("$", make_zjquery()); +set_global("$", $); run_test("initialize_everything", () => { util.is_mobile = () => false; diff --git a/frontend_tests/node_tests/upgrade.js b/frontend_tests/node_tests/upgrade.js index 6b909be045..3233c10b42 100644 --- a/frontend_tests/node_tests/upgrade.js +++ b/frontend_tests/node_tests/upgrade.js @@ -7,7 +7,7 @@ const {JSDOM} = require("jsdom"); const {set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -const {make_zjquery} = require("../zjsunit/zjquery"); +const $ = require("../zjsunit/zjquery"); const noop = () => {}; const template = fs.readFileSync("templates/corporate/upgrade.html", "utf-8"); @@ -26,7 +26,6 @@ set_global("page_params", { }); const helpers = zrequire("helpers", "js/billing/helpers"); -set_global("$", make_zjquery()); run_test("initialize", () => { let token_func; diff --git a/frontend_tests/node_tests/upload.js b/frontend_tests/node_tests/upload.js index 345af29e7a..a74bd790ce 100644 --- a/frontend_tests/node_tests/upload.js +++ b/frontend_tests/node_tests/upload.js @@ -6,9 +6,8 @@ const rewiremock = require("rewiremock/node"); const {set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -const {make_zjquery} = require("../zjsunit/zjquery"); +const $ = require("../zjsunit/zjquery"); -set_global("$", make_zjquery()); set_global("document", { location: {}, }); diff --git a/frontend_tests/node_tests/user_events.js b/frontend_tests/node_tests/user_events.js index 972aa1684f..5b0b35f2e6 100644 --- a/frontend_tests/node_tests/user_events.js +++ b/frontend_tests/node_tests/user_events.js @@ -4,9 +4,6 @@ const {strict: assert} = require("assert"); const {set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -const {make_zjquery} = require("../zjsunit/zjquery"); - -set_global("$", make_zjquery()); const people = zrequire("people"); const settings_config = zrequire("settings_config"); diff --git a/frontend_tests/node_tests/util.js b/frontend_tests/node_tests/util.js index 1c23ae1def..efe82afe48 100644 --- a/frontend_tests/node_tests/util.js +++ b/frontend_tests/node_tests/util.js @@ -7,9 +7,7 @@ const _ = require("lodash"); const {set_global, with_field, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -const {make_zjquery} = require("../zjsunit/zjquery"); -set_global("$", make_zjquery()); set_global("DOMParser", new JSDOM().window.DOMParser); set_global("document", {}); const util = zrequire("util"); diff --git a/frontend_tests/node_tests/widgetize.js b/frontend_tests/node_tests/widgetize.js index 221e9bba29..cc21242dec 100644 --- a/frontend_tests/node_tests/widgetize.js +++ b/frontend_tests/node_tests/widgetize.js @@ -4,9 +4,8 @@ const {strict: assert} = require("assert"); const {set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -const {make_zjquery} = require("../zjsunit/zjquery"); +const $ = require("../zjsunit/zjquery"); -set_global("$", make_zjquery()); const poll_widget = set_global("poll_widget", {}); set_global("document", "document-stub"); diff --git a/frontend_tests/node_tests/zjquery.js b/frontend_tests/node_tests/zjquery.js index 4641db9b08..8263656f6b 100644 --- a/frontend_tests/node_tests/zjquery.js +++ b/frontend_tests/node_tests/zjquery.js @@ -2,9 +2,8 @@ const {strict: assert} = require("assert"); -const {set_global} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -const {make_zjquery} = require("../zjsunit/zjquery"); +const $ = require("../zjsunit/zjquery"); /* @@ -30,12 +29,6 @@ The code we are testing lives here: */ -// The first thing we do to use zjquery is patch our global namespace -// with zjquery as follows. This call gives us our own instance of a -// zjquery stub variable. Like with real jQuery, the '$' function will -// be the gateway to a bigger API. -set_global("$", make_zjquery()); - run_test("basics", () => { // Let's create a sample piece of code to test: diff --git a/frontend_tests/zjsunit/index.js b/frontend_tests/zjsunit/index.js index d3830a0013..9804eff90e 100644 --- a/frontend_tests/zjsunit/index.js +++ b/frontend_tests/zjsunit/index.js @@ -13,6 +13,8 @@ const namespace = require("./namespace"); const test = require("./test"); const {make_zblueslip} = require("./zblueslip"); +global.$ = require("./zjquery"); + require("@babel/register")({ extensions: [".es6", ".es", ".jsx", ".js", ".mjs", ".ts"], only: [ @@ -66,6 +68,7 @@ function short_tb(tb) { } function run_one_module(file) { + global.$.clear_all_elements(); console.info("running test " + path.basename(file, ".js")); test.set_current_file_name(file); require(file); diff --git a/frontend_tests/zjsunit/zjquery.js b/frontend_tests/zjsunit/zjquery.js index 0af6b4fc66..911a19d316 100644 --- a/frontend_tests/zjsunit/zjquery.js +++ b/frontend_tests/zjsunit/zjquery.js @@ -16,7 +16,7 @@ class Event { stopPropagation() {} } -exports.make_event_store = (selector) => { +function make_event_store(selector) { /* This function returns an event_store object that @@ -144,9 +144,9 @@ exports.make_event_store = (selector) => { }; return self; -}; +} -exports.make_new_elem = function (selector, opts) { +function make_new_elem(selector, opts) { let html = "never-been-set"; let text = "never-been-set"; let value; @@ -160,7 +160,7 @@ exports.make_new_elem = function (selector, opts) { const properties = new Map(); const attrs = new Map(); const classes = new Map(); - const event_store = exports.make_event_store(selector); + const event_store = make_event_store(selector); const self = { addClass(class_name) { @@ -402,16 +402,16 @@ exports.make_new_elem = function (selector, opts) { self.length = 1; return self; -}; +} -exports.make_zjquery = function () { +function make_zjquery() { const elems = new Map(); // Our fn structure helps us simulate extending jQuery. const fn = {}; function new_elem(selector, create_opts) { - const elem = exports.make_new_elem(selector, {...create_opts}); + const elem = make_new_elem(selector, {...create_opts}); Object.assign(elem, fn); // Create a proxy handler to detect missing stubs. @@ -550,4 +550,6 @@ exports.make_zjquery = function () { }; return zjquery; -}; +} + +module.exports = make_zjquery();