diff --git a/frontend_tests/node_tests/activity.js b/frontend_tests/node_tests/activity.js index bf85d214a0..f19920b869 100644 --- a/frontend_tests/node_tests/activity.js +++ b/frontend_tests/node_tests/activity.js @@ -2,7 +2,7 @@ const {strict: assert} = require("assert"); -const {mock_module, set_global, zrequire} = require("../zjsunit/namespace"); +const {mock_esm, set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); const $ = require("../zjsunit/zjquery"); @@ -23,36 +23,36 @@ const _document = { }, }; -const compose_state = mock_module("compose_state"); -const channel = mock_module("channel"); +const compose_state = mock_esm("../../static/js/compose_state"); +const channel = mock_esm("../../static/js/channel"); -mock_module("padded_widget", { +mock_esm("../../static/js/padded_widget", { update_padding: () => {}, }); -mock_module("keydown_util", { +mock_esm("../../static/js/keydown_util", { handle: (opts) => { filter_key_handlers = opts.handlers; }, }); -mock_module("pm_list", { +mock_esm("../../static/js/pm_list", { update_private_messages: () => {}, }); -mock_module("popovers", { +mock_esm("../../static/js/popovers", { hide_all_except_sidebars() {}, hide_all() {}, show_userlist_sidebar() {}, }); -mock_module("resize", { +mock_esm("../../static/js/resize", { resize_sidebars: () => {}, resize_page_components: () => {}, }); -mock_module("scroll_util", { +mock_esm("../../static/js/scroll_util", { scroll_element_into_container: () => {}, }); -mock_module("server_events", { +mock_esm("../../static/js/server_events", { check_for_unsuspend() {}, }); -mock_module("stream_popover", { +mock_esm("../../static/js/stream_popover", { show_streamlist_sidebar() {}, }); set_global("document", _document); diff --git a/frontend_tests/node_tests/alert_words_ui.js b/frontend_tests/node_tests/alert_words_ui.js index 885740b5f2..6fbc119387 100644 --- a/frontend_tests/node_tests/alert_words_ui.js +++ b/frontend_tests/node_tests/alert_words_ui.js @@ -3,11 +3,11 @@ const {strict: assert} = require("assert"); const {stub_templates} = require("../zjsunit/handlebars"); -const {mock_module, zrequire} = require("../zjsunit/namespace"); +const {mock_esm, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); const $ = require("../zjsunit/zjquery"); -const channel = mock_module("channel"); +const channel = mock_esm("../../static/js/channel"); const alert_words = zrequire("alert_words"); const alert_words_ui = zrequire("alert_words_ui"); diff --git a/frontend_tests/node_tests/billing.js b/frontend_tests/node_tests/billing.js index 803d8fac2a..408673c256 100644 --- a/frontend_tests/node_tests/billing.js +++ b/frontend_tests/node_tests/billing.js @@ -5,7 +5,7 @@ const fs = require("fs"); const {JSDOM} = require("jsdom"); -const {mock_module, set_global, with_field, zrequire} = require("../zjsunit/namespace"); +const {mock_esm, set_global, with_field, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); const $ = require("../zjsunit/zjquery"); @@ -17,7 +17,7 @@ const StripeCheckout = set_global("StripeCheckout", { configure: () => {}, }); -const helpers = mock_module("billing/helpers", { +const helpers = mock_esm("../../static/js/billing/helpers", { set_tab: () => {}, }); diff --git a/frontend_tests/node_tests/billing_helpers.js b/frontend_tests/node_tests/billing_helpers.js index ff75342487..71d3cf4fdc 100644 --- a/frontend_tests/node_tests/billing_helpers.js +++ b/frontend_tests/node_tests/billing_helpers.js @@ -6,7 +6,7 @@ const fs = require("fs"); const jQueryFactory = require("jquery"); const {JSDOM} = require("jsdom"); -const {mock_module, set_global, zrequire} = require("../zjsunit/namespace"); +const {mock_esm, set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); const $ = require("../zjsunit/zjquery"); @@ -16,7 +16,7 @@ const jquery = jQueryFactory(dom.window); const page_params = set_global("page_params", {}); const history = set_global("history", {}); -const loading = mock_module("loading"); +const loading = mock_esm("../../static/js/loading"); set_global("document", { title: "Zulip", }); diff --git a/frontend_tests/node_tests/bot_data.js b/frontend_tests/node_tests/bot_data.js index 51592bbc69..84b6e7aeba 100644 --- a/frontend_tests/node_tests/bot_data.js +++ b/frontend_tests/node_tests/bot_data.js @@ -2,10 +2,10 @@ const {strict: assert} = require("assert"); -const {mock_module, zrequire} = require("../zjsunit/namespace"); +const {mock_esm, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -mock_module("settings_bots", { +mock_esm("../../static/js/settings_bots", { render_bots: () => {}, }); const bot_data = zrequire("bot_data"); diff --git a/frontend_tests/node_tests/buddy_data.js b/frontend_tests/node_tests/buddy_data.js index a6eba2e731..f627c24d5c 100644 --- a/frontend_tests/node_tests/buddy_data.js +++ b/frontend_tests/node_tests/buddy_data.js @@ -4,12 +4,12 @@ const {strict: assert} = require("assert"); const _ = require("lodash"); -const {mock_module, set_global, with_field, zrequire} = require("../zjsunit/namespace"); +const {mock_esm, set_global, with_field, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); const page_params = set_global("page_params", {}); -const timerender = mock_module("timerender"); +const timerender = mock_esm("../../static/js/timerender"); const people = zrequire("people"); const presence = zrequire("presence"); diff --git a/frontend_tests/node_tests/buddy_list.js b/frontend_tests/node_tests/buddy_list.js index 3804ad09da..93104568cb 100644 --- a/frontend_tests/node_tests/buddy_list.js +++ b/frontend_tests/node_tests/buddy_list.js @@ -4,15 +4,15 @@ const {strict: assert} = require("assert"); const _ = require("lodash"); -const {mock_module, zrequire} = require("../zjsunit/namespace"); +const {mock_esm, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); const $ = require("../zjsunit/zjquery"); -mock_module("padded_widget", { +mock_esm("../../static/js/padded_widget", { update_padding: () => {}, }); -mock_module("message_viewport", { +mock_esm("../../static/js/message_viewport", { height: () => 550, }); diff --git a/frontend_tests/node_tests/compose.js b/frontend_tests/node_tests/compose.js index e098660e47..b25a83a73b 100644 --- a/frontend_tests/node_tests/compose.js +++ b/frontend_tests/node_tests/compose.js @@ -6,7 +6,7 @@ const {JSDOM} = require("jsdom"); const MockDate = require("mockdate"); const {stub_templates} = require("../zjsunit/handlebars"); -const {mock_module, set_global, zrequire} = require("../zjsunit/namespace"); +const {mock_esm, set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); const $ = require("../zjsunit/zjquery"); @@ -17,7 +17,7 @@ set_global("DOMParser", new JSDOM().window.DOMParser); let compose_actions_start_checked; let compose_actions_expected_opts; -mock_module("compose_actions", { +mock_esm("../../static/js/compose_actions", { update_placeholder_text: noop, start(msg_type, opts) { @@ -27,7 +27,7 @@ mock_module("compose_actions", { }, }); -const server_events = mock_module("server_events"); +const server_events = mock_esm("../../static/js/server_events"); const _navigator = { platform: "", }; @@ -41,30 +41,30 @@ const _document = { }; set_global("document", _document); -const channel = mock_module("channel"); -const loading = mock_module("loading"); -const local_message = mock_module("local_message"); -const markdown = mock_module("markdown"); +const channel = mock_esm("../../static/js/channel"); +const loading = mock_esm("../../static/js/loading"); +const local_message = mock_esm("../../static/js/local_message"); +const markdown = mock_esm("../../static/js/markdown"); const page_params = set_global("page_params", {}); -const reminder = mock_module("reminder", { +const reminder = mock_esm("../../static/js/reminder", { is_deferred_delivery: noop, }); -const resize = mock_module("resize"); -const sent_messages = mock_module("sent_messages", { +const resize = mock_esm("../../static/js/resize"); +const sent_messages = mock_esm("../../static/js/sent_messages", { start_tracking_message: noop, }); -const stream_edit = mock_module("stream_edit"); -const subs = mock_module("subs"); -const transmit = mock_module("transmit"); -const ui_util = mock_module("ui_util"); -mock_module("drafts", { +const stream_edit = mock_esm("../../static/js/stream_edit"); +const subs = mock_esm("../../static/js/subs"); +const transmit = mock_esm("../../static/js/transmit"); +const ui_util = mock_esm("../../static/js/ui_util"); +mock_esm("../../static/js/drafts", { delete_draft_after_send: noop, }); -mock_module("notifications", { +mock_esm("../../static/js/notifications", { notify_above_composebox: noop, clear_compose_notifications: noop, }); -mock_module("rendered_markdown", { +mock_esm("../../static/js/rendered_markdown", { update_elements: () => {}, }); set_global("navigator", _navigator); diff --git a/frontend_tests/node_tests/compose_actions.js b/frontend_tests/node_tests/compose_actions.js index 70b7fb5ef9..e405627ca6 100644 --- a/frontend_tests/node_tests/compose_actions.js +++ b/frontend_tests/node_tests/compose_actions.js @@ -2,7 +2,7 @@ const {strict: assert} = require("assert"); -const {mock_module, set_global, zrequire} = require("../zjsunit/namespace"); +const {mock_esm, set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); const $ = require("../zjsunit/zjquery"); @@ -15,28 +15,28 @@ set_global("document", { to_$: () => $("document-stub"), }); -const channel = mock_module("channel"); -const compose_fade = mock_module("compose_fade", { +const channel = mock_esm("../../static/js/channel"); +const compose_fade = mock_esm("../../static/js/compose_fade", { clear_compose: noop, }); -const compose_pm_pill = mock_module("compose_pm_pill"); -const hash_util = mock_module("hash_util"); -const narrow_state = mock_module("narrow_state", { +const compose_pm_pill = mock_esm("../../static/js/compose_pm_pill"); +const hash_util = mock_esm("../../static/js/hash_util"); +const narrow_state = mock_esm("../../static/js/narrow_state", { set_compose_defaults: noop, }); -mock_module("notifications", { +mock_esm("../../static/js/notifications", { clear_compose_notifications: noop, }); -mock_module("reload_state", { +mock_esm("../../static/js/reload_state", { is_in_progress: () => false, }); -mock_module("drafts", { +mock_esm("../../static/js/drafts", { update_draft: noop, }); -mock_module("common", { +mock_esm("../../static/js/common", { status_classes: "status_classes", }); -mock_module("unread_ops", { +mock_esm("../../static/js/unread_ops", { notify_server_message_read: noop, }); set_global("current_msg_list", { diff --git a/frontend_tests/node_tests/compose_pm_pill.js b/frontend_tests/node_tests/compose_pm_pill.js index 7ce27e73f5..73954041dc 100644 --- a/frontend_tests/node_tests/compose_pm_pill.js +++ b/frontend_tests/node_tests/compose_pm_pill.js @@ -2,11 +2,11 @@ const {strict: assert} = require("assert"); -const {mock_module, zrequire} = require("../zjsunit/namespace"); +const {mock_esm, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); const $ = require("../zjsunit/zjquery"); -const compose_actions = mock_module("compose_actions"); +const compose_actions = mock_esm("../../static/js/compose_actions"); const people = zrequire("people"); const compose_pm_pill = zrequire("compose_pm_pill"); diff --git a/frontend_tests/node_tests/compose_state.js b/frontend_tests/node_tests/compose_state.js index 7123f5d59d..2528d5f30f 100644 --- a/frontend_tests/node_tests/compose_state.js +++ b/frontend_tests/node_tests/compose_state.js @@ -2,10 +2,10 @@ const {strict: assert} = require("assert"); -const {mock_module, zrequire} = require("../zjsunit/namespace"); +const {mock_esm, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -const compose_pm_pill = mock_module("compose_pm_pill"); +const compose_pm_pill = mock_esm("../../static/js/compose_pm_pill"); const compose_state = zrequire("compose_state"); diff --git a/frontend_tests/node_tests/compose_video.js b/frontend_tests/node_tests/compose_video.js index cfad094d41..d3d611670d 100644 --- a/frontend_tests/node_tests/compose_video.js +++ b/frontend_tests/node_tests/compose_video.js @@ -2,16 +2,16 @@ const {strict: assert} = require("assert"); -const {mock_module, set_global, zrequire} = require("../zjsunit/namespace"); +const {mock_esm, set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); const $ = require("../zjsunit/zjquery"); const events = require("./lib/events"); -const channel = mock_module("channel"); +const channel = mock_esm("../../static/js/channel"); const page_params = set_global("page_params", {}); -const upload = mock_module("upload"); -mock_module("resize", { +const upload = mock_esm("../../static/js/upload"); +mock_esm("../../static/js/resize", { watch_manual_resize() {}, }); set_global("csrf_token", "fake-csrf-token"); diff --git a/frontend_tests/node_tests/composebox_typeahead.js b/frontend_tests/node_tests/composebox_typeahead.js index 598d2741e2..e628c876a0 100644 --- a/frontend_tests/node_tests/composebox_typeahead.js +++ b/frontend_tests/node_tests/composebox_typeahead.js @@ -2,26 +2,26 @@ const {strict: assert} = require("assert"); -const {mock_module, set_global, zrequire} = require("../zjsunit/namespace"); +const {mock_esm, set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); const $ = require("../zjsunit/zjquery"); const noop = () => {}; -const channel = mock_module("channel"); -const compose = mock_module("compose", { +const channel = mock_esm("../../static/js/channel"); +const compose = mock_esm("../../static/js/compose", { finish: noop, }); -const message_store = mock_module("message_store", { +const message_store = mock_esm("../../static/js/message_store", { user_ids: () => [], }); -const stream_topic_history = mock_module("stream_topic_history"); +const stream_topic_history = mock_esm("../../static/js/stream_topic_history"); const page_params = set_global("page_params", {}); let autosize_called; -mock_module("compose_ui", { +mock_esm("../../static/js/compose_ui", { autosize_textarea() { autosize_called = true; }, diff --git a/frontend_tests/node_tests/copy_and_paste.js b/frontend_tests/node_tests/copy_and_paste.js index ecf517d18b..05d87115e3 100644 --- a/frontend_tests/node_tests/copy_and_paste.js +++ b/frontend_tests/node_tests/copy_and_paste.js @@ -5,7 +5,7 @@ const {strict: assert} = require("assert"); const jquery = require("jquery"); const {JSDOM} = require("jsdom"); -const {mock_module, set_global, zrequire} = require("../zjsunit/namespace"); +const {mock_esm, set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); const {window} = new JSDOM("

Hello world

"); @@ -13,7 +13,7 @@ const {window} = new JSDOM("

Hello world

"); const {DOMParser, document} = window; const $ = set_global("$", jquery(window)); -const compose_ui = mock_module("compose_ui"); +const compose_ui = mock_esm("../../static/js/compose_ui"); set_global("page_params", { development_environment: true, }); diff --git a/frontend_tests/node_tests/dispatch.js b/frontend_tests/node_tests/dispatch.js index 9d2898fb3f..9d9c1a8af9 100644 --- a/frontend_tests/node_tests/dispatch.js +++ b/frontend_tests/node_tests/dispatch.js @@ -2,7 +2,7 @@ const {strict: assert} = require("assert"); -const {mock_module, set_global, with_field, zrequire} = require("../zjsunit/namespace"); +const {mock_esm, set_global, with_field, zrequire} = require("../zjsunit/namespace"); const {make_stub} = require("../zjsunit/stub"); const {run_test} = require("../zjsunit/test"); const $ = require("../zjsunit/zjquery"); @@ -18,47 +18,47 @@ const typing_person1 = events.typing_person1; set_global("setTimeout", (func) => func()); -const activity = mock_module("activity"); -const alert_words_ui = mock_module("alert_words_ui"); -const attachments_ui = mock_module("attachments_ui"); -const bot_data = mock_module("bot_data"); -const composebox_typeahead = mock_module("composebox_typeahead"); -const emoji_picker = mock_module("emoji_picker"); -const hotspots = mock_module("hotspots"); -const markdown = mock_module("markdown"); -const message_edit = mock_module("message_edit"); -const message_events = mock_module("message_events"); -const message_list = mock_module("message_list"); -const muting_ui = mock_module("muting_ui"); -const night_mode = mock_module("night_mode"); -const notifications = mock_module("notifications"); -const reactions = mock_module("reactions"); -const realm_icon = mock_module("realm_icon"); -const realm_logo = mock_module("realm_logo"); -const reload = mock_module("reload"); -const scroll_bar = mock_module("scroll_bar"); -const settings_account = mock_module("settings_account"); -const settings_bots = mock_module("settings_bots"); -const settings_display = mock_module("settings_display"); -const settings_emoji = mock_module("settings_emoji"); -const settings_exports = mock_module("settings_exports"); -const settings_invites = mock_module("settings_invites"); -const settings_linkifiers = mock_module("settings_linkifiers"); -const settings_notifications = mock_module("settings_notifications"); -const settings_org = mock_module("settings_org"); -const settings_profile_fields = mock_module("settings_profile_fields"); -const settings_streams = mock_module("settings_streams"); -const settings_user_groups = mock_module("settings_user_groups"); -const settings_users = mock_module("settings_users"); -const stream_data = mock_module("stream_data"); -const stream_events = mock_module("stream_events"); -const submessage = mock_module("submessage"); -const typing_events = mock_module("typing_events"); -const ui = mock_module("ui"); -const unread_ops = mock_module("unread_ops"); -const user_events = mock_module("user_events"); -const user_groups = mock_module("user_groups"); -mock_module("compose"); +const activity = mock_esm("../../static/js/activity"); +const alert_words_ui = mock_esm("../../static/js/alert_words_ui"); +const attachments_ui = mock_esm("../../static/js/attachments_ui"); +const bot_data = mock_esm("../../static/js/bot_data"); +const composebox_typeahead = mock_esm("../../static/js/composebox_typeahead"); +const emoji_picker = mock_esm("../../static/js/emoji_picker"); +const hotspots = mock_esm("../../static/js/hotspots"); +const markdown = mock_esm("../../static/js/markdown"); +const message_edit = mock_esm("../../static/js/message_edit"); +const message_events = mock_esm("../../static/js/message_events"); +const message_list = mock_esm("../../static/js/message_list"); +const muting_ui = mock_esm("../../static/js/muting_ui"); +const night_mode = mock_esm("../../static/js/night_mode"); +const notifications = mock_esm("../../static/js/notifications"); +const reactions = mock_esm("../../static/js/reactions"); +const realm_icon = mock_esm("../../static/js/realm_icon"); +const realm_logo = mock_esm("../../static/js/realm_logo"); +const reload = mock_esm("../../static/js/reload"); +const scroll_bar = mock_esm("../../static/js/scroll_bar"); +const settings_account = mock_esm("../../static/js/settings_account"); +const settings_bots = mock_esm("../../static/js/settings_bots"); +const settings_display = mock_esm("../../static/js/settings_display"); +const settings_emoji = mock_esm("../../static/js/settings_emoji"); +const settings_exports = mock_esm("../../static/js/settings_exports"); +const settings_invites = mock_esm("../../static/js/settings_invites"); +const settings_linkifiers = mock_esm("../../static/js/settings_linkifiers"); +const settings_notifications = mock_esm("../../static/js/settings_notifications"); +const settings_org = mock_esm("../../static/js/settings_org"); +const settings_profile_fields = mock_esm("../../static/js/settings_profile_fields"); +const settings_streams = mock_esm("../../static/js/settings_streams"); +const settings_user_groups = mock_esm("../../static/js/settings_user_groups"); +const settings_users = mock_esm("../../static/js/settings_users"); +const stream_data = mock_esm("../../static/js/stream_data"); +const stream_events = mock_esm("../../static/js/stream_events"); +const submessage = mock_esm("../../static/js/submessage"); +const typing_events = mock_esm("../../static/js/typing_events"); +const ui = mock_esm("../../static/js/ui"); +const unread_ops = mock_esm("../../static/js/unread_ops"); +const user_events = mock_esm("../../static/js/user_events"); +const user_groups = mock_esm("../../static/js/user_groups"); +mock_esm("../../static/js/compose"); const electron_bridge = set_global("electron_bridge", {}); diff --git a/frontend_tests/node_tests/dispatch_subs.js b/frontend_tests/node_tests/dispatch_subs.js index 93aebeee2e..efb29aa024 100644 --- a/frontend_tests/node_tests/dispatch_subs.js +++ b/frontend_tests/node_tests/dispatch_subs.js @@ -2,7 +2,7 @@ const {strict: assert} = require("assert"); -const {mock_module, set_global, zrequire} = require("../zjsunit/namespace"); +const {mock_esm, set_global, zrequire} = require("../zjsunit/namespace"); const {make_stub} = require("../zjsunit/stub"); const {run_test} = require("../zjsunit/test"); @@ -11,15 +11,15 @@ const events = require("./lib/events"); const event_fixtures = events.fixtures; const test_user = events.test_user; -const compose_fade = mock_module("compose_fade"); -const narrow_state = mock_module("narrow_state"); -const overlays = mock_module("overlays"); +const compose_fade = mock_esm("../../static/js/compose_fade"); +const narrow_state = mock_esm("../../static/js/narrow_state"); +const overlays = mock_esm("../../static/js/overlays"); const page_params = set_global("page_params", {}); -const settings_org = mock_module("settings_org"); -const settings_streams = mock_module("settings_streams"); -const stream_events = mock_module("stream_events"); -const stream_list = mock_module("stream_list"); -const subs = mock_module("subs"); +const settings_org = mock_esm("../../static/js/settings_org"); +const settings_streams = mock_esm("../../static/js/settings_streams"); +const stream_events = mock_esm("../../static/js/stream_events"); +const stream_list = mock_esm("../../static/js/stream_list"); +const subs = mock_esm("../../static/js/subs"); set_global("current_msg_list", {}); const peer_data = zrequire("peer_data"); diff --git a/frontend_tests/node_tests/drafts.js b/frontend_tests/node_tests/drafts.js index 14fd17ff62..f91fca93c6 100644 --- a/frontend_tests/node_tests/drafts.js +++ b/frontend_tests/node_tests/drafts.js @@ -3,7 +3,7 @@ const {strict: assert} = require("assert"); const {stub_templates} = require("../zjsunit/handlebars"); -const {mock_module, set_global, zrequire, with_overrides} = require("../zjsunit/namespace"); +const {mock_esm, set_global, zrequire, with_overrides} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); const $ = require("../zjsunit/zjquery"); @@ -24,11 +24,11 @@ const localStorage = set_global("localStorage", { ls_container.clear(); }, }); -const compose_state = mock_module("compose_state"); -mock_module("markdown", { +const compose_state = mock_esm("../../static/js/compose_state"); +mock_esm("../../static/js/markdown", { apply_markdown: noop, }); -mock_module("stream_data", { +mock_esm("../../static/js/stream_data", { get_color() { return "#FFFFFF"; }, diff --git a/frontend_tests/node_tests/dropdown_list_widget.js b/frontend_tests/node_tests/dropdown_list_widget.js index 63767ffcfa..3c42e4264f 100644 --- a/frontend_tests/node_tests/dropdown_list_widget.js +++ b/frontend_tests/node_tests/dropdown_list_widget.js @@ -2,12 +2,12 @@ const {strict: assert} = require("assert"); -const {mock_module, zrequire} = require("../zjsunit/namespace"); +const {mock_esm, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); const $ = require("../zjsunit/zjquery"); const noop = () => {}; -mock_module("list_widget", { +mock_esm("../../static/js/list_widget", { create: () => ({init: noop}), }); const {DropdownListWidget: dropdown_list_widget} = zrequire("dropdown_list_widget"); diff --git a/frontend_tests/node_tests/echo.js b/frontend_tests/node_tests/echo.js index 7eafd76e7a..ff3d590ce6 100644 --- a/frontend_tests/node_tests/echo.js +++ b/frontend_tests/node_tests/echo.js @@ -4,27 +4,27 @@ const {strict: assert} = require("assert"); const MockDate = require("mockdate"); -const {mock_module, set_global, zrequire} = require("../zjsunit/namespace"); +const {mock_esm, set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -const local_message = mock_module("local_message"); -const markdown = mock_module("markdown"); +const local_message = mock_esm("../../static/js/local_message"); +const markdown = mock_esm("../../static/js/markdown"); const page_params = set_global("page_params", {}); let disparities = []; let messages_to_rerender = []; -mock_module("ui", { +mock_esm("../../static/js/ui", { show_failed_message_success: () => {}, }); -mock_module("sent_messages", { +mock_esm("../../static/js/sent_messages", { mark_disparity: (local_id) => { disparities.push(local_id); }, }); -mock_module("message_store", { +mock_esm("../../static/js/message_store", { get: () => ({failed_request: true}), update_booleans: () => {}, @@ -38,7 +38,7 @@ set_global("home_msg_list", { }, }); -mock_module("message_list"); +mock_esm("../../static/js/message_list"); set_global("current_msg_list", ""); const echo = zrequire("echo"); diff --git a/frontend_tests/node_tests/fetch_status.js b/frontend_tests/node_tests/fetch_status.js index 0fee733463..96672c0791 100644 --- a/frontend_tests/node_tests/fetch_status.js +++ b/frontend_tests/node_tests/fetch_status.js @@ -2,10 +2,10 @@ const {strict: assert} = require("assert"); -const {mock_module, zrequire} = require("../zjsunit/namespace"); +const {mock_esm, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -mock_module("message_scroll", { +mock_esm("../../static/js/message_scroll", { hide_loading_older: () => {}, show_loading_older: () => {}, diff --git a/frontend_tests/node_tests/filter.js b/frontend_tests/node_tests/filter.js index 84e42c1052..69c5093222 100644 --- a/frontend_tests/node_tests/filter.js +++ b/frontend_tests/node_tests/filter.js @@ -2,11 +2,11 @@ const {strict: assert} = require("assert"); -const {mock_module, set_global, with_field, zrequire} = require("../zjsunit/namespace"); +const {mock_esm, set_global, with_field, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); const $ = require("../zjsunit/zjquery"); -const message_store = mock_module("message_store"); +const message_store = mock_esm("../../static/js/message_store"); const page_params = set_global("page_params", {}); const stream_data = zrequire("stream_data"); diff --git a/frontend_tests/node_tests/hash_util.js b/frontend_tests/node_tests/hash_util.js index c17936e195..1276e550bf 100644 --- a/frontend_tests/node_tests/hash_util.js +++ b/frontend_tests/node_tests/hash_util.js @@ -2,10 +2,10 @@ const {strict: assert} = require("assert"); -const {mock_module, set_global, zrequire} = require("../zjsunit/namespace"); +const {mock_esm, set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -const ui_report = mock_module("ui_report", { +const ui_report = mock_esm("../../static/js/ui_report", { displayed_error: false, error: () => { diff --git a/frontend_tests/node_tests/hashchange.js b/frontend_tests/node_tests/hashchange.js index 13f4e18050..eef6524a92 100644 --- a/frontend_tests/node_tests/hashchange.js +++ b/frontend_tests/node_tests/hashchange.js @@ -2,7 +2,7 @@ const {strict: assert} = require("assert"); -const {mock_module, set_global, zrequire} = require("../zjsunit/namespace"); +const {mock_esm, set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); const $ = require("../zjsunit/zjquery"); @@ -13,23 +13,23 @@ set_global("location", { }); set_global("to_$", () => window_stub); -mock_module("search", { +mock_esm("../../static/js/search", { update_button_visibility: () => {}, }); set_global("document", "document-stub"); const history = set_global("history", {}); -const admin = mock_module("admin"); -const drafts = mock_module("drafts"); -const floating_recipient_bar = mock_module("floating_recipient_bar"); -const info_overlay = mock_module("info_overlay"); -const message_viewport = mock_module("message_viewport"); -const narrow = mock_module("narrow"); -const overlays = mock_module("overlays"); -const settings = mock_module("settings"); -const subs = mock_module("subs"); -const ui_util = mock_module("ui_util"); -mock_module("top_left_corner", { +const admin = mock_esm("../../static/js/admin"); +const drafts = mock_esm("../../static/js/drafts"); +const floating_recipient_bar = mock_esm("../../static/js/floating_recipient_bar"); +const info_overlay = mock_esm("../../static/js/info_overlay"); +const message_viewport = mock_esm("../../static/js/message_viewport"); +const narrow = mock_esm("../../static/js/narrow"); +const overlays = mock_esm("../../static/js/overlays"); +const settings = mock_esm("../../static/js/settings"); +const subs = mock_esm("../../static/js/subs"); +const ui_util = mock_esm("../../static/js/ui_util"); +mock_esm("../../static/js/top_left_corner", { handle_narrow_deactivated: () => {}, }); set_global("favicon", {}); diff --git a/frontend_tests/node_tests/hotkey.js b/frontend_tests/node_tests/hotkey.js index bcacc96b74..0cd2535b4c 100644 --- a/frontend_tests/node_tests/hotkey.js +++ b/frontend_tests/node_tests/hotkey.js @@ -3,7 +3,7 @@ const {strict: assert} = require("assert"); const { - mock_module, + mock_esm, set_global, with_field, with_overrides, @@ -39,25 +39,25 @@ const page_params = set_global("page_params", {}); // jQuery stuff should go away if we make an initialize() method. set_global("document", "document-stub"); -const compose_actions = mock_module("compose_actions"); -const condense = mock_module("condense"); -const drafts = mock_module("drafts"); -const emoji_picker = mock_module("emoji_picker", { +const compose_actions = mock_esm("../../static/js/compose_actions"); +const condense = mock_esm("../../static/js/condense"); +const drafts = mock_esm("../../static/js/drafts"); +const emoji_picker = mock_esm("../../static/js/emoji_picker", { reactions_popped: () => false, }); -const gear_menu = mock_module("gear_menu", { +const gear_menu = mock_esm("../../static/js/gear_menu", { is_open: () => false, }); -const hashchange = mock_module("hashchange", { +const hashchange = mock_esm("../../static/js/hashchange", { in_recent_topics_hash: () => false, }); -const lightbox = mock_module("lightbox"); -const list_util = mock_module("list_util"); -const message_edit = mock_module("message_edit"); -const muting_ui = mock_module("muting_ui"); -const narrow = mock_module("narrow"); -const navigate = mock_module("navigate"); -const overlays = mock_module("overlays", { +const lightbox = mock_esm("../../static/js/lightbox"); +const list_util = mock_esm("../../static/js/list_util"); +const message_edit = mock_esm("../../static/js/message_edit"); +const muting_ui = mock_esm("../../static/js/muting_ui"); +const narrow = mock_esm("../../static/js/narrow"); +const navigate = mock_esm("../../static/js/navigate"); +const overlays = mock_esm("../../static/js/overlays", { is_active: () => false, settings_open: () => false, streams_open: () => false, @@ -65,29 +65,29 @@ const overlays = mock_module("overlays", { drafts_open: () => false, info_overlay_open: () => false, }); -const popovers = mock_module("popovers", { +const popovers = mock_esm("../../static/js/popovers", { actions_popped: () => false, message_info_popped: () => false, user_sidebar_popped: () => false, user_info_popped: () => false, }); -const reactions = mock_module("reactions"); -const search = mock_module("search"); -const stream_list = mock_module("stream_list"); -const subs = mock_module("subs"); +const reactions = mock_esm("../../static/js/reactions"); +const search = mock_esm("../../static/js/search"); +const stream_list = mock_esm("../../static/js/stream_list"); +const subs = mock_esm("../../static/js/subs"); -mock_module("stream_popover", { +mock_esm("../../static/js/stream_popover", { stream_popped: () => false, topic_popped: () => false, all_messages_popped: () => false, starred_messages_popped: () => false, }); -mock_module("hotspots", { +mock_esm("../../static/js/hotspots", { is_open: () => false, }); -mock_module("recent_topics", { +mock_esm("../../static/js/recent_topics", { is_visible: () => false, }); diff --git a/frontend_tests/node_tests/input_pill.js b/frontend_tests/node_tests/input_pill.js index 0e03ec5484..ebe20ec5e0 100644 --- a/frontend_tests/node_tests/input_pill.js +++ b/frontend_tests/node_tests/input_pill.js @@ -2,7 +2,7 @@ const {strict: assert} = require("assert"); -const {mock_module, set_global, zrequire} = require("../zjsunit/namespace"); +const {mock_esm, set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); const $ = require("../zjsunit/zjquery"); @@ -11,7 +11,7 @@ set_global("document", {}); const noop = () => {}; const example_img_link = "http://example.com/example.png"; -mock_module("ui_util", { +mock_esm("../../static/js/ui_util", { place_caret_at_end: noop, }); diff --git a/frontend_tests/node_tests/lightbox.js b/frontend_tests/node_tests/lightbox.js index b5abd594eb..d3440300a3 100644 --- a/frontend_tests/node_tests/lightbox.js +++ b/frontend_tests/node_tests/lightbox.js @@ -2,22 +2,22 @@ const {strict: assert} = require("assert"); -const {mock_module, set_global, zrequire} = require("../zjsunit/namespace"); +const {mock_esm, set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); const $ = require("../zjsunit/zjquery"); set_global("Image", class Image {}); -mock_module("overlays", { +mock_esm("../../static/js/overlays", { close_overlay: () => {}, close_active: () => {}, open_overlay: () => {}, }); -mock_module("popovers", { +mock_esm("../../static/js/popovers", { hide_all: () => {}, }); -const message_store = mock_module("message_store"); +const message_store = mock_esm("../../static/js/message_store"); const rows = zrequire("rows"); const lightbox = zrequire("lightbox"); diff --git a/frontend_tests/node_tests/list_widget.js b/frontend_tests/node_tests/list_widget.js index f4105043a0..4a3f40eeb7 100644 --- a/frontend_tests/node_tests/list_widget.js +++ b/frontend_tests/node_tests/list_widget.js @@ -2,14 +2,14 @@ const {strict: assert} = require("assert"); -const {mock_module, set_global, zrequire} = require("../zjsunit/namespace"); +const {mock_esm, set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); // We need these stubs to get by instanceof checks. // The ListWidget library allows you to insert objects // that are either jQuery, Element, or just raw HTML // strings. We initially test with raw strings. -const ui = mock_module("ui"); +const ui = mock_esm("../../static/js/ui"); set_global("Element", () => {}); set_global("jQuery", "stub"); diff --git a/frontend_tests/node_tests/message_events.js b/frontend_tests/node_tests/message_events.js index 5e1dbf2e32..6723222b5e 100644 --- a/frontend_tests/node_tests/message_events.js +++ b/frontend_tests/node_tests/message_events.js @@ -2,17 +2,17 @@ const {strict: assert} = require("assert"); -const {mock_module, set_global, zrequire} = require("../zjsunit/namespace"); +const {mock_esm, set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -const condense = mock_module("condense"); -const message_edit = mock_module("message_edit"); -const message_list = mock_module("message_list"); -const notifications = mock_module("notifications"); +const condense = mock_esm("../../static/js/condense"); +const message_edit = mock_esm("../../static/js/message_edit"); +const message_list = mock_esm("../../static/js/message_list"); +const notifications = mock_esm("../../static/js/notifications"); const page_params = set_global("page_params", {}); -const pm_list = mock_module("pm_list"); -const stream_list = mock_module("stream_list"); -const unread_ui = mock_module("unread_ui"); +const pm_list = mock_esm("../../static/js/pm_list"); +const stream_list = mock_esm("../../static/js/stream_list"); +const unread_ui = mock_esm("../../static/js/unread_ui"); set_global("current_msg_list", {}); const people = zrequire("people"); diff --git a/frontend_tests/node_tests/message_fetch.js b/frontend_tests/node_tests/message_fetch.js index 0286a35db8..5c63114392 100644 --- a/frontend_tests/node_tests/message_fetch.js +++ b/frontend_tests/node_tests/message_fetch.js @@ -4,7 +4,7 @@ const {strict: assert} = require("assert"); const _ = require("lodash"); -const {mock_module, set_global, zrequire} = require("../zjsunit/namespace"); +const {mock_esm, set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); const $ = require("../zjsunit/zjquery"); @@ -15,28 +15,28 @@ const noop = () => {}; function MessageListView() { return {}; } -mock_module("message_list_view", { +mock_esm("../../static/js/message_list_view", { MessageListView, }); -mock_module("recent_topics", { +mock_esm("../../static/js/recent_topics", { process_messages: noop, }); // Still required for page_params.initial_pointer set_global("page_params", {}); -mock_module("ui_report", { +mock_esm("../../static/js/ui_report", { hide_error: noop, }); -const channel = mock_module("channel"); -const message_store = mock_module("message_store"); -const message_util = mock_module("message_util"); -const pm_list = mock_module("pm_list"); -const server_events = mock_module("server_events"); -const stream_list = mock_module("stream_list", { +const channel = mock_esm("../../static/js/channel"); +const message_store = mock_esm("../../static/js/message_store"); +const message_util = mock_esm("../../static/js/message_util"); +const pm_list = mock_esm("../../static/js/pm_list"); +const server_events = mock_esm("../../static/js/server_events"); +const stream_list = mock_esm("../../static/js/stream_list", { maybe_scroll_narrow_into_view: () => {}, }); -mock_module("message_scroll", { +mock_esm("../../static/js/message_scroll", { show_loading_older: noop, hide_loading_older: noop, show_loading_newer: noop, diff --git a/frontend_tests/node_tests/message_flags.js b/frontend_tests/node_tests/message_flags.js index 6381b88e41..c663566b61 100644 --- a/frontend_tests/node_tests/message_flags.js +++ b/frontend_tests/node_tests/message_flags.js @@ -2,13 +2,13 @@ const {strict: assert} = require("assert"); -const {mock_module, set_global, with_field, zrequire} = require("../zjsunit/namespace"); +const {mock_esm, set_global, with_field, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -const channel = mock_module("channel"); -const ui = mock_module("ui"); +const channel = mock_esm("../../static/js/channel"); +const ui = mock_esm("../../static/js/ui"); -mock_module("starred_messages", { +mock_esm("../../static/js/starred_messages", { add: () => {}, remove: () => {}, diff --git a/frontend_tests/node_tests/message_list.js b/frontend_tests/node_tests/message_list.js index f8868d5505..799c05214a 100644 --- a/frontend_tests/node_tests/message_list.js +++ b/frontend_tests/node_tests/message_list.js @@ -2,7 +2,7 @@ const {strict: assert} = require("assert"); -const {mock_module, set_global, zrequire} = require("../zjsunit/namespace"); +const {mock_esm, set_global, zrequire} = require("../zjsunit/namespace"); const {make_stub} = require("../zjsunit/stub"); const {run_test} = require("../zjsunit/test"); const $ = require("../zjsunit/zjquery"); @@ -13,7 +13,7 @@ const $ = require("../zjsunit/zjquery"); const noop = function () {}; -mock_module("filter", { +mock_esm("../../static/js/filter", { Filter: noop, }); set_global("document", { @@ -24,8 +24,8 @@ set_global("document", { }, }); -const narrow_state = mock_module("narrow_state"); -const stream_data = mock_module("stream_data"); +const narrow_state = mock_esm("../../static/js/narrow_state"); +const stream_data = mock_esm("../../static/js/stream_data"); const muting = zrequire("muting"); const {MessageList} = zrequire("message_list"); diff --git a/frontend_tests/node_tests/message_list_view.js b/frontend_tests/node_tests/message_list_view.js index 9031ed9f03..898051b689 100644 --- a/frontend_tests/node_tests/message_list_view.js +++ b/frontend_tests/node_tests/message_list_view.js @@ -4,7 +4,7 @@ const {strict: assert} = require("assert"); const _ = require("lodash"); -const {mock_module, set_global, zrequire} = require("../zjsunit/namespace"); +const {mock_esm, set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); set_global("document", "document-stub"); @@ -16,7 +16,7 @@ const page_params = set_global("page_params", { }); set_global("home_msg_list", "stub"); // timerender calls setInterval when imported -mock_module("timerender", { +mock_esm("../../static/js/timerender", { render_date(time1, time2) { if (time2 === undefined) { return [{outerHTML: String(time1.getTime())}]; @@ -31,7 +31,7 @@ mock_module("timerender", { }, }); -mock_module("rows", { +mock_esm("../../static/js/rows", { get_table() { return { children() { diff --git a/frontend_tests/node_tests/message_store.js b/frontend_tests/node_tests/message_store.js index 288a09ba3a..7a9e5cee33 100644 --- a/frontend_tests/node_tests/message_store.js +++ b/frontend_tests/node_tests/message_store.js @@ -2,17 +2,17 @@ const {strict: assert} = require("assert"); -const {mock_module, set_global, with_field, zrequire} = require("../zjsunit/namespace"); +const {mock_esm, set_global, with_field, zrequire} = require("../zjsunit/namespace"); const {make_stub} = require("../zjsunit/stub"); const {run_test} = require("../zjsunit/test"); const noop = () => {}; -mock_module("stream_topic_history", { +mock_esm("../../static/js/stream_topic_history", { add_message: noop, }); -mock_module("recent_senders", { +mock_esm("../../static/js/recent_senders", { process_message_for_senders: noop, }); diff --git a/frontend_tests/node_tests/narrow.js b/frontend_tests/node_tests/narrow.js index 9fa57b8ede..4c0136ab29 100644 --- a/frontend_tests/node_tests/narrow.js +++ b/frontend_tests/node_tests/narrow.js @@ -2,7 +2,7 @@ const {strict: assert} = require("assert"); -const {mock_module, set_global, with_field, zrequire} = require("../zjsunit/namespace"); +const {mock_esm, set_global, with_field, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); const $ = require("../zjsunit/zjquery"); @@ -10,7 +10,7 @@ set_global("page_params", { stop_words: ["what", "about"], }); -const stream_topic_history = mock_module("stream_topic_history"); +const stream_topic_history = mock_esm("../../static/js/stream_topic_history"); const hash_util = zrequire("hash_util"); const compose_state = zrequire("compose_state"); diff --git a/frontend_tests/node_tests/narrow_activate.js b/frontend_tests/node_tests/narrow_activate.js index 3a309a9975..3830fe367d 100644 --- a/frontend_tests/node_tests/narrow_activate.js +++ b/frontend_tests/node_tests/narrow_activate.js @@ -2,33 +2,33 @@ const {strict: assert} = require("assert"); -const {mock_module, set_global, zrequire} = require("../zjsunit/namespace"); +const {mock_esm, set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -mock_module("resize", { +mock_esm("../../static/js/resize", { resize_stream_filters_container: () => {}, }); -const channel = mock_module("channel"); -const compose = mock_module("compose"); -const compose_actions = mock_module("compose_actions"); -const hashchange = mock_module("hashchange"); -const message_fetch = mock_module("message_fetch"); -const message_list = mock_module("message_list", { +const channel = mock_esm("../../static/js/channel"); +const compose = mock_esm("../../static/js/compose"); +const compose_actions = mock_esm("../../static/js/compose_actions"); +const hashchange = mock_esm("../../static/js/hashchange"); +const message_fetch = mock_esm("../../static/js/message_fetch"); +const message_list = mock_esm("../../static/js/message_list", { set_narrowed(value) { message_list.narrowed = value; }, }); -const message_scroll = mock_module("message_scroll"); -const message_view_header = mock_module("message_view_header"); -const notifications = mock_module("notifications"); -const search = mock_module("search"); -const stream_list = mock_module("stream_list"); -const top_left_corner = mock_module("top_left_corner"); -const typing_events = mock_module("typing_events"); -const ui_util = mock_module("ui_util"); -const unread_ops = mock_module("unread_ops"); -mock_module("recent_topics", { +const message_scroll = mock_esm("../../static/js/message_scroll"); +const message_view_header = mock_esm("../../static/js/message_view_header"); +const notifications = mock_esm("../../static/js/notifications"); +const search = mock_esm("../../static/js/search"); +const stream_list = mock_esm("../../static/js/stream_list"); +const top_left_corner = mock_esm("../../static/js/top_left_corner"); +const typing_events = mock_esm("../../static/js/typing_events"); +const ui_util = mock_esm("../../static/js/ui_util"); +const unread_ops = mock_esm("../../static/js/unread_ops"); +mock_esm("../../static/js/recent_topics", { hide: () => {}, is_visible: () => {}, }); @@ -44,7 +44,7 @@ set_global("setTimeout", (f, t) => { f(); }); -mock_module("muting", { +mock_esm("../../static/js/muting", { is_topic_muted: () => false, }); diff --git a/frontend_tests/node_tests/narrow_local.js b/frontend_tests/node_tests/narrow_local.js index 0ce0cefa84..9b17f72258 100644 --- a/frontend_tests/node_tests/narrow_local.js +++ b/frontend_tests/node_tests/narrow_local.js @@ -2,10 +2,10 @@ const {strict: assert} = require("assert"); -const {mock_module, zrequire} = require("../zjsunit/namespace"); +const {mock_esm, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -const message_list = mock_module("message_list"); +const message_list = mock_esm("../../static/js/message_list"); const {Filter} = zrequire("../js/filter"); const {MessageListData} = zrequire("../js/message_list_data"); diff --git a/frontend_tests/node_tests/narrow_unread.js b/frontend_tests/node_tests/narrow_unread.js index 79164a1078..461813a776 100644 --- a/frontend_tests/node_tests/narrow_unread.js +++ b/frontend_tests/node_tests/narrow_unread.js @@ -2,11 +2,11 @@ const {strict: assert} = require("assert"); -const {mock_module, set_global, zrequire} = require("../zjsunit/namespace"); +const {mock_esm, set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -const message_store = mock_module("message_store"); -mock_module("muting", { +const message_store = mock_esm("../../static/js/message_store"); +mock_esm("../../static/js/muting", { is_topic_muted: () => false, }); set_global("page_params", {}); diff --git a/frontend_tests/node_tests/people.js b/frontend_tests/node_tests/people.js index cc1b28d32f..25dd2dcafe 100644 --- a/frontend_tests/node_tests/people.js +++ b/frontend_tests/node_tests/people.js @@ -6,10 +6,10 @@ const {parseISO} = require("date-fns"); const _ = require("lodash"); const MockDate = require("mockdate"); -const {mock_module, set_global, zrequire} = require("../zjsunit/namespace"); +const {mock_esm, set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -const message_store = mock_module("message_store"); +const message_store = mock_esm("../../static/js/message_store"); const page_params = set_global("page_params", {}); const people = zrequire("people"); diff --git a/frontend_tests/node_tests/people_errors.js b/frontend_tests/node_tests/people_errors.js index a4fa6af77f..1c243ce64a 100644 --- a/frontend_tests/node_tests/people_errors.js +++ b/frontend_tests/node_tests/people_errors.js @@ -2,10 +2,10 @@ const {strict: assert} = require("assert"); -const {mock_module, zrequire} = require("../zjsunit/namespace"); +const {mock_esm, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -const reload_state = mock_module("reload_state", { +const reload_state = mock_esm("../../static/js/reload_state", { is_in_progress: () => false, }); diff --git a/frontend_tests/node_tests/pm_list.js b/frontend_tests/node_tests/pm_list.js index 3517d47eba..8c6f89ce5b 100644 --- a/frontend_tests/node_tests/pm_list.js +++ b/frontend_tests/node_tests/pm_list.js @@ -2,22 +2,22 @@ const {strict: assert} = require("assert"); -const {mock_module, with_field, zrequire} = require("../zjsunit/namespace"); +const {mock_esm, with_field, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); const $ = require("../zjsunit/zjquery"); -const narrow_state = mock_module("narrow_state"); -const pm_list_dom = mock_module("pm_list_dom"); -const unread = mock_module("unread"); -const unread_ui = mock_module("unread_ui"); -const vdom = mock_module("vdom", { +const narrow_state = mock_esm("../../static/js/narrow_state"); +const pm_list_dom = mock_esm("../../static/js/pm_list_dom"); +const unread = mock_esm("../../static/js/unread"); +const unread_ui = mock_esm("../../static/js/unread_ui"); +const vdom = mock_esm("../../static/js/vdom", { render: () => "fake-dom-for-pm-list", }); -mock_module("stream_popover", { +mock_esm("../../static/js/stream_popover", { hide_topic_popover() {}, }); -mock_module("ui", { +mock_esm("../../static/js/ui", { get_content_element: (element) => element, }); diff --git a/frontend_tests/node_tests/popovers.js b/frontend_tests/node_tests/popovers.js index 5b9a709569..479f47d59a 100644 --- a/frontend_tests/node_tests/popovers.js +++ b/frontend_tests/node_tests/popovers.js @@ -3,21 +3,21 @@ const {strict: assert} = require("assert"); const {stub_templates} = require("../zjsunit/handlebars"); -const {mock_module, set_global, with_field, zrequire} = require("../zjsunit/namespace"); +const {mock_esm, set_global, with_field, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); const $ = require("../zjsunit/zjquery"); const noop = function () {}; -const rows = mock_module("rows"); -const stream_data = mock_module("stream_data"); -mock_module("emoji_picker", { +const rows = mock_esm("../../static/js/rows"); +const stream_data = mock_esm("../../static/js/stream_data"); +mock_esm("../../static/js/emoji_picker", { hide_emoji_popover: noop, }); -mock_module("message_viewport", { +mock_esm("../../static/js/message_viewport", { height: () => 500, }); -mock_module("stream_popover", { +mock_esm("../../static/js/stream_popover", { hide_stream_popover: noop, hide_topic_popover: noop, hide_all_messages_popover: noop, diff --git a/frontend_tests/node_tests/presence.js b/frontend_tests/node_tests/presence.js index 289a6f166c..a22aac02ec 100644 --- a/frontend_tests/node_tests/presence.js +++ b/frontend_tests/node_tests/presence.js @@ -2,13 +2,13 @@ const {strict: assert} = require("assert"); -const {mock_module, zrequire} = require("../zjsunit/namespace"); +const {mock_esm, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -const reload_state = mock_module("reload_state", { +const reload_state = mock_esm("../../static/js/reload_state", { is_in_progress: () => false, }); -const server_events = mock_module("server_events"); +const server_events = mock_esm("../../static/js/server_events"); const people = zrequire("people"); const presence = zrequire("presence"); diff --git a/frontend_tests/node_tests/reactions.js b/frontend_tests/node_tests/reactions.js index 937487e3ed..98e22f43eb 100644 --- a/frontend_tests/node_tests/reactions.js +++ b/frontend_tests/node_tests/reactions.js @@ -3,7 +3,7 @@ const {strict: assert} = require("assert"); const {stub_templates} = require("../zjsunit/handlebars"); -const {mock_module, set_global, zrequire} = require("../zjsunit/namespace"); +const {mock_esm, set_global, zrequire} = require("../zjsunit/namespace"); const {make_stub} = require("../zjsunit/stub"); const {run_test} = require("../zjsunit/test"); const $ = require("../zjsunit/zjquery"); @@ -37,11 +37,11 @@ const sample_message = { ], }; -const channel = mock_module("channel"); -const emoji_picker = mock_module("emoji_picker", { +const channel = mock_esm("../../static/js/channel"); +const emoji_picker = mock_esm("../../static/js/emoji_picker", { hide_emoji_popover() {}, }); -const message_store = mock_module("message_store"); +const message_store = mock_esm("../../static/js/message_store"); set_global("current_msg_list", { selected_message() { diff --git a/frontend_tests/node_tests/recent_senders.js b/frontend_tests/node_tests/recent_senders.js index 80bd91a01b..b65b305285 100644 --- a/frontend_tests/node_tests/recent_senders.js +++ b/frontend_tests/node_tests/recent_senders.js @@ -2,7 +2,7 @@ const {strict: assert} = require("assert"); -const {mock_module, zrequire} = require("../zjsunit/namespace"); +const {mock_esm, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); let next_id = 0; @@ -23,14 +23,14 @@ function make_stream_message({stream_id, topic, sender_id}) { return message; } -const message_list = mock_module("message_list", { +const message_list = mock_esm("../../static/js/message_list", { all: { all_messages() { return Array.from(messages.values()); }, }, }); -mock_module("message_store", { +mock_esm("../../static/js/message_store", { get: (message_id) => messages.get(message_id), }); diff --git a/frontend_tests/node_tests/recent_topics.js b/frontend_tests/node_tests/recent_topics.js index 73f5853f05..c0f9632093 100644 --- a/frontend_tests/node_tests/recent_topics.js +++ b/frontend_tests/node_tests/recent_topics.js @@ -3,7 +3,7 @@ const {strict: assert} = require("assert"); const {stub_templates} = require("../zjsunit/handlebars"); -const {mock_module, set_global, zrequire} = require("../zjsunit/namespace"); +const {mock_esm, set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); const $ = require("../zjsunit/zjquery"); @@ -36,14 +36,14 @@ const topic8 = "topic-8"; const topic9 = "topic-9"; const topic10 = "topic-10"; -const message_list = mock_module("message_list", { +const message_list = mock_esm("../../static/js/message_list", { all: { all_messages() { return messages; }, }, }); -const ListWidget = mock_module("list_widget", { +const ListWidget = mock_esm("../../static/js/list_widget", { modifier: noop, create: (container, mapped_topic_values, opts) => { @@ -70,27 +70,27 @@ const ListWidget = mock_module("list_widget", { render_item: (item) => ListWidget.modifier(item), }); -mock_module("compose_actions", { +mock_esm("../../static/js/compose_actions", { cancel: noop, }); -mock_module("drafts", { +mock_esm("../../static/js/drafts", { update_draft: noop, }); -mock_module("hash_util", { +mock_esm("../../static/js/hash_util", { by_stream_uri: () => "https://www.example.com", by_stream_topic_uri: () => "https://www.example.com", }); -mock_module("narrow", { +mock_esm("../../static/js/narrow", { set_narrow_title: noop, }); -mock_module("message_store", { +mock_esm("../../static/js/message_store", { get: (msg_id) => messages[msg_id - 1], }); -mock_module("message_view_header", { +mock_esm("../../static/js/message_view_header", { render_title_area: noop, }); -mock_module("muting", { +mock_esm("../../static/js/muting", { is_topic_muted: (stream_id, topic) => { if (stream_id === stream1 && topic === topic7) { return true; @@ -98,10 +98,10 @@ mock_module("muting", { return false; }, }); -mock_module("recent_senders", { +mock_esm("../../static/js/recent_senders", { get_topic_recent_senders: () => [1, 2], }); -mock_module("stream_data", { +mock_esm("../../static/js/stream_data", { get_sub_by_id: (stream) => { if (stream === stream5) { // No data is available for deactivated streams @@ -120,10 +120,10 @@ mock_module("stream_data", { false, id_is_subscribed: () => true, }); -mock_module("stream_list", { +mock_esm("../../static/js/stream_list", { handle_narrow_deactivated: noop, }); -mock_module("timerender", { +mock_esm("../../static/js/timerender", { last_seen_status_from_date: () => "Just now", get_full_datetime: () => ({ @@ -131,10 +131,10 @@ mock_module("timerender", { time: "time", }), }); -mock_module("top_left_corner", { +mock_esm("../../static/js/top_left_corner", { narrow_to_recent_topics: noop, }); -mock_module("unread", { +mock_esm("../../static/js/unread", { num_unread_for_topic: (stream_id, topic) => { if (stream_id === 1 && topic === "topic-1") { // Only stream1, topic-1 is read. diff --git a/frontend_tests/node_tests/rendered_markdown.js b/frontend_tests/node_tests/rendered_markdown.js index 771a7430a8..2f95e357e9 100644 --- a/frontend_tests/node_tests/rendered_markdown.js +++ b/frontend_tests/node_tests/rendered_markdown.js @@ -2,11 +2,11 @@ const {strict: assert} = require("assert"); -const {mock_module, set_global, with_field, zrequire} = require("../zjsunit/namespace"); +const {mock_esm, set_global, with_field, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); const $ = require("../zjsunit/zjquery"); -mock_module("rtl", { +mock_esm("../../static/js/rtl", { get_direction: () => "ltr", }); const page_params = set_global("page_params", {emojiset: "apple"}); diff --git a/frontend_tests/node_tests/scroll_util.js b/frontend_tests/node_tests/scroll_util.js index 691fbaf297..3b8b783476 100644 --- a/frontend_tests/node_tests/scroll_util.js +++ b/frontend_tests/node_tests/scroll_util.js @@ -2,10 +2,10 @@ const {strict: assert} = require("assert"); -const {mock_module, zrequire} = require("../zjsunit/namespace"); +const {mock_esm, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -mock_module("ui", { +mock_esm("../../static/js/ui", { get_scroll_element: (element) => element, }); diff --git a/frontend_tests/node_tests/search.js b/frontend_tests/node_tests/search.js index 3422409f9d..22c9d596bc 100644 --- a/frontend_tests/node_tests/search.js +++ b/frontend_tests/node_tests/search.js @@ -2,24 +2,24 @@ const {strict: assert} = require("assert"); -const {mock_module, set_global, zrequire} = require("../zjsunit/namespace"); +const {mock_esm, set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); const $ = require("../zjsunit/zjquery"); const noop = () => {}; -const narrow = mock_module("narrow"); -const narrow_state = mock_module("narrow_state", { +const narrow = mock_esm("../../static/js/narrow"); +const narrow_state = mock_esm("../../static/js/narrow_state", { filter: () => false, }); -const search_suggestion = mock_module("search_suggestion"); +const search_suggestion = mock_esm("../../static/js/search_suggestion"); -mock_module("search_pill_widget", { +mock_esm("../../static/js/search_pill_widget", { widget: { getByID: () => true, }, }); -mock_module("ui_util", { +mock_esm("../../static/js/ui_util", { change_tab_to: noop, place_caret_at_end: noop, }); diff --git a/frontend_tests/node_tests/search_legacy.js b/frontend_tests/node_tests/search_legacy.js index 8b0beb8d25..9ac256985e 100644 --- a/frontend_tests/node_tests/search_legacy.js +++ b/frontend_tests/node_tests/search_legacy.js @@ -2,7 +2,7 @@ const {strict: assert} = require("assert"); -const {mock_module, set_global, zrequire} = require("../zjsunit/namespace"); +const {mock_esm, set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); const $ = require("../zjsunit/zjquery"); @@ -12,16 +12,16 @@ set_global("page_params", { const noop = () => {}; -const narrow = mock_module("narrow"); -const narrow_state = mock_module("narrow_state"); -const search_suggestion = mock_module("search_suggestion"); -mock_module("ui_util", { +const narrow = mock_esm("../../static/js/narrow"); +const narrow_state = mock_esm("../../static/js/narrow_state"); +const search_suggestion = mock_esm("../../static/js/search_suggestion"); +mock_esm("../../static/js/ui_util", { change_tab_to: noop, }); const Filter = {}; -mock_module("filter", { +mock_esm("../../static/js/filter", { Filter, }); diff --git a/frontend_tests/node_tests/search_suggestion.js b/frontend_tests/node_tests/search_suggestion.js index 23d1b715cd..364eb74cfd 100644 --- a/frontend_tests/node_tests/search_suggestion.js +++ b/frontend_tests/node_tests/search_suggestion.js @@ -2,14 +2,14 @@ const {strict: assert} = require("assert"); -const {mock_module, set_global, zrequire} = require("../zjsunit/namespace"); +const {mock_esm, set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); const page_params = set_global("page_params", { search_pills_enabled: true, }); -mock_module("message_store", { +mock_esm("../../static/js/message_store", { user_ids: () => [], }); diff --git a/frontend_tests/node_tests/search_suggestion_legacy.js b/frontend_tests/node_tests/search_suggestion_legacy.js index e7817773bd..da429e42bc 100644 --- a/frontend_tests/node_tests/search_suggestion_legacy.js +++ b/frontend_tests/node_tests/search_suggestion_legacy.js @@ -2,13 +2,13 @@ const {strict: assert} = require("assert"); -const {mock_module, set_global, zrequire} = require("../zjsunit/namespace"); +const {mock_esm, set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); const page_params = set_global("page_params", { search_pills_enabled: false, }); -mock_module("message_store", { +mock_esm("../../static/js/message_store", { user_ids: () => [], }); diff --git a/frontend_tests/node_tests/server_events.js b/frontend_tests/node_tests/server_events.js index 43eee07438..39272e9819 100644 --- a/frontend_tests/node_tests/server_events.js +++ b/frontend_tests/node_tests/server_events.js @@ -2,7 +2,7 @@ const {strict: assert} = require("assert"); -const {mock_module, set_global, zrequire} = require("../zjsunit/namespace"); +const {mock_esm, set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); const noop = () => {}; @@ -16,8 +16,8 @@ set_global("document", { }); set_global("addEventListener", noop); -const channel = mock_module("channel"); -mock_module("reload_state", { +const channel = mock_esm("../../static/js/channel"); +mock_esm("../../static/js/reload_state", { is_in_progress() { return false; }, @@ -33,7 +33,7 @@ set_global("page_params", {test_suite: false}); // we also directly write to pointer set_global("pointer", {}); -mock_module("ui_report", { +mock_esm("../../static/js/ui_report", { hide_error() { return false; }, @@ -42,13 +42,13 @@ mock_module("ui_report", { }, }); -mock_module("stream_events", { +mock_esm("../../static/js/stream_events", { update_property() { throw new Error("subs update error"); }, }); -const message_events = mock_module("message_events", { +const message_events = mock_esm("../../static/js/message_events", { insert_new_messages() { throw new Error("insert error"); }, diff --git a/frontend_tests/node_tests/settings_bots.js b/frontend_tests/node_tests/settings_bots.js index 20555772ba..06be275bce 100644 --- a/frontend_tests/node_tests/settings_bots.js +++ b/frontend_tests/node_tests/settings_bots.js @@ -2,7 +2,7 @@ const {strict: assert} = require("assert"); -const {mock_module, set_global, zrequire} = require("../zjsunit/namespace"); +const {mock_esm, set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); const $ = require("../zjsunit/zjquery"); @@ -27,7 +27,7 @@ const bot_data_params = { ], }; -const avatar = mock_module("avatar"); +const avatar = mock_esm("../../static/js/avatar"); function ClipboardJS(sel) { assert.equal(sel, "#copy_zuliprc"); } diff --git a/frontend_tests/node_tests/settings_emoji.js b/frontend_tests/node_tests/settings_emoji.js index ce30a09d6f..428b0c1a55 100644 --- a/frontend_tests/node_tests/settings_emoji.js +++ b/frontend_tests/node_tests/settings_emoji.js @@ -2,11 +2,11 @@ const {strict: assert} = require("assert"); -const {mock_module, zrequire} = require("../zjsunit/namespace"); +const {mock_esm, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); const $ = require("../zjsunit/zjquery"); -const upload_widget = mock_module("upload_widget"); +const upload_widget = mock_esm("../../static/js/upload_widget"); const settings_emoji = zrequire("settings_emoji"); run_test("build_emoji_upload_widget", () => { diff --git a/frontend_tests/node_tests/settings_muting.js b/frontend_tests/node_tests/settings_muting.js index 026b556524..2a9b0aa1bd 100644 --- a/frontend_tests/node_tests/settings_muting.js +++ b/frontend_tests/node_tests/settings_muting.js @@ -2,11 +2,11 @@ const {strict: assert} = require("assert"); -const {mock_module, zrequire} = require("../zjsunit/namespace"); +const {mock_esm, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); const $ = require("../zjsunit/zjquery"); -const muting_ui = mock_module("muting_ui"); +const muting_ui = mock_esm("../../static/js/muting_ui"); const settings_muting = zrequire("settings_muting"); const stream_data = zrequire("stream_data"); diff --git a/frontend_tests/node_tests/settings_org.js b/frontend_tests/node_tests/settings_org.js index 88484fde7b..b77b75e3ad 100644 --- a/frontend_tests/node_tests/settings_org.js +++ b/frontend_tests/node_tests/settings_org.js @@ -3,7 +3,7 @@ const {strict: assert} = require("assert"); const {stub_templates} = require("../zjsunit/handlebars"); -const {mock_module, set_global, zrequire} = require("../zjsunit/namespace"); +const {mock_esm, set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); const $ = require("../zjsunit/zjquery"); @@ -32,7 +32,7 @@ const page_params = set_global("page_params", { realm_authentication_methods: {}, }); -const realm_icon = mock_module("realm_icon"); +const realm_icon = mock_esm("../../static/js/realm_icon"); stub_templates((name, data) => { if (name === "settings/admin_realm_domains_list") { @@ -42,17 +42,17 @@ stub_templates((name, data) => { throw new Error(`Unknown template ${name}`); }); -const channel = mock_module("channel"); -const overlays = mock_module("overlays"); +const channel = mock_esm("../../static/js/channel"); +const overlays = mock_esm("../../static/js/overlays"); -mock_module("list_widget", { +mock_esm("../../static/js/list_widget", { create: () => ({init: noop}), }); -mock_module("loading", { +mock_esm("../../static/js/loading", { make_indicator: noop, destroy_indicator: noop, }); -mock_module("ui_report", { +mock_esm("../../static/js/ui_report", { success(msg, elem) { elem.val(msg); }, diff --git a/frontend_tests/node_tests/settings_profile_fields.js b/frontend_tests/node_tests/settings_profile_fields.js index a8dd8b0eba..85b517a6a6 100644 --- a/frontend_tests/node_tests/settings_profile_fields.js +++ b/frontend_tests/node_tests/settings_profile_fields.js @@ -3,11 +3,11 @@ const {strict: assert} = require("assert"); const {stub_templates} = require("../zjsunit/handlebars"); -const {mock_module, set_global, zrequire} = require("../zjsunit/namespace"); +const {mock_esm, set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); const $ = require("../zjsunit/zjquery"); -const loading = mock_module("loading"); +const loading = mock_esm("../../static/js/loading"); const page_params = set_global("page_params", {}); 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 47fdcb0143..8b3a4b55de 100644 --- a/frontend_tests/node_tests/settings_user_groups.js +++ b/frontend_tests/node_tests/settings_user_groups.js @@ -5,7 +5,7 @@ const {strict: assert} = require("assert"); const _ = require("lodash"); const {stub_templates} = require("../zjsunit/handlebars"); -const {mock_module, set_global, zrequire} = require("../zjsunit/namespace"); +const {mock_esm, set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); const $ = require("../zjsunit/zjquery"); @@ -17,16 +17,16 @@ const pills = { let create_item_handler; -const channel = mock_module("channel"); -const confirm_dialog = mock_module("confirm_dialog"); -const input_pill = mock_module("input_pill"); -const typeahead_helper = mock_module("typeahead_helper"); -const user_groups = mock_module("user_groups", { +const channel = mock_esm("../../static/js/channel"); +const confirm_dialog = mock_esm("../../static/js/confirm_dialog"); +const input_pill = mock_esm("../../static/js/input_pill"); +const typeahead_helper = mock_esm("../../static/js/typeahead_helper"); +const user_groups = mock_esm("../../static/js/user_groups", { get_user_group_from_id: noop, remove: noop, add: noop, }); -const ui_report = mock_module("ui_report"); +const ui_report = mock_esm("../../static/js/ui_report"); const page_params = set_global("page_params", {}); diff --git a/frontend_tests/node_tests/stream_edit.js b/frontend_tests/node_tests/stream_edit.js index 455c892916..24773b81b5 100644 --- a/frontend_tests/node_tests/stream_edit.js +++ b/frontend_tests/node_tests/stream_edit.js @@ -3,7 +3,7 @@ const {strict: assert} = require("assert"); const {stub_templates} = require("../zjsunit/handlebars"); -const {mock_module, set_global, zrequire} = require("../zjsunit/namespace"); +const {mock_esm, set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); const $ = require("../zjsunit/zjquery"); @@ -11,23 +11,23 @@ const noop = () => {}; stub_templates(() => noop); const page_params = set_global("page_params", {}); -const typeahead_helper = mock_module("typeahead_helper"); -const ui = mock_module("ui", { +const typeahead_helper = mock_esm("../../static/js/typeahead_helper"); +const ui = mock_esm("../../static/js/ui", { get_scroll_element: noop, }); -mock_module("hash_util", { +mock_esm("../../static/js/hash_util", { stream_edit_uri: noop, by_stream_uri: noop, }); -mock_module("hashchange", {update_browser_history: noop}); -mock_module("list_widget", { +mock_esm("../../static/js/hashchange", {update_browser_history: noop}); +mock_esm("../../static/js/list_widget", { create: () => ({init: noop}), }); -mock_module("settings_notifications", { +mock_esm("../../static/js/settings_notifications", { get_notifications_table_row_data: noop, }); -mock_module("stream_color", { +mock_esm("../../static/js/stream_color", { set_colorpicker_color: noop, }); diff --git a/frontend_tests/node_tests/stream_events.js b/frontend_tests/node_tests/stream_events.js index 2f677684b5..581c2c1162 100644 --- a/frontend_tests/node_tests/stream_events.js +++ b/frontend_tests/node_tests/stream_events.js @@ -2,37 +2,37 @@ const {strict: assert} = require("assert"); -const {mock_module, set_global, zrequire} = require("../zjsunit/namespace"); +const {mock_esm, set_global, zrequire} = require("../zjsunit/namespace"); const {make_stub} = require("../zjsunit/stub"); const {run_test} = require("../zjsunit/test"); const $ = require("../zjsunit/zjquery"); const noop = () => {}; -const color_data = mock_module("color_data"); -const message_util = mock_module("message_util"); -const stream_color = mock_module("stream_color"); -const stream_list = mock_module("stream_list"); -const stream_muting = mock_module("stream_muting"); -const subs = mock_module("subs", { +const color_data = mock_esm("../../static/js/color_data"); +const message_util = mock_esm("../../static/js/message_util"); +const stream_color = mock_esm("../../static/js/stream_color"); +const stream_list = mock_esm("../../static/js/stream_list"); +const stream_muting = mock_esm("../../static/js/stream_muting"); +const subs = mock_esm("../../static/js/subs", { update_settings_for_subscribed: noop, }); -mock_module("message_list", { +mock_esm("../../static/js/message_list", { all: { all_messages() { return ["msg"]; }, }, }); -mock_module("recent_topics", { +mock_esm("../../static/js/recent_topics", { complete_rerender: () => {}, }); -mock_module("settings_notifications", { +mock_esm("../../static/js/settings_notifications", { update_page: () => {}, }); set_global("current_msg_list", {}); -mock_module("overlays", {streams_open: () => true}); +mock_esm("../../static/js/overlays", {streams_open: () => true}); const {Filter} = zrequire("../js/filter"); const message_view_header = zrequire("message_view_header"); diff --git a/frontend_tests/node_tests/stream_list.js b/frontend_tests/node_tests/stream_list.js index 41008dbc2b..9a3de56655 100644 --- a/frontend_tests/node_tests/stream_list.js +++ b/frontend_tests/node_tests/stream_list.js @@ -3,7 +3,7 @@ const {strict: assert} = require("assert"); const {stub_templates} = require("../zjsunit/handlebars"); -const {mock_module, set_global, zrequire} = require("../zjsunit/namespace"); +const {mock_esm, set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); const $ = require("../zjsunit/zjquery"); @@ -16,12 +16,12 @@ const page_params = set_global("page_params", { const noop = () => {}; -const narrow_state = mock_module("narrow_state"); -const topic_list = mock_module("topic_list"); -mock_module("keydown_util", { +const narrow_state = mock_esm("../../static/js/narrow_state"); +const topic_list = mock_esm("../../static/js/topic_list"); +mock_esm("../../static/js/keydown_util", { handle: noop, }); -mock_module("ui", {get_scroll_element: (element) => element}); +mock_esm("../../static/js/ui", {get_scroll_element: (element) => element}); const {Filter} = zrequire("../js/filter"); const stream_sort = zrequire("stream_sort"); diff --git a/frontend_tests/node_tests/stream_search.js b/frontend_tests/node_tests/stream_search.js index 576dec430d..c22ae3c293 100644 --- a/frontend_tests/node_tests/stream_search.js +++ b/frontend_tests/node_tests/stream_search.js @@ -2,7 +2,7 @@ const {strict: assert} = require("assert"); -const {mock_module, zrequire} = require("../zjsunit/namespace"); +const {mock_esm, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); const $ = require("../zjsunit/zjquery"); @@ -11,14 +11,14 @@ const $ = require("../zjsunit/zjquery"); const noop = () => {}; -mock_module("resize", { +mock_esm("../../static/js/resize", { resize_page_components: noop, resize_stream_filters_container: noop, }); -const popovers = mock_module("popovers"); -const stream_popover = mock_module("stream_popover"); +const popovers = mock_esm("../../static/js/popovers"); +const stream_popover = mock_esm("../../static/js/stream_popover"); const stream_list = zrequire("stream_list"); diff --git a/frontend_tests/node_tests/stream_topic_history.js b/frontend_tests/node_tests/stream_topic_history.js index 5d99f716d3..c7329edc2b 100644 --- a/frontend_tests/node_tests/stream_topic_history.js +++ b/frontend_tests/node_tests/stream_topic_history.js @@ -2,12 +2,12 @@ const {strict: assert} = require("assert"); -const {mock_module, zrequire} = require("../zjsunit/namespace"); +const {mock_esm, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -const channel = mock_module("channel"); -const message_list = mock_module("message_list"); -const message_util = mock_module("message_util"); +const channel = mock_esm("../../static/js/channel"); +const message_list = mock_esm("../../static/js/message_list"); +const message_util = mock_esm("../../static/js/message_util"); const unread = zrequire("unread"); const stream_data = zrequire("stream_data"); diff --git a/frontend_tests/node_tests/submessage.js b/frontend_tests/node_tests/submessage.js index 17a8c7f0f4..1a9432c247 100644 --- a/frontend_tests/node_tests/submessage.js +++ b/frontend_tests/node_tests/submessage.js @@ -2,12 +2,12 @@ const {strict: assert} = require("assert"); -const {mock_module, zrequire} = require("../zjsunit/namespace"); +const {mock_esm, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -const channel = mock_module("channel"); -const message_store = mock_module("message_store"); -const widgetize = mock_module("widgetize"); +const channel = mock_esm("../../static/js/channel"); +const message_store = mock_esm("../../static/js/message_store"); +const widgetize = mock_esm("../../static/js/widgetize"); const submessage = zrequire("submessage"); diff --git a/frontend_tests/node_tests/subs.js b/frontend_tests/node_tests/subs.js index d11dbceb33..d108518827 100644 --- a/frontend_tests/node_tests/subs.js +++ b/frontend_tests/node_tests/subs.js @@ -3,13 +3,13 @@ const {strict: assert} = require("assert"); const {stub_templates} = require("../zjsunit/handlebars"); -const {mock_module, set_global, zrequire} = require("../zjsunit/namespace"); +const {mock_esm, set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); const $ = require("../zjsunit/zjquery"); const denmark_stream_id = 101; -const ui = mock_module("ui", { +const ui = mock_esm("../../static/js/ui", { get_content_element: (element) => element, get_scroll_element: (element) => element, }); @@ -17,7 +17,7 @@ const ui = mock_module("ui", { set_global("location", { hash: `#streams/${denmark_stream_id}/announce`, }); -mock_module("hash_util", { +mock_esm("../../static/js/hash_util", { by_stream_uri: () => {}, }); set_global("page_params", {}); diff --git a/frontend_tests/node_tests/top_left_corner.js b/frontend_tests/node_tests/top_left_corner.js index 0c4a138af2..c55057e56d 100644 --- a/frontend_tests/node_tests/top_left_corner.js +++ b/frontend_tests/node_tests/top_left_corner.js @@ -2,11 +2,11 @@ const {strict: assert} = require("assert"); -const {mock_module, set_global, zrequire} = require("../zjsunit/namespace"); +const {mock_esm, set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); const $ = require("../zjsunit/zjquery"); -mock_module("resize", { +mock_esm("../../static/js/resize", { resize_stream_filters_container: () => {}, }); const {Filter} = zrequire("../js/filter"); diff --git a/frontend_tests/node_tests/topic_list_data.js b/frontend_tests/node_tests/topic_list_data.js index 0180844042..82ff1ef9ca 100644 --- a/frontend_tests/node_tests/topic_list_data.js +++ b/frontend_tests/node_tests/topic_list_data.js @@ -4,15 +4,15 @@ const {strict: assert} = require("assert"); const _ = require("lodash"); -const {mock_module, zrequire} = require("../zjsunit/namespace"); +const {mock_esm, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -const muting = mock_module("muting", { +const muting = mock_esm("../../static/js/muting", { is_topic_muted() { return false; }, }); -const narrow_state = mock_module("narrow_state", { +const narrow_state = mock_esm("../../static/js/narrow_state", { topic() {}, }); diff --git a/frontend_tests/node_tests/transmit.js b/frontend_tests/node_tests/transmit.js index 0f641583cb..26853ab862 100644 --- a/frontend_tests/node_tests/transmit.js +++ b/frontend_tests/node_tests/transmit.js @@ -2,16 +2,16 @@ const {strict: assert} = require("assert"); -const {mock_module, set_global, zrequire} = require("../zjsunit/namespace"); +const {mock_esm, set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); const noop = () => {}; const page_params = set_global("page_params", {}); -const channel = mock_module("channel"); -const reload = mock_module("reload"); -const reload_state = mock_module("reload_state"); -const sent_messages = mock_module("sent_messages", { +const channel = mock_esm("../../static/js/channel"); +const reload = mock_esm("../../static/js/reload"); +const reload_state = mock_esm("../../static/js/reload_state"); +const sent_messages = mock_esm("../../static/js/sent_messages", { start_tracking_message: noop, report_server_ack: noop, }); diff --git a/frontend_tests/node_tests/tutorial.js b/frontend_tests/node_tests/tutorial.js index 0b30198b09..38894667b2 100644 --- a/frontend_tests/node_tests/tutorial.js +++ b/frontend_tests/node_tests/tutorial.js @@ -9,13 +9,7 @@ // become clear as you keep reading. const {strict: assert} = require("assert"); -const { - mock_module, - set_global, - unmock_module, - with_field, - zrequire, -} = require("../zjsunit/namespace"); +const {mock_esm, set_global, unmock_module, with_field, zrequire} = require("../zjsunit/namespace"); const {make_stub} = require("../zjsunit/stub"); const {run_test} = require("../zjsunit/test"); @@ -23,23 +17,23 @@ const {run_test} = require("../zjsunit/test"); // structure that the server sends down to us when the app starts. We // prefer to test with a clean slate. -const activity = mock_module("activity"); -const channel = mock_module("channel"); +const activity = mock_esm("../../static/js/activity"); +const channel = mock_esm("../../static/js/channel"); const home_msg_list = set_global("home_msg_list", {}); -const message_list = mock_module("message_list"); -const message_live_update = mock_module("message_live_update"); -const message_util = mock_module("message_util"); -const message_viewport = mock_module("message_viewport"); -const notifications = mock_module("notifications"); -const overlays = mock_module("overlays"); -const pm_list = mock_module("pm_list"); -const resize = mock_module("resize"); -const settings_users = mock_module("settings_users"); -const topic_list = mock_module("topic_list"); -const unread_ui = mock_module("unread_ui"); +const message_list = mock_esm("../../static/js/message_list"); +const message_live_update = mock_esm("../../static/js/message_live_update"); +const message_util = mock_esm("../../static/js/message_util"); +const message_viewport = mock_esm("../../static/js/message_viewport"); +const notifications = mock_esm("../../static/js/notifications"); +const overlays = mock_esm("../../static/js/overlays"); +const pm_list = mock_esm("../../static/js/pm_list"); +const resize = mock_esm("../../static/js/resize"); +const settings_users = mock_esm("../../static/js/settings_users"); +const topic_list = mock_esm("../../static/js/topic_list"); +const unread_ui = mock_esm("../../static/js/unread_ui"); -let stream_list = mock_module("stream_list"); -let unread_ops = mock_module("unread_ops"); +let stream_list = mock_esm("../../static/js/stream_list"); +let unread_ops = mock_esm("../../static/js/unread_ops"); set_global("page_params", {}); @@ -587,7 +581,7 @@ run_test("explore make_stub", (override) => { */ -unmock_module("unread_ops"); +unmock_module("../../static/js/unread_ops"); unread_ops = zrequire("unread_ops"); run_test("unread_ops", (override) => { @@ -686,7 +680,7 @@ run_test("unread_ops", (override) => { */ -unmock_module("stream_list"); +unmock_module("../../static/js/stream_list"); stream_list = zrequire("stream_list"); const social_stream = { diff --git a/frontend_tests/node_tests/unread.js b/frontend_tests/node_tests/unread.js index daa8804ee8..d85175fbd9 100644 --- a/frontend_tests/node_tests/unread.js +++ b/frontend_tests/node_tests/unread.js @@ -4,14 +4,14 @@ const {strict: assert} = require("assert"); const _ = require("lodash"); -const {mock_module, set_global, zrequire} = require("../zjsunit/namespace"); +const {mock_esm, set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); let page_params = set_global("page_params", { realm_push_notifications_enabled: false, }); -const message_store = mock_module("message_store", { +const message_store = mock_esm("../../static/js/message_store", { get() {}, }); const muting = zrequire("muting"); diff --git a/frontend_tests/node_tests/user_events.js b/frontend_tests/node_tests/user_events.js index b2ff175cd9..7deb0b1d4b 100644 --- a/frontend_tests/node_tests/user_events.js +++ b/frontend_tests/node_tests/user_events.js @@ -2,43 +2,43 @@ const {strict: assert} = require("assert"); -const {mock_module, set_global, zrequire} = require("../zjsunit/namespace"); +const {mock_esm, set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -const message_live_update = mock_module("message_live_update"); -const settings_account = mock_module("settings_account", { +const message_live_update = mock_esm("../../static/js/message_live_update"); +const settings_account = mock_esm("../../static/js/settings_account", { update_email() {}, update_full_name() {}, }); -mock_module("activity", { +mock_esm("../../static/js/activity", { redraw() {}, }); -mock_module("compose", { +mock_esm("../../static/js/compose", { update_email() {}, }); -mock_module("gear_menu", { +mock_esm("../../static/js/gear_menu", { update_org_settings_menu_item() {}, }); -mock_module("narrow_state", { +mock_esm("../../static/js/narrow_state", { update_email() {}, }); -mock_module("pm_list", { +mock_esm("../../static/js/pm_list", { update_private_messages() {}, }); -mock_module("settings_linkifiers", { +mock_esm("../../static/js/settings_linkifiers", { maybe_disable_widgets() {}, }); -mock_module("settings_org", { +mock_esm("../../static/js/settings_org", { maybe_disable_widgets() {}, }); -mock_module("settings_profile_fields", { +mock_esm("../../static/js/settings_profile_fields", { maybe_disable_widgets() {}, }); -mock_module("settings_streams", { +mock_esm("../../static/js/settings_streams", { maybe_disable_widgets() {}, }); -mock_module("settings_users", { +mock_esm("../../static/js/settings_users", { update_user_data() {}, }); diff --git a/frontend_tests/node_tests/user_status.js b/frontend_tests/node_tests/user_status.js index de398832ce..dbf81d895d 100644 --- a/frontend_tests/node_tests/user_status.js +++ b/frontend_tests/node_tests/user_status.js @@ -2,10 +2,10 @@ const {strict: assert} = require("assert"); -const {mock_module, zrequire} = require("../zjsunit/namespace"); +const {mock_esm, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -const channel = mock_module("channel"); +const channel = mock_esm("../../static/js/channel"); const user_status = zrequire("user_status"); function initialize() { diff --git a/frontend_tests/node_tests/widgetize.js b/frontend_tests/node_tests/widgetize.js index 7ee0435394..940f2487c2 100644 --- a/frontend_tests/node_tests/widgetize.js +++ b/frontend_tests/node_tests/widgetize.js @@ -2,7 +2,7 @@ const {strict: assert} = require("assert"); -const {mock_module, set_global, zrequire} = require("../zjsunit/namespace"); +const {mock_esm, set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); const $ = require("../zjsunit/zjquery"); @@ -36,7 +36,7 @@ const events = [ let widget_elem; let is_event_handled; let is_widget_activated; -mock_module("poll_widget", { +mock_esm("../../static/js/poll_widget", { activate(data) { is_widget_activated = true; widget_elem = data.elem; @@ -52,7 +52,7 @@ mock_module("poll_widget", { }); set_global("document", "document-stub"); -const narrow_state = mock_module("narrow_state"); +const narrow_state = mock_esm("../../static/js/narrow_state"); set_global("current_msg_list", {}); const widgetize = zrequire("widgetize"); diff --git a/frontend_tests/zjsunit/namespace.js b/frontend_tests/zjsunit/namespace.js index 28b71f8ddd..73f5017f2c 100644 --- a/frontend_tests/zjsunit/namespace.js +++ b/frontend_tests/zjsunit/namespace.js @@ -3,6 +3,8 @@ const Module = require("module"); const path = require("path"); +const callsites = require("callsites"); + const new_globals = new Set(); let old_globals = {}; @@ -28,23 +30,16 @@ exports.start = () => { Module._load = load; }; -exports.mock_module = (short_fn, obj) => { - if (obj === undefined) { - obj = {}; - } - +exports.mock_esm = (request, obj = {}) => { if (typeof obj !== "object") { - throw new TypeError("We expect you to stub with an object."); + throw new TypeError("An ES module must be mocked with an object"); } - if (short_fn.startsWith("/") || short_fn.includes(".")) { - throw new Error(` - There is no need for a path like ${short_fn}. - We just assume the file is under static/js. - `); - } - - const filename = require.resolve(`../../static/js/${short_fn}`); + const filename = Module._resolveFilename( + request, + require.cache[callsites()[1].getFileName()], + false, + ); if (module_mocks.has(filename)) { throw new Error(`You already set up a mock for ${filename}`); @@ -59,8 +54,12 @@ exports.mock_module = (short_fn, obj) => { return obj; }; -exports.unmock_module = (short_fn) => { - const filename = require.resolve(`../../static/js/${short_fn}`); +exports.unmock_module = (request) => { + const filename = Module._resolveFilename( + request, + require.cache[callsites()[1].getFileName()], + false, + ); if (!module_mocks.has(filename)) { throw new Error(`Cannot unmock ${filename}, which was not mocked`); diff --git a/package.json b/package.json index 8052a2ee19..d0f6b50c17 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "babel-loader": "^8.0.6", "blueimp-md5": "^2.10.0", "cache-loader": "^4.0.0", + "callsites": "^3.1.0", "clean-css": "^5.1.0", "clipboard": "^2.0.4", "core-js": "^3.6.5", diff --git a/yarn.lock b/yarn.lock index c115bf4d52..8913919a7b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2740,7 +2740,7 @@ callsites@^2.0.0: resolved "https://registry.yarnpkg.com/callsites/-/callsites-2.0.0.tgz#06eb84f00eea413da86affefacbffb36093b3c50" integrity sha1-BuuE8A7qQT2oav/vrL/7Ngk7PFA= -callsites@^3.0.0: +callsites@^3.0.0, callsites@^3.1.0: version "3.1.0" resolved "https://registry.yarnpkg.com/callsites/-/callsites-3.1.0.tgz#b3630abd8943432f54b3f0519238e33cd7df2f73" integrity sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ==