zjsunit: Lift restriction against mocking third party modules.

Use fully resolvable request paths because we need to be able to refer
to third party modules, and to increase uniformity and explicitness.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2021-03-09 21:10:32 -08:00
parent 87a3650176
commit 876806eb4d
76 changed files with 436 additions and 442 deletions

View File

@ -2,7 +2,7 @@
const {strict: assert} = require("assert"); 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 {run_test} = require("../zjsunit/test");
const $ = require("../zjsunit/zjquery"); const $ = require("../zjsunit/zjquery");
@ -23,36 +23,36 @@ const _document = {
}, },
}; };
const compose_state = mock_module("compose_state"); const compose_state = mock_esm("../../static/js/compose_state");
const channel = mock_module("channel"); const channel = mock_esm("../../static/js/channel");
mock_module("padded_widget", { mock_esm("../../static/js/padded_widget", {
update_padding: () => {}, update_padding: () => {},
}); });
mock_module("keydown_util", { mock_esm("../../static/js/keydown_util", {
handle: (opts) => { handle: (opts) => {
filter_key_handlers = opts.handlers; filter_key_handlers = opts.handlers;
}, },
}); });
mock_module("pm_list", { mock_esm("../../static/js/pm_list", {
update_private_messages: () => {}, update_private_messages: () => {},
}); });
mock_module("popovers", { mock_esm("../../static/js/popovers", {
hide_all_except_sidebars() {}, hide_all_except_sidebars() {},
hide_all() {}, hide_all() {},
show_userlist_sidebar() {}, show_userlist_sidebar() {},
}); });
mock_module("resize", { mock_esm("../../static/js/resize", {
resize_sidebars: () => {}, resize_sidebars: () => {},
resize_page_components: () => {}, resize_page_components: () => {},
}); });
mock_module("scroll_util", { mock_esm("../../static/js/scroll_util", {
scroll_element_into_container: () => {}, scroll_element_into_container: () => {},
}); });
mock_module("server_events", { mock_esm("../../static/js/server_events", {
check_for_unsuspend() {}, check_for_unsuspend() {},
}); });
mock_module("stream_popover", { mock_esm("../../static/js/stream_popover", {
show_streamlist_sidebar() {}, show_streamlist_sidebar() {},
}); });
set_global("document", _document); set_global("document", _document);

View File

@ -3,11 +3,11 @@
const {strict: assert} = require("assert"); const {strict: assert} = require("assert");
const {stub_templates} = require("../zjsunit/handlebars"); 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 {run_test} = require("../zjsunit/test");
const $ = require("../zjsunit/zjquery"); 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 = zrequire("alert_words");
const alert_words_ui = zrequire("alert_words_ui"); const alert_words_ui = zrequire("alert_words_ui");

View File

@ -5,7 +5,7 @@ const fs = require("fs");
const {JSDOM} = require("jsdom"); 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 {run_test} = require("../zjsunit/test");
const $ = require("../zjsunit/zjquery"); const $ = require("../zjsunit/zjquery");
@ -17,7 +17,7 @@ const StripeCheckout = set_global("StripeCheckout", {
configure: () => {}, configure: () => {},
}); });
const helpers = mock_module("billing/helpers", { const helpers = mock_esm("../../static/js/billing/helpers", {
set_tab: () => {}, set_tab: () => {},
}); });

View File

@ -6,7 +6,7 @@ const fs = require("fs");
const jQueryFactory = require("jquery"); const jQueryFactory = require("jquery");
const {JSDOM} = require("jsdom"); 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 {run_test} = require("../zjsunit/test");
const $ = require("../zjsunit/zjquery"); const $ = require("../zjsunit/zjquery");
@ -16,7 +16,7 @@ const jquery = jQueryFactory(dom.window);
const page_params = set_global("page_params", {}); const page_params = set_global("page_params", {});
const history = set_global("history", {}); const history = set_global("history", {});
const loading = mock_module("loading"); const loading = mock_esm("../../static/js/loading");
set_global("document", { set_global("document", {
title: "Zulip", title: "Zulip",
}); });

View File

@ -2,10 +2,10 @@
const {strict: assert} = require("assert"); 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 {run_test} = require("../zjsunit/test");
mock_module("settings_bots", { mock_esm("../../static/js/settings_bots", {
render_bots: () => {}, render_bots: () => {},
}); });
const bot_data = zrequire("bot_data"); const bot_data = zrequire("bot_data");

View File

@ -4,12 +4,12 @@ const {strict: assert} = require("assert");
const _ = require("lodash"); 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 {run_test} = require("../zjsunit/test");
const page_params = set_global("page_params", {}); const page_params = set_global("page_params", {});
const timerender = mock_module("timerender"); const timerender = mock_esm("../../static/js/timerender");
const people = zrequire("people"); const people = zrequire("people");
const presence = zrequire("presence"); const presence = zrequire("presence");

View File

@ -4,15 +4,15 @@ const {strict: assert} = require("assert");
const _ = require("lodash"); const _ = require("lodash");
const {mock_module, zrequire} = require("../zjsunit/namespace"); const {mock_esm, zrequire} = require("../zjsunit/namespace");
const {run_test} = require("../zjsunit/test"); const {run_test} = require("../zjsunit/test");
const $ = require("../zjsunit/zjquery"); const $ = require("../zjsunit/zjquery");
mock_module("padded_widget", { mock_esm("../../static/js/padded_widget", {
update_padding: () => {}, update_padding: () => {},
}); });
mock_module("message_viewport", { mock_esm("../../static/js/message_viewport", {
height: () => 550, height: () => 550,
}); });

View File

@ -6,7 +6,7 @@ const {JSDOM} = require("jsdom");
const MockDate = require("mockdate"); const MockDate = require("mockdate");
const {stub_templates} = require("../zjsunit/handlebars"); 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 {run_test} = require("../zjsunit/test");
const $ = require("../zjsunit/zjquery"); const $ = require("../zjsunit/zjquery");
@ -17,7 +17,7 @@ set_global("DOMParser", new JSDOM().window.DOMParser);
let compose_actions_start_checked; let compose_actions_start_checked;
let compose_actions_expected_opts; let compose_actions_expected_opts;
mock_module("compose_actions", { mock_esm("../../static/js/compose_actions", {
update_placeholder_text: noop, update_placeholder_text: noop,
start(msg_type, opts) { 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 = { const _navigator = {
platform: "", platform: "",
}; };
@ -41,30 +41,30 @@ const _document = {
}; };
set_global("document", _document); set_global("document", _document);
const channel = mock_module("channel"); const channel = mock_esm("../../static/js/channel");
const loading = mock_module("loading"); const loading = mock_esm("../../static/js/loading");
const local_message = mock_module("local_message"); const local_message = mock_esm("../../static/js/local_message");
const markdown = mock_module("markdown"); const markdown = mock_esm("../../static/js/markdown");
const page_params = set_global("page_params", {}); const page_params = set_global("page_params", {});
const reminder = mock_module("reminder", { const reminder = mock_esm("../../static/js/reminder", {
is_deferred_delivery: noop, is_deferred_delivery: noop,
}); });
const resize = mock_module("resize"); const resize = mock_esm("../../static/js/resize");
const sent_messages = mock_module("sent_messages", { const sent_messages = mock_esm("../../static/js/sent_messages", {
start_tracking_message: noop, start_tracking_message: noop,
}); });
const stream_edit = mock_module("stream_edit"); const stream_edit = mock_esm("../../static/js/stream_edit");
const subs = mock_module("subs"); const subs = mock_esm("../../static/js/subs");
const transmit = mock_module("transmit"); const transmit = mock_esm("../../static/js/transmit");
const ui_util = mock_module("ui_util"); const ui_util = mock_esm("../../static/js/ui_util");
mock_module("drafts", { mock_esm("../../static/js/drafts", {
delete_draft_after_send: noop, delete_draft_after_send: noop,
}); });
mock_module("notifications", { mock_esm("../../static/js/notifications", {
notify_above_composebox: noop, notify_above_composebox: noop,
clear_compose_notifications: noop, clear_compose_notifications: noop,
}); });
mock_module("rendered_markdown", { mock_esm("../../static/js/rendered_markdown", {
update_elements: () => {}, update_elements: () => {},
}); });
set_global("navigator", _navigator); set_global("navigator", _navigator);

View File

@ -2,7 +2,7 @@
const {strict: assert} = require("assert"); 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 {run_test} = require("../zjsunit/test");
const $ = require("../zjsunit/zjquery"); const $ = require("../zjsunit/zjquery");
@ -15,28 +15,28 @@ set_global("document", {
to_$: () => $("document-stub"), to_$: () => $("document-stub"),
}); });
const channel = mock_module("channel"); const channel = mock_esm("../../static/js/channel");
const compose_fade = mock_module("compose_fade", { const compose_fade = mock_esm("../../static/js/compose_fade", {
clear_compose: noop, clear_compose: noop,
}); });
const compose_pm_pill = mock_module("compose_pm_pill"); const compose_pm_pill = mock_esm("../../static/js/compose_pm_pill");
const hash_util = mock_module("hash_util"); const hash_util = mock_esm("../../static/js/hash_util");
const narrow_state = mock_module("narrow_state", { const narrow_state = mock_esm("../../static/js/narrow_state", {
set_compose_defaults: noop, set_compose_defaults: noop,
}); });
mock_module("notifications", { mock_esm("../../static/js/notifications", {
clear_compose_notifications: noop, clear_compose_notifications: noop,
}); });
mock_module("reload_state", { mock_esm("../../static/js/reload_state", {
is_in_progress: () => false, is_in_progress: () => false,
}); });
mock_module("drafts", { mock_esm("../../static/js/drafts", {
update_draft: noop, update_draft: noop,
}); });
mock_module("common", { mock_esm("../../static/js/common", {
status_classes: "status_classes", status_classes: "status_classes",
}); });
mock_module("unread_ops", { mock_esm("../../static/js/unread_ops", {
notify_server_message_read: noop, notify_server_message_read: noop,
}); });
set_global("current_msg_list", { set_global("current_msg_list", {

View File

@ -2,11 +2,11 @@
const {strict: assert} = require("assert"); 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 {run_test} = require("../zjsunit/test");
const $ = require("../zjsunit/zjquery"); 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 people = zrequire("people");
const compose_pm_pill = zrequire("compose_pm_pill"); const compose_pm_pill = zrequire("compose_pm_pill");

View File

@ -2,10 +2,10 @@
const {strict: assert} = require("assert"); 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 {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"); const compose_state = zrequire("compose_state");

View File

@ -2,16 +2,16 @@
const {strict: assert} = require("assert"); 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 {run_test} = require("../zjsunit/test");
const $ = require("../zjsunit/zjquery"); const $ = require("../zjsunit/zjquery");
const events = require("./lib/events"); 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 page_params = set_global("page_params", {});
const upload = mock_module("upload"); const upload = mock_esm("../../static/js/upload");
mock_module("resize", { mock_esm("../../static/js/resize", {
watch_manual_resize() {}, watch_manual_resize() {},
}); });
set_global("csrf_token", "fake-csrf-token"); set_global("csrf_token", "fake-csrf-token");

View File

@ -2,26 +2,26 @@
const {strict: assert} = require("assert"); 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 {run_test} = require("../zjsunit/test");
const $ = require("../zjsunit/zjquery"); const $ = require("../zjsunit/zjquery");
const noop = () => {}; const noop = () => {};
const channel = mock_module("channel"); const channel = mock_esm("../../static/js/channel");
const compose = mock_module("compose", { const compose = mock_esm("../../static/js/compose", {
finish: noop, finish: noop,
}); });
const message_store = mock_module("message_store", { const message_store = mock_esm("../../static/js/message_store", {
user_ids: () => [], 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", {}); const page_params = set_global("page_params", {});
let autosize_called; let autosize_called;
mock_module("compose_ui", { mock_esm("../../static/js/compose_ui", {
autosize_textarea() { autosize_textarea() {
autosize_called = true; autosize_called = true;
}, },

View File

@ -5,7 +5,7 @@ const {strict: assert} = require("assert");
const jquery = require("jquery"); const jquery = require("jquery");
const {JSDOM} = require("jsdom"); 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 {run_test} = require("../zjsunit/test");
const {window} = new JSDOM("<!DOCTYPE html><p>Hello world</p>"); const {window} = new JSDOM("<!DOCTYPE html><p>Hello world</p>");
@ -13,7 +13,7 @@ const {window} = new JSDOM("<!DOCTYPE html><p>Hello world</p>");
const {DOMParser, document} = window; const {DOMParser, document} = window;
const $ = set_global("$", jquery(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", { set_global("page_params", {
development_environment: true, development_environment: true,
}); });

View File

@ -2,7 +2,7 @@
const {strict: assert} = require("assert"); 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 {make_stub} = require("../zjsunit/stub");
const {run_test} = require("../zjsunit/test"); const {run_test} = require("../zjsunit/test");
const $ = require("../zjsunit/zjquery"); const $ = require("../zjsunit/zjquery");
@ -18,47 +18,47 @@ const typing_person1 = events.typing_person1;
set_global("setTimeout", (func) => func()); set_global("setTimeout", (func) => func());
const activity = mock_module("activity"); const activity = mock_esm("../../static/js/activity");
const alert_words_ui = mock_module("alert_words_ui"); const alert_words_ui = mock_esm("../../static/js/alert_words_ui");
const attachments_ui = mock_module("attachments_ui"); const attachments_ui = mock_esm("../../static/js/attachments_ui");
const bot_data = mock_module("bot_data"); const bot_data = mock_esm("../../static/js/bot_data");
const composebox_typeahead = mock_module("composebox_typeahead"); const composebox_typeahead = mock_esm("../../static/js/composebox_typeahead");
const emoji_picker = mock_module("emoji_picker"); const emoji_picker = mock_esm("../../static/js/emoji_picker");
const hotspots = mock_module("hotspots"); const hotspots = mock_esm("../../static/js/hotspots");
const markdown = mock_module("markdown"); const markdown = mock_esm("../../static/js/markdown");
const message_edit = mock_module("message_edit"); const message_edit = mock_esm("../../static/js/message_edit");
const message_events = mock_module("message_events"); const message_events = mock_esm("../../static/js/message_events");
const message_list = mock_module("message_list"); const message_list = mock_esm("../../static/js/message_list");
const muting_ui = mock_module("muting_ui"); const muting_ui = mock_esm("../../static/js/muting_ui");
const night_mode = mock_module("night_mode"); const night_mode = mock_esm("../../static/js/night_mode");
const notifications = mock_module("notifications"); const notifications = mock_esm("../../static/js/notifications");
const reactions = mock_module("reactions"); const reactions = mock_esm("../../static/js/reactions");
const realm_icon = mock_module("realm_icon"); const realm_icon = mock_esm("../../static/js/realm_icon");
const realm_logo = mock_module("realm_logo"); const realm_logo = mock_esm("../../static/js/realm_logo");
const reload = mock_module("reload"); const reload = mock_esm("../../static/js/reload");
const scroll_bar = mock_module("scroll_bar"); const scroll_bar = mock_esm("../../static/js/scroll_bar");
const settings_account = mock_module("settings_account"); const settings_account = mock_esm("../../static/js/settings_account");
const settings_bots = mock_module("settings_bots"); const settings_bots = mock_esm("../../static/js/settings_bots");
const settings_display = mock_module("settings_display"); const settings_display = mock_esm("../../static/js/settings_display");
const settings_emoji = mock_module("settings_emoji"); const settings_emoji = mock_esm("../../static/js/settings_emoji");
const settings_exports = mock_module("settings_exports"); const settings_exports = mock_esm("../../static/js/settings_exports");
const settings_invites = mock_module("settings_invites"); const settings_invites = mock_esm("../../static/js/settings_invites");
const settings_linkifiers = mock_module("settings_linkifiers"); const settings_linkifiers = mock_esm("../../static/js/settings_linkifiers");
const settings_notifications = mock_module("settings_notifications"); const settings_notifications = mock_esm("../../static/js/settings_notifications");
const settings_org = mock_module("settings_org"); const settings_org = mock_esm("../../static/js/settings_org");
const settings_profile_fields = mock_module("settings_profile_fields"); const settings_profile_fields = mock_esm("../../static/js/settings_profile_fields");
const settings_streams = mock_module("settings_streams"); const settings_streams = mock_esm("../../static/js/settings_streams");
const settings_user_groups = mock_module("settings_user_groups"); const settings_user_groups = mock_esm("../../static/js/settings_user_groups");
const settings_users = mock_module("settings_users"); const settings_users = mock_esm("../../static/js/settings_users");
const stream_data = mock_module("stream_data"); const stream_data = mock_esm("../../static/js/stream_data");
const stream_events = mock_module("stream_events"); const stream_events = mock_esm("../../static/js/stream_events");
const submessage = mock_module("submessage"); const submessage = mock_esm("../../static/js/submessage");
const typing_events = mock_module("typing_events"); const typing_events = mock_esm("../../static/js/typing_events");
const ui = mock_module("ui"); const ui = mock_esm("../../static/js/ui");
const unread_ops = mock_module("unread_ops"); const unread_ops = mock_esm("../../static/js/unread_ops");
const user_events = mock_module("user_events"); const user_events = mock_esm("../../static/js/user_events");
const user_groups = mock_module("user_groups"); const user_groups = mock_esm("../../static/js/user_groups");
mock_module("compose"); mock_esm("../../static/js/compose");
const electron_bridge = set_global("electron_bridge", {}); const electron_bridge = set_global("electron_bridge", {});

View File

@ -2,7 +2,7 @@
const {strict: assert} = require("assert"); 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 {make_stub} = require("../zjsunit/stub");
const {run_test} = require("../zjsunit/test"); const {run_test} = require("../zjsunit/test");
@ -11,15 +11,15 @@ const events = require("./lib/events");
const event_fixtures = events.fixtures; const event_fixtures = events.fixtures;
const test_user = events.test_user; const test_user = events.test_user;
const compose_fade = mock_module("compose_fade"); const compose_fade = mock_esm("../../static/js/compose_fade");
const narrow_state = mock_module("narrow_state"); const narrow_state = mock_esm("../../static/js/narrow_state");
const overlays = mock_module("overlays"); const overlays = mock_esm("../../static/js/overlays");
const page_params = set_global("page_params", {}); const page_params = set_global("page_params", {});
const settings_org = mock_module("settings_org"); const settings_org = mock_esm("../../static/js/settings_org");
const settings_streams = mock_module("settings_streams"); const settings_streams = mock_esm("../../static/js/settings_streams");
const stream_events = mock_module("stream_events"); const stream_events = mock_esm("../../static/js/stream_events");
const stream_list = mock_module("stream_list"); const stream_list = mock_esm("../../static/js/stream_list");
const subs = mock_module("subs"); const subs = mock_esm("../../static/js/subs");
set_global("current_msg_list", {}); set_global("current_msg_list", {});
const peer_data = zrequire("peer_data"); const peer_data = zrequire("peer_data");

View File

@ -3,7 +3,7 @@
const {strict: assert} = require("assert"); const {strict: assert} = require("assert");
const {stub_templates} = require("../zjsunit/handlebars"); 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 {run_test} = require("../zjsunit/test");
const $ = require("../zjsunit/zjquery"); const $ = require("../zjsunit/zjquery");
@ -24,11 +24,11 @@ const localStorage = set_global("localStorage", {
ls_container.clear(); ls_container.clear();
}, },
}); });
const compose_state = mock_module("compose_state"); const compose_state = mock_esm("../../static/js/compose_state");
mock_module("markdown", { mock_esm("../../static/js/markdown", {
apply_markdown: noop, apply_markdown: noop,
}); });
mock_module("stream_data", { mock_esm("../../static/js/stream_data", {
get_color() { get_color() {
return "#FFFFFF"; return "#FFFFFF";
}, },

View File

@ -2,12 +2,12 @@
const {strict: assert} = require("assert"); 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 {run_test} = require("../zjsunit/test");
const $ = require("../zjsunit/zjquery"); const $ = require("../zjsunit/zjquery");
const noop = () => {}; const noop = () => {};
mock_module("list_widget", { mock_esm("../../static/js/list_widget", {
create: () => ({init: noop}), create: () => ({init: noop}),
}); });
const {DropdownListWidget: dropdown_list_widget} = zrequire("dropdown_list_widget"); const {DropdownListWidget: dropdown_list_widget} = zrequire("dropdown_list_widget");

View File

@ -4,27 +4,27 @@ const {strict: assert} = require("assert");
const MockDate = require("mockdate"); 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 {run_test} = require("../zjsunit/test");
const local_message = mock_module("local_message"); const local_message = mock_esm("../../static/js/local_message");
const markdown = mock_module("markdown"); const markdown = mock_esm("../../static/js/markdown");
const page_params = set_global("page_params", {}); const page_params = set_global("page_params", {});
let disparities = []; let disparities = [];
let messages_to_rerender = []; let messages_to_rerender = [];
mock_module("ui", { mock_esm("../../static/js/ui", {
show_failed_message_success: () => {}, show_failed_message_success: () => {},
}); });
mock_module("sent_messages", { mock_esm("../../static/js/sent_messages", {
mark_disparity: (local_id) => { mark_disparity: (local_id) => {
disparities.push(local_id); disparities.push(local_id);
}, },
}); });
mock_module("message_store", { mock_esm("../../static/js/message_store", {
get: () => ({failed_request: true}), get: () => ({failed_request: true}),
update_booleans: () => {}, 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", ""); set_global("current_msg_list", "");
const echo = zrequire("echo"); const echo = zrequire("echo");

View File

@ -2,10 +2,10 @@
const {strict: assert} = require("assert"); 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 {run_test} = require("../zjsunit/test");
mock_module("message_scroll", { mock_esm("../../static/js/message_scroll", {
hide_loading_older: () => {}, hide_loading_older: () => {},
show_loading_older: () => {}, show_loading_older: () => {},

View File

@ -2,11 +2,11 @@
const {strict: assert} = require("assert"); 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 {run_test} = require("../zjsunit/test");
const $ = require("../zjsunit/zjquery"); 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 page_params = set_global("page_params", {});
const stream_data = zrequire("stream_data"); const stream_data = zrequire("stream_data");

View File

@ -2,10 +2,10 @@
const {strict: assert} = require("assert"); 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 {run_test} = require("../zjsunit/test");
const ui_report = mock_module("ui_report", { const ui_report = mock_esm("../../static/js/ui_report", {
displayed_error: false, displayed_error: false,
error: () => { error: () => {

View File

@ -2,7 +2,7 @@
const {strict: assert} = require("assert"); 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 {run_test} = require("../zjsunit/test");
const $ = require("../zjsunit/zjquery"); const $ = require("../zjsunit/zjquery");
@ -13,23 +13,23 @@ set_global("location", {
}); });
set_global("to_$", () => window_stub); set_global("to_$", () => window_stub);
mock_module("search", { mock_esm("../../static/js/search", {
update_button_visibility: () => {}, update_button_visibility: () => {},
}); });
set_global("document", "document-stub"); set_global("document", "document-stub");
const history = set_global("history", {}); const history = set_global("history", {});
const admin = mock_module("admin"); const admin = mock_esm("../../static/js/admin");
const drafts = mock_module("drafts"); const drafts = mock_esm("../../static/js/drafts");
const floating_recipient_bar = mock_module("floating_recipient_bar"); const floating_recipient_bar = mock_esm("../../static/js/floating_recipient_bar");
const info_overlay = mock_module("info_overlay"); const info_overlay = mock_esm("../../static/js/info_overlay");
const message_viewport = mock_module("message_viewport"); const message_viewport = mock_esm("../../static/js/message_viewport");
const narrow = mock_module("narrow"); const narrow = mock_esm("../../static/js/narrow");
const overlays = mock_module("overlays"); const overlays = mock_esm("../../static/js/overlays");
const settings = mock_module("settings"); const settings = mock_esm("../../static/js/settings");
const subs = mock_module("subs"); const subs = mock_esm("../../static/js/subs");
const ui_util = mock_module("ui_util"); const ui_util = mock_esm("../../static/js/ui_util");
mock_module("top_left_corner", { mock_esm("../../static/js/top_left_corner", {
handle_narrow_deactivated: () => {}, handle_narrow_deactivated: () => {},
}); });
set_global("favicon", {}); set_global("favicon", {});

View File

@ -3,7 +3,7 @@
const {strict: assert} = require("assert"); const {strict: assert} = require("assert");
const { const {
mock_module, mock_esm,
set_global, set_global,
with_field, with_field,
with_overrides, with_overrides,
@ -39,25 +39,25 @@ const page_params = set_global("page_params", {});
// jQuery stuff should go away if we make an initialize() method. // jQuery stuff should go away if we make an initialize() method.
set_global("document", "document-stub"); set_global("document", "document-stub");
const compose_actions = mock_module("compose_actions"); const compose_actions = mock_esm("../../static/js/compose_actions");
const condense = mock_module("condense"); const condense = mock_esm("../../static/js/condense");
const drafts = mock_module("drafts"); const drafts = mock_esm("../../static/js/drafts");
const emoji_picker = mock_module("emoji_picker", { const emoji_picker = mock_esm("../../static/js/emoji_picker", {
reactions_popped: () => false, reactions_popped: () => false,
}); });
const gear_menu = mock_module("gear_menu", { const gear_menu = mock_esm("../../static/js/gear_menu", {
is_open: () => false, is_open: () => false,
}); });
const hashchange = mock_module("hashchange", { const hashchange = mock_esm("../../static/js/hashchange", {
in_recent_topics_hash: () => false, in_recent_topics_hash: () => false,
}); });
const lightbox = mock_module("lightbox"); const lightbox = mock_esm("../../static/js/lightbox");
const list_util = mock_module("list_util"); const list_util = mock_esm("../../static/js/list_util");
const message_edit = mock_module("message_edit"); const message_edit = mock_esm("../../static/js/message_edit");
const muting_ui = mock_module("muting_ui"); const muting_ui = mock_esm("../../static/js/muting_ui");
const narrow = mock_module("narrow"); const narrow = mock_esm("../../static/js/narrow");
const navigate = mock_module("navigate"); const navigate = mock_esm("../../static/js/navigate");
const overlays = mock_module("overlays", { const overlays = mock_esm("../../static/js/overlays", {
is_active: () => false, is_active: () => false,
settings_open: () => false, settings_open: () => false,
streams_open: () => false, streams_open: () => false,
@ -65,29 +65,29 @@ const overlays = mock_module("overlays", {
drafts_open: () => false, drafts_open: () => false,
info_overlay_open: () => false, info_overlay_open: () => false,
}); });
const popovers = mock_module("popovers", { const popovers = mock_esm("../../static/js/popovers", {
actions_popped: () => false, actions_popped: () => false,
message_info_popped: () => false, message_info_popped: () => false,
user_sidebar_popped: () => false, user_sidebar_popped: () => false,
user_info_popped: () => false, user_info_popped: () => false,
}); });
const reactions = mock_module("reactions"); const reactions = mock_esm("../../static/js/reactions");
const search = mock_module("search"); const search = mock_esm("../../static/js/search");
const stream_list = mock_module("stream_list"); const stream_list = mock_esm("../../static/js/stream_list");
const subs = mock_module("subs"); const subs = mock_esm("../../static/js/subs");
mock_module("stream_popover", { mock_esm("../../static/js/stream_popover", {
stream_popped: () => false, stream_popped: () => false,
topic_popped: () => false, topic_popped: () => false,
all_messages_popped: () => false, all_messages_popped: () => false,
starred_messages_popped: () => false, starred_messages_popped: () => false,
}); });
mock_module("hotspots", { mock_esm("../../static/js/hotspots", {
is_open: () => false, is_open: () => false,
}); });
mock_module("recent_topics", { mock_esm("../../static/js/recent_topics", {
is_visible: () => false, is_visible: () => false,
}); });

View File

@ -2,7 +2,7 @@
const {strict: assert} = require("assert"); 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 {run_test} = require("../zjsunit/test");
const $ = require("../zjsunit/zjquery"); const $ = require("../zjsunit/zjquery");
@ -11,7 +11,7 @@ set_global("document", {});
const noop = () => {}; const noop = () => {};
const example_img_link = "http://example.com/example.png"; const example_img_link = "http://example.com/example.png";
mock_module("ui_util", { mock_esm("../../static/js/ui_util", {
place_caret_at_end: noop, place_caret_at_end: noop,
}); });

View File

@ -2,22 +2,22 @@
const {strict: assert} = require("assert"); 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 {run_test} = require("../zjsunit/test");
const $ = require("../zjsunit/zjquery"); const $ = require("../zjsunit/zjquery");
set_global("Image", class Image {}); set_global("Image", class Image {});
mock_module("overlays", { mock_esm("../../static/js/overlays", {
close_overlay: () => {}, close_overlay: () => {},
close_active: () => {}, close_active: () => {},
open_overlay: () => {}, open_overlay: () => {},
}); });
mock_module("popovers", { mock_esm("../../static/js/popovers", {
hide_all: () => {}, hide_all: () => {},
}); });
const message_store = mock_module("message_store"); const message_store = mock_esm("../../static/js/message_store");
const rows = zrequire("rows"); const rows = zrequire("rows");
const lightbox = zrequire("lightbox"); const lightbox = zrequire("lightbox");

View File

@ -2,14 +2,14 @@
const {strict: assert} = require("assert"); 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 {run_test} = require("../zjsunit/test");
// We need these stubs to get by instanceof checks. // We need these stubs to get by instanceof checks.
// The ListWidget library allows you to insert objects // The ListWidget library allows you to insert objects
// that are either jQuery, Element, or just raw HTML // that are either jQuery, Element, or just raw HTML
// strings. We initially test with raw strings. // strings. We initially test with raw strings.
const ui = mock_module("ui"); const ui = mock_esm("../../static/js/ui");
set_global("Element", () => {}); set_global("Element", () => {});
set_global("jQuery", "stub"); set_global("jQuery", "stub");

View File

@ -2,17 +2,17 @@
const {strict: assert} = require("assert"); 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 {run_test} = require("../zjsunit/test");
const condense = mock_module("condense"); const condense = mock_esm("../../static/js/condense");
const message_edit = mock_module("message_edit"); const message_edit = mock_esm("../../static/js/message_edit");
const message_list = mock_module("message_list"); const message_list = mock_esm("../../static/js/message_list");
const notifications = mock_module("notifications"); const notifications = mock_esm("../../static/js/notifications");
const page_params = set_global("page_params", {}); const page_params = set_global("page_params", {});
const pm_list = mock_module("pm_list"); const pm_list = mock_esm("../../static/js/pm_list");
const stream_list = mock_module("stream_list"); const stream_list = mock_esm("../../static/js/stream_list");
const unread_ui = mock_module("unread_ui"); const unread_ui = mock_esm("../../static/js/unread_ui");
set_global("current_msg_list", {}); set_global("current_msg_list", {});
const people = zrequire("people"); const people = zrequire("people");

View File

@ -4,7 +4,7 @@ const {strict: assert} = require("assert");
const _ = require("lodash"); 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 {run_test} = require("../zjsunit/test");
const $ = require("../zjsunit/zjquery"); const $ = require("../zjsunit/zjquery");
@ -15,28 +15,28 @@ const noop = () => {};
function MessageListView() { function MessageListView() {
return {}; return {};
} }
mock_module("message_list_view", { mock_esm("../../static/js/message_list_view", {
MessageListView, MessageListView,
}); });
mock_module("recent_topics", { mock_esm("../../static/js/recent_topics", {
process_messages: noop, process_messages: noop,
}); });
// Still required for page_params.initial_pointer // Still required for page_params.initial_pointer
set_global("page_params", {}); set_global("page_params", {});
mock_module("ui_report", { mock_esm("../../static/js/ui_report", {
hide_error: noop, hide_error: noop,
}); });
const channel = mock_module("channel"); const channel = mock_esm("../../static/js/channel");
const message_store = mock_module("message_store"); const message_store = mock_esm("../../static/js/message_store");
const message_util = mock_module("message_util"); const message_util = mock_esm("../../static/js/message_util");
const pm_list = mock_module("pm_list"); const pm_list = mock_esm("../../static/js/pm_list");
const server_events = mock_module("server_events"); const server_events = mock_esm("../../static/js/server_events");
const stream_list = mock_module("stream_list", { const stream_list = mock_esm("../../static/js/stream_list", {
maybe_scroll_narrow_into_view: () => {}, maybe_scroll_narrow_into_view: () => {},
}); });
mock_module("message_scroll", { mock_esm("../../static/js/message_scroll", {
show_loading_older: noop, show_loading_older: noop,
hide_loading_older: noop, hide_loading_older: noop,
show_loading_newer: noop, show_loading_newer: noop,

View File

@ -2,13 +2,13 @@
const {strict: assert} = require("assert"); 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 {run_test} = require("../zjsunit/test");
const channel = mock_module("channel"); const channel = mock_esm("../../static/js/channel");
const ui = mock_module("ui"); const ui = mock_esm("../../static/js/ui");
mock_module("starred_messages", { mock_esm("../../static/js/starred_messages", {
add: () => {}, add: () => {},
remove: () => {}, remove: () => {},

View File

@ -2,7 +2,7 @@
const {strict: assert} = require("assert"); 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 {make_stub} = require("../zjsunit/stub");
const {run_test} = require("../zjsunit/test"); const {run_test} = require("../zjsunit/test");
const $ = require("../zjsunit/zjquery"); const $ = require("../zjsunit/zjquery");
@ -13,7 +13,7 @@ const $ = require("../zjsunit/zjquery");
const noop = function () {}; const noop = function () {};
mock_module("filter", { mock_esm("../../static/js/filter", {
Filter: noop, Filter: noop,
}); });
set_global("document", { set_global("document", {
@ -24,8 +24,8 @@ set_global("document", {
}, },
}); });
const narrow_state = mock_module("narrow_state"); const narrow_state = mock_esm("../../static/js/narrow_state");
const stream_data = mock_module("stream_data"); const stream_data = mock_esm("../../static/js/stream_data");
const muting = zrequire("muting"); const muting = zrequire("muting");
const {MessageList} = zrequire("message_list"); const {MessageList} = zrequire("message_list");

View File

@ -4,7 +4,7 @@ const {strict: assert} = require("assert");
const _ = require("lodash"); 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 {run_test} = require("../zjsunit/test");
set_global("document", "document-stub"); set_global("document", "document-stub");
@ -16,7 +16,7 @@ const page_params = set_global("page_params", {
}); });
set_global("home_msg_list", "stub"); set_global("home_msg_list", "stub");
// timerender calls setInterval when imported // timerender calls setInterval when imported
mock_module("timerender", { mock_esm("../../static/js/timerender", {
render_date(time1, time2) { render_date(time1, time2) {
if (time2 === undefined) { if (time2 === undefined) {
return [{outerHTML: String(time1.getTime())}]; return [{outerHTML: String(time1.getTime())}];
@ -31,7 +31,7 @@ mock_module("timerender", {
}, },
}); });
mock_module("rows", { mock_esm("../../static/js/rows", {
get_table() { get_table() {
return { return {
children() { children() {

View File

@ -2,17 +2,17 @@
const {strict: assert} = require("assert"); 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 {make_stub} = require("../zjsunit/stub");
const {run_test} = require("../zjsunit/test"); const {run_test} = require("../zjsunit/test");
const noop = () => {}; const noop = () => {};
mock_module("stream_topic_history", { mock_esm("../../static/js/stream_topic_history", {
add_message: noop, add_message: noop,
}); });
mock_module("recent_senders", { mock_esm("../../static/js/recent_senders", {
process_message_for_senders: noop, process_message_for_senders: noop,
}); });

View File

@ -2,7 +2,7 @@
const {strict: assert} = require("assert"); 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 {run_test} = require("../zjsunit/test");
const $ = require("../zjsunit/zjquery"); const $ = require("../zjsunit/zjquery");
@ -10,7 +10,7 @@ set_global("page_params", {
stop_words: ["what", "about"], 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 hash_util = zrequire("hash_util");
const compose_state = zrequire("compose_state"); const compose_state = zrequire("compose_state");

View File

@ -2,33 +2,33 @@
const {strict: assert} = require("assert"); 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 {run_test} = require("../zjsunit/test");
mock_module("resize", { mock_esm("../../static/js/resize", {
resize_stream_filters_container: () => {}, resize_stream_filters_container: () => {},
}); });
const channel = mock_module("channel"); const channel = mock_esm("../../static/js/channel");
const compose = mock_module("compose"); const compose = mock_esm("../../static/js/compose");
const compose_actions = mock_module("compose_actions"); const compose_actions = mock_esm("../../static/js/compose_actions");
const hashchange = mock_module("hashchange"); const hashchange = mock_esm("../../static/js/hashchange");
const message_fetch = mock_module("message_fetch"); const message_fetch = mock_esm("../../static/js/message_fetch");
const message_list = mock_module("message_list", { const message_list = mock_esm("../../static/js/message_list", {
set_narrowed(value) { set_narrowed(value) {
message_list.narrowed = value; message_list.narrowed = value;
}, },
}); });
const message_scroll = mock_module("message_scroll"); const message_scroll = mock_esm("../../static/js/message_scroll");
const message_view_header = mock_module("message_view_header"); const message_view_header = mock_esm("../../static/js/message_view_header");
const notifications = mock_module("notifications"); const notifications = mock_esm("../../static/js/notifications");
const search = mock_module("search"); const search = mock_esm("../../static/js/search");
const stream_list = mock_module("stream_list"); const stream_list = mock_esm("../../static/js/stream_list");
const top_left_corner = mock_module("top_left_corner"); const top_left_corner = mock_esm("../../static/js/top_left_corner");
const typing_events = mock_module("typing_events"); const typing_events = mock_esm("../../static/js/typing_events");
const ui_util = mock_module("ui_util"); const ui_util = mock_esm("../../static/js/ui_util");
const unread_ops = mock_module("unread_ops"); const unread_ops = mock_esm("../../static/js/unread_ops");
mock_module("recent_topics", { mock_esm("../../static/js/recent_topics", {
hide: () => {}, hide: () => {},
is_visible: () => {}, is_visible: () => {},
}); });
@ -44,7 +44,7 @@ set_global("setTimeout", (f, t) => {
f(); f();
}); });
mock_module("muting", { mock_esm("../../static/js/muting", {
is_topic_muted: () => false, is_topic_muted: () => false,
}); });

View File

@ -2,10 +2,10 @@
const {strict: assert} = require("assert"); 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 {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 {Filter} = zrequire("../js/filter");
const {MessageListData} = zrequire("../js/message_list_data"); const {MessageListData} = zrequire("../js/message_list_data");

View File

@ -2,11 +2,11 @@
const {strict: assert} = require("assert"); 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 {run_test} = require("../zjsunit/test");
const message_store = mock_module("message_store"); const message_store = mock_esm("../../static/js/message_store");
mock_module("muting", { mock_esm("../../static/js/muting", {
is_topic_muted: () => false, is_topic_muted: () => false,
}); });
set_global("page_params", {}); set_global("page_params", {});

View File

@ -6,10 +6,10 @@ const {parseISO} = require("date-fns");
const _ = require("lodash"); const _ = require("lodash");
const MockDate = require("mockdate"); 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 {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 page_params = set_global("page_params", {});
const people = zrequire("people"); const people = zrequire("people");

View File

@ -2,10 +2,10 @@
const {strict: assert} = require("assert"); 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 {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, is_in_progress: () => false,
}); });

View File

@ -2,22 +2,22 @@
const {strict: assert} = require("assert"); 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 {run_test} = require("../zjsunit/test");
const $ = require("../zjsunit/zjquery"); const $ = require("../zjsunit/zjquery");
const narrow_state = mock_module("narrow_state"); const narrow_state = mock_esm("../../static/js/narrow_state");
const pm_list_dom = mock_module("pm_list_dom"); const pm_list_dom = mock_esm("../../static/js/pm_list_dom");
const unread = mock_module("unread"); const unread = mock_esm("../../static/js/unread");
const unread_ui = mock_module("unread_ui"); const unread_ui = mock_esm("../../static/js/unread_ui");
const vdom = mock_module("vdom", { const vdom = mock_esm("../../static/js/vdom", {
render: () => "fake-dom-for-pm-list", render: () => "fake-dom-for-pm-list",
}); });
mock_module("stream_popover", { mock_esm("../../static/js/stream_popover", {
hide_topic_popover() {}, hide_topic_popover() {},
}); });
mock_module("ui", { mock_esm("../../static/js/ui", {
get_content_element: (element) => element, get_content_element: (element) => element,
}); });

View File

@ -3,21 +3,21 @@
const {strict: assert} = require("assert"); const {strict: assert} = require("assert");
const {stub_templates} = require("../zjsunit/handlebars"); 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 {run_test} = require("../zjsunit/test");
const $ = require("../zjsunit/zjquery"); const $ = require("../zjsunit/zjquery");
const noop = function () {}; const noop = function () {};
const rows = mock_module("rows"); const rows = mock_esm("../../static/js/rows");
const stream_data = mock_module("stream_data"); const stream_data = mock_esm("../../static/js/stream_data");
mock_module("emoji_picker", { mock_esm("../../static/js/emoji_picker", {
hide_emoji_popover: noop, hide_emoji_popover: noop,
}); });
mock_module("message_viewport", { mock_esm("../../static/js/message_viewport", {
height: () => 500, height: () => 500,
}); });
mock_module("stream_popover", { mock_esm("../../static/js/stream_popover", {
hide_stream_popover: noop, hide_stream_popover: noop,
hide_topic_popover: noop, hide_topic_popover: noop,
hide_all_messages_popover: noop, hide_all_messages_popover: noop,

View File

@ -2,13 +2,13 @@
const {strict: assert} = require("assert"); 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 {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, 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 people = zrequire("people");
const presence = zrequire("presence"); const presence = zrequire("presence");

View File

@ -3,7 +3,7 @@
const {strict: assert} = require("assert"); const {strict: assert} = require("assert");
const {stub_templates} = require("../zjsunit/handlebars"); 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 {make_stub} = require("../zjsunit/stub");
const {run_test} = require("../zjsunit/test"); const {run_test} = require("../zjsunit/test");
const $ = require("../zjsunit/zjquery"); const $ = require("../zjsunit/zjquery");
@ -37,11 +37,11 @@ const sample_message = {
], ],
}; };
const channel = mock_module("channel"); const channel = mock_esm("../../static/js/channel");
const emoji_picker = mock_module("emoji_picker", { const emoji_picker = mock_esm("../../static/js/emoji_picker", {
hide_emoji_popover() {}, hide_emoji_popover() {},
}); });
const message_store = mock_module("message_store"); const message_store = mock_esm("../../static/js/message_store");
set_global("current_msg_list", { set_global("current_msg_list", {
selected_message() { selected_message() {

View File

@ -2,7 +2,7 @@
const {strict: assert} = require("assert"); 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 {run_test} = require("../zjsunit/test");
let next_id = 0; let next_id = 0;
@ -23,14 +23,14 @@ function make_stream_message({stream_id, topic, sender_id}) {
return message; return message;
} }
const message_list = mock_module("message_list", { const message_list = mock_esm("../../static/js/message_list", {
all: { all: {
all_messages() { all_messages() {
return Array.from(messages.values()); return Array.from(messages.values());
}, },
}, },
}); });
mock_module("message_store", { mock_esm("../../static/js/message_store", {
get: (message_id) => messages.get(message_id), get: (message_id) => messages.get(message_id),
}); });

View File

@ -3,7 +3,7 @@
const {strict: assert} = require("assert"); const {strict: assert} = require("assert");
const {stub_templates} = require("../zjsunit/handlebars"); 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 {run_test} = require("../zjsunit/test");
const $ = require("../zjsunit/zjquery"); const $ = require("../zjsunit/zjquery");
@ -36,14 +36,14 @@ const topic8 = "topic-8";
const topic9 = "topic-9"; const topic9 = "topic-9";
const topic10 = "topic-10"; const topic10 = "topic-10";
const message_list = mock_module("message_list", { const message_list = mock_esm("../../static/js/message_list", {
all: { all: {
all_messages() { all_messages() {
return messages; return messages;
}, },
}, },
}); });
const ListWidget = mock_module("list_widget", { const ListWidget = mock_esm("../../static/js/list_widget", {
modifier: noop, modifier: noop,
create: (container, mapped_topic_values, opts) => { create: (container, mapped_topic_values, opts) => {
@ -70,27 +70,27 @@ const ListWidget = mock_module("list_widget", {
render_item: (item) => ListWidget.modifier(item), render_item: (item) => ListWidget.modifier(item),
}); });
mock_module("compose_actions", { mock_esm("../../static/js/compose_actions", {
cancel: noop, cancel: noop,
}); });
mock_module("drafts", { mock_esm("../../static/js/drafts", {
update_draft: noop, update_draft: noop,
}); });
mock_module("hash_util", { mock_esm("../../static/js/hash_util", {
by_stream_uri: () => "https://www.example.com", by_stream_uri: () => "https://www.example.com",
by_stream_topic_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, set_narrow_title: noop,
}); });
mock_module("message_store", { mock_esm("../../static/js/message_store", {
get: (msg_id) => messages[msg_id - 1], get: (msg_id) => messages[msg_id - 1],
}); });
mock_module("message_view_header", { mock_esm("../../static/js/message_view_header", {
render_title_area: noop, render_title_area: noop,
}); });
mock_module("muting", { mock_esm("../../static/js/muting", {
is_topic_muted: (stream_id, topic) => { is_topic_muted: (stream_id, topic) => {
if (stream_id === stream1 && topic === topic7) { if (stream_id === stream1 && topic === topic7) {
return true; return true;
@ -98,10 +98,10 @@ mock_module("muting", {
return false; return false;
}, },
}); });
mock_module("recent_senders", { mock_esm("../../static/js/recent_senders", {
get_topic_recent_senders: () => [1, 2], get_topic_recent_senders: () => [1, 2],
}); });
mock_module("stream_data", { mock_esm("../../static/js/stream_data", {
get_sub_by_id: (stream) => { get_sub_by_id: (stream) => {
if (stream === stream5) { if (stream === stream5) {
// No data is available for deactivated streams // No data is available for deactivated streams
@ -120,10 +120,10 @@ mock_module("stream_data", {
false, false,
id_is_subscribed: () => true, id_is_subscribed: () => true,
}); });
mock_module("stream_list", { mock_esm("../../static/js/stream_list", {
handle_narrow_deactivated: noop, handle_narrow_deactivated: noop,
}); });
mock_module("timerender", { mock_esm("../../static/js/timerender", {
last_seen_status_from_date: () => "Just now", last_seen_status_from_date: () => "Just now",
get_full_datetime: () => ({ get_full_datetime: () => ({
@ -131,10 +131,10 @@ mock_module("timerender", {
time: "time", time: "time",
}), }),
}); });
mock_module("top_left_corner", { mock_esm("../../static/js/top_left_corner", {
narrow_to_recent_topics: noop, narrow_to_recent_topics: noop,
}); });
mock_module("unread", { mock_esm("../../static/js/unread", {
num_unread_for_topic: (stream_id, topic) => { num_unread_for_topic: (stream_id, topic) => {
if (stream_id === 1 && topic === "topic-1") { if (stream_id === 1 && topic === "topic-1") {
// Only stream1, topic-1 is read. // Only stream1, topic-1 is read.

View File

@ -2,11 +2,11 @@
const {strict: assert} = require("assert"); 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 {run_test} = require("../zjsunit/test");
const $ = require("../zjsunit/zjquery"); const $ = require("../zjsunit/zjquery");
mock_module("rtl", { mock_esm("../../static/js/rtl", {
get_direction: () => "ltr", get_direction: () => "ltr",
}); });
const page_params = set_global("page_params", {emojiset: "apple"}); const page_params = set_global("page_params", {emojiset: "apple"});

View File

@ -2,10 +2,10 @@
const {strict: assert} = require("assert"); 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 {run_test} = require("../zjsunit/test");
mock_module("ui", { mock_esm("../../static/js/ui", {
get_scroll_element: (element) => element, get_scroll_element: (element) => element,
}); });

View File

@ -2,24 +2,24 @@
const {strict: assert} = require("assert"); 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 {run_test} = require("../zjsunit/test");
const $ = require("../zjsunit/zjquery"); const $ = require("../zjsunit/zjquery");
const noop = () => {}; const noop = () => {};
const narrow = mock_module("narrow"); const narrow = mock_esm("../../static/js/narrow");
const narrow_state = mock_module("narrow_state", { const narrow_state = mock_esm("../../static/js/narrow_state", {
filter: () => false, 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: { widget: {
getByID: () => true, getByID: () => true,
}, },
}); });
mock_module("ui_util", { mock_esm("../../static/js/ui_util", {
change_tab_to: noop, change_tab_to: noop,
place_caret_at_end: noop, place_caret_at_end: noop,
}); });

View File

@ -2,7 +2,7 @@
const {strict: assert} = require("assert"); 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 {run_test} = require("../zjsunit/test");
const $ = require("../zjsunit/zjquery"); const $ = require("../zjsunit/zjquery");
@ -12,16 +12,16 @@ set_global("page_params", {
const noop = () => {}; const noop = () => {};
const narrow = mock_module("narrow"); const narrow = mock_esm("../../static/js/narrow");
const narrow_state = mock_module("narrow_state"); const narrow_state = mock_esm("../../static/js/narrow_state");
const search_suggestion = mock_module("search_suggestion"); const search_suggestion = mock_esm("../../static/js/search_suggestion");
mock_module("ui_util", { mock_esm("../../static/js/ui_util", {
change_tab_to: noop, change_tab_to: noop,
}); });
const Filter = {}; const Filter = {};
mock_module("filter", { mock_esm("../../static/js/filter", {
Filter, Filter,
}); });

View File

@ -2,14 +2,14 @@
const {strict: assert} = require("assert"); 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 {run_test} = require("../zjsunit/test");
const page_params = set_global("page_params", { const page_params = set_global("page_params", {
search_pills_enabled: true, search_pills_enabled: true,
}); });
mock_module("message_store", { mock_esm("../../static/js/message_store", {
user_ids: () => [], user_ids: () => [],
}); });

View File

@ -2,13 +2,13 @@
const {strict: assert} = require("assert"); 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 {run_test} = require("../zjsunit/test");
const page_params = set_global("page_params", { const page_params = set_global("page_params", {
search_pills_enabled: false, search_pills_enabled: false,
}); });
mock_module("message_store", { mock_esm("../../static/js/message_store", {
user_ids: () => [], user_ids: () => [],
}); });

View File

@ -2,7 +2,7 @@
const {strict: assert} = require("assert"); 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 {run_test} = require("../zjsunit/test");
const noop = () => {}; const noop = () => {};
@ -16,8 +16,8 @@ set_global("document", {
}); });
set_global("addEventListener", noop); set_global("addEventListener", noop);
const channel = mock_module("channel"); const channel = mock_esm("../../static/js/channel");
mock_module("reload_state", { mock_esm("../../static/js/reload_state", {
is_in_progress() { is_in_progress() {
return false; return false;
}, },
@ -33,7 +33,7 @@ set_global("page_params", {test_suite: false});
// we also directly write to pointer // we also directly write to pointer
set_global("pointer", {}); set_global("pointer", {});
mock_module("ui_report", { mock_esm("../../static/js/ui_report", {
hide_error() { hide_error() {
return false; return false;
}, },
@ -42,13 +42,13 @@ mock_module("ui_report", {
}, },
}); });
mock_module("stream_events", { mock_esm("../../static/js/stream_events", {
update_property() { update_property() {
throw new Error("subs update error"); 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() { insert_new_messages() {
throw new Error("insert error"); throw new Error("insert error");
}, },

View File

@ -2,7 +2,7 @@
const {strict: assert} = require("assert"); 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 {run_test} = require("../zjsunit/test");
const $ = require("../zjsunit/zjquery"); 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) { function ClipboardJS(sel) {
assert.equal(sel, "#copy_zuliprc"); assert.equal(sel, "#copy_zuliprc");
} }

View File

@ -2,11 +2,11 @@
const {strict: assert} = require("assert"); 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 {run_test} = require("../zjsunit/test");
const $ = require("../zjsunit/zjquery"); 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"); const settings_emoji = zrequire("settings_emoji");
run_test("build_emoji_upload_widget", () => { run_test("build_emoji_upload_widget", () => {

View File

@ -2,11 +2,11 @@
const {strict: assert} = require("assert"); 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 {run_test} = require("../zjsunit/test");
const $ = require("../zjsunit/zjquery"); 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 settings_muting = zrequire("settings_muting");
const stream_data = zrequire("stream_data"); const stream_data = zrequire("stream_data");

View File

@ -3,7 +3,7 @@
const {strict: assert} = require("assert"); const {strict: assert} = require("assert");
const {stub_templates} = require("../zjsunit/handlebars"); 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 {run_test} = require("../zjsunit/test");
const $ = require("../zjsunit/zjquery"); const $ = require("../zjsunit/zjquery");
@ -32,7 +32,7 @@ const page_params = set_global("page_params", {
realm_authentication_methods: {}, realm_authentication_methods: {},
}); });
const realm_icon = mock_module("realm_icon"); const realm_icon = mock_esm("../../static/js/realm_icon");
stub_templates((name, data) => { stub_templates((name, data) => {
if (name === "settings/admin_realm_domains_list") { if (name === "settings/admin_realm_domains_list") {
@ -42,17 +42,17 @@ stub_templates((name, data) => {
throw new Error(`Unknown template ${name}`); throw new Error(`Unknown template ${name}`);
}); });
const channel = mock_module("channel"); const channel = mock_esm("../../static/js/channel");
const overlays = mock_module("overlays"); const overlays = mock_esm("../../static/js/overlays");
mock_module("list_widget", { mock_esm("../../static/js/list_widget", {
create: () => ({init: noop}), create: () => ({init: noop}),
}); });
mock_module("loading", { mock_esm("../../static/js/loading", {
make_indicator: noop, make_indicator: noop,
destroy_indicator: noop, destroy_indicator: noop,
}); });
mock_module("ui_report", { mock_esm("../../static/js/ui_report", {
success(msg, elem) { success(msg, elem) {
elem.val(msg); elem.val(msg);
}, },

View File

@ -3,11 +3,11 @@
const {strict: assert} = require("assert"); const {strict: assert} = require("assert");
const {stub_templates} = require("../zjsunit/handlebars"); 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 {run_test} = require("../zjsunit/test");
const $ = require("../zjsunit/zjquery"); const $ = require("../zjsunit/zjquery");
const loading = mock_module("loading"); const loading = mock_esm("../../static/js/loading");
const page_params = set_global("page_params", {}); const page_params = set_global("page_params", {});
const SHORT_TEXT_ID = 1; const SHORT_TEXT_ID = 1;

View File

@ -5,7 +5,7 @@ const {strict: assert} = require("assert");
const _ = require("lodash"); const _ = require("lodash");
const {stub_templates} = require("../zjsunit/handlebars"); 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 {run_test} = require("../zjsunit/test");
const $ = require("../zjsunit/zjquery"); const $ = require("../zjsunit/zjquery");
@ -17,16 +17,16 @@ const pills = {
let create_item_handler; let create_item_handler;
const channel = mock_module("channel"); const channel = mock_esm("../../static/js/channel");
const confirm_dialog = mock_module("confirm_dialog"); const confirm_dialog = mock_esm("../../static/js/confirm_dialog");
const input_pill = mock_module("input_pill"); const input_pill = mock_esm("../../static/js/input_pill");
const typeahead_helper = mock_module("typeahead_helper"); const typeahead_helper = mock_esm("../../static/js/typeahead_helper");
const user_groups = mock_module("user_groups", { const user_groups = mock_esm("../../static/js/user_groups", {
get_user_group_from_id: noop, get_user_group_from_id: noop,
remove: noop, remove: noop,
add: 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", {}); const page_params = set_global("page_params", {});

View File

@ -3,7 +3,7 @@
const {strict: assert} = require("assert"); const {strict: assert} = require("assert");
const {stub_templates} = require("../zjsunit/handlebars"); 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 {run_test} = require("../zjsunit/test");
const $ = require("../zjsunit/zjquery"); const $ = require("../zjsunit/zjquery");
@ -11,23 +11,23 @@ const noop = () => {};
stub_templates(() => noop); stub_templates(() => noop);
const page_params = set_global("page_params", {}); const page_params = set_global("page_params", {});
const typeahead_helper = mock_module("typeahead_helper"); const typeahead_helper = mock_esm("../../static/js/typeahead_helper");
const ui = mock_module("ui", { const ui = mock_esm("../../static/js/ui", {
get_scroll_element: noop, get_scroll_element: noop,
}); });
mock_module("hash_util", { mock_esm("../../static/js/hash_util", {
stream_edit_uri: noop, stream_edit_uri: noop,
by_stream_uri: noop, by_stream_uri: noop,
}); });
mock_module("hashchange", {update_browser_history: noop}); mock_esm("../../static/js/hashchange", {update_browser_history: noop});
mock_module("list_widget", { mock_esm("../../static/js/list_widget", {
create: () => ({init: noop}), create: () => ({init: noop}),
}); });
mock_module("settings_notifications", { mock_esm("../../static/js/settings_notifications", {
get_notifications_table_row_data: noop, get_notifications_table_row_data: noop,
}); });
mock_module("stream_color", { mock_esm("../../static/js/stream_color", {
set_colorpicker_color: noop, set_colorpicker_color: noop,
}); });

View File

@ -2,37 +2,37 @@
const {strict: assert} = require("assert"); 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 {make_stub} = require("../zjsunit/stub");
const {run_test} = require("../zjsunit/test"); const {run_test} = require("../zjsunit/test");
const $ = require("../zjsunit/zjquery"); const $ = require("../zjsunit/zjquery");
const noop = () => {}; const noop = () => {};
const color_data = mock_module("color_data"); const color_data = mock_esm("../../static/js/color_data");
const message_util = mock_module("message_util"); const message_util = mock_esm("../../static/js/message_util");
const stream_color = mock_module("stream_color"); const stream_color = mock_esm("../../static/js/stream_color");
const stream_list = mock_module("stream_list"); const stream_list = mock_esm("../../static/js/stream_list");
const stream_muting = mock_module("stream_muting"); const stream_muting = mock_esm("../../static/js/stream_muting");
const subs = mock_module("subs", { const subs = mock_esm("../../static/js/subs", {
update_settings_for_subscribed: noop, update_settings_for_subscribed: noop,
}); });
mock_module("message_list", { mock_esm("../../static/js/message_list", {
all: { all: {
all_messages() { all_messages() {
return ["msg"]; return ["msg"];
}, },
}, },
}); });
mock_module("recent_topics", { mock_esm("../../static/js/recent_topics", {
complete_rerender: () => {}, complete_rerender: () => {},
}); });
mock_module("settings_notifications", { mock_esm("../../static/js/settings_notifications", {
update_page: () => {}, update_page: () => {},
}); });
set_global("current_msg_list", {}); 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 {Filter} = zrequire("../js/filter");
const message_view_header = zrequire("message_view_header"); const message_view_header = zrequire("message_view_header");

View File

@ -3,7 +3,7 @@
const {strict: assert} = require("assert"); const {strict: assert} = require("assert");
const {stub_templates} = require("../zjsunit/handlebars"); 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 {run_test} = require("../zjsunit/test");
const $ = require("../zjsunit/zjquery"); const $ = require("../zjsunit/zjquery");
@ -16,12 +16,12 @@ const page_params = set_global("page_params", {
const noop = () => {}; const noop = () => {};
const narrow_state = mock_module("narrow_state"); const narrow_state = mock_esm("../../static/js/narrow_state");
const topic_list = mock_module("topic_list"); const topic_list = mock_esm("../../static/js/topic_list");
mock_module("keydown_util", { mock_esm("../../static/js/keydown_util", {
handle: noop, 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 {Filter} = zrequire("../js/filter");
const stream_sort = zrequire("stream_sort"); const stream_sort = zrequire("stream_sort");

View File

@ -2,7 +2,7 @@
const {strict: assert} = require("assert"); 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 {run_test} = require("../zjsunit/test");
const $ = require("../zjsunit/zjquery"); const $ = require("../zjsunit/zjquery");
@ -11,14 +11,14 @@ const $ = require("../zjsunit/zjquery");
const noop = () => {}; const noop = () => {};
mock_module("resize", { mock_esm("../../static/js/resize", {
resize_page_components: noop, resize_page_components: noop,
resize_stream_filters_container: noop, resize_stream_filters_container: noop,
}); });
const popovers = mock_module("popovers"); const popovers = mock_esm("../../static/js/popovers");
const stream_popover = mock_module("stream_popover"); const stream_popover = mock_esm("../../static/js/stream_popover");
const stream_list = zrequire("stream_list"); const stream_list = zrequire("stream_list");

View File

@ -2,12 +2,12 @@
const {strict: assert} = require("assert"); 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 {run_test} = require("../zjsunit/test");
const channel = mock_module("channel"); const channel = mock_esm("../../static/js/channel");
const message_list = mock_module("message_list"); const message_list = mock_esm("../../static/js/message_list");
const message_util = mock_module("message_util"); const message_util = mock_esm("../../static/js/message_util");
const unread = zrequire("unread"); const unread = zrequire("unread");
const stream_data = zrequire("stream_data"); const stream_data = zrequire("stream_data");

View File

@ -2,12 +2,12 @@
const {strict: assert} = require("assert"); 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 {run_test} = require("../zjsunit/test");
const channel = mock_module("channel"); const channel = mock_esm("../../static/js/channel");
const message_store = mock_module("message_store"); const message_store = mock_esm("../../static/js/message_store");
const widgetize = mock_module("widgetize"); const widgetize = mock_esm("../../static/js/widgetize");
const submessage = zrequire("submessage"); const submessage = zrequire("submessage");

View File

@ -3,13 +3,13 @@
const {strict: assert} = require("assert"); const {strict: assert} = require("assert");
const {stub_templates} = require("../zjsunit/handlebars"); 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 {run_test} = require("../zjsunit/test");
const $ = require("../zjsunit/zjquery"); const $ = require("../zjsunit/zjquery");
const denmark_stream_id = 101; const denmark_stream_id = 101;
const ui = mock_module("ui", { const ui = mock_esm("../../static/js/ui", {
get_content_element: (element) => element, get_content_element: (element) => element,
get_scroll_element: (element) => element, get_scroll_element: (element) => element,
}); });
@ -17,7 +17,7 @@ const ui = mock_module("ui", {
set_global("location", { set_global("location", {
hash: `#streams/${denmark_stream_id}/announce`, hash: `#streams/${denmark_stream_id}/announce`,
}); });
mock_module("hash_util", { mock_esm("../../static/js/hash_util", {
by_stream_uri: () => {}, by_stream_uri: () => {},
}); });
set_global("page_params", {}); set_global("page_params", {});

View File

@ -2,11 +2,11 @@
const {strict: assert} = require("assert"); 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 {run_test} = require("../zjsunit/test");
const $ = require("../zjsunit/zjquery"); const $ = require("../zjsunit/zjquery");
mock_module("resize", { mock_esm("../../static/js/resize", {
resize_stream_filters_container: () => {}, resize_stream_filters_container: () => {},
}); });
const {Filter} = zrequire("../js/filter"); const {Filter} = zrequire("../js/filter");

View File

@ -4,15 +4,15 @@ const {strict: assert} = require("assert");
const _ = require("lodash"); const _ = require("lodash");
const {mock_module, zrequire} = require("../zjsunit/namespace"); const {mock_esm, zrequire} = require("../zjsunit/namespace");
const {run_test} = require("../zjsunit/test"); const {run_test} = require("../zjsunit/test");
const muting = mock_module("muting", { const muting = mock_esm("../../static/js/muting", {
is_topic_muted() { is_topic_muted() {
return false; return false;
}, },
}); });
const narrow_state = mock_module("narrow_state", { const narrow_state = mock_esm("../../static/js/narrow_state", {
topic() {}, topic() {},
}); });

View File

@ -2,16 +2,16 @@
const {strict: assert} = require("assert"); 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 {run_test} = require("../zjsunit/test");
const noop = () => {}; const noop = () => {};
const page_params = set_global("page_params", {}); const page_params = set_global("page_params", {});
const channel = mock_module("channel"); const channel = mock_esm("../../static/js/channel");
const reload = mock_module("reload"); const reload = mock_esm("../../static/js/reload");
const reload_state = mock_module("reload_state"); const reload_state = mock_esm("../../static/js/reload_state");
const sent_messages = mock_module("sent_messages", { const sent_messages = mock_esm("../../static/js/sent_messages", {
start_tracking_message: noop, start_tracking_message: noop,
report_server_ack: noop, report_server_ack: noop,
}); });

View File

@ -9,13 +9,7 @@
// become clear as you keep reading. // become clear as you keep reading.
const {strict: assert} = require("assert"); const {strict: assert} = require("assert");
const { const {mock_esm, set_global, unmock_module, with_field, zrequire} = require("../zjsunit/namespace");
mock_module,
set_global,
unmock_module,
with_field,
zrequire,
} = require("../zjsunit/namespace");
const {make_stub} = require("../zjsunit/stub"); const {make_stub} = require("../zjsunit/stub");
const {run_test} = require("../zjsunit/test"); 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 // structure that the server sends down to us when the app starts. We
// prefer to test with a clean slate. // prefer to test with a clean slate.
const activity = mock_module("activity"); const activity = mock_esm("../../static/js/activity");
const channel = mock_module("channel"); const channel = mock_esm("../../static/js/channel");
const home_msg_list = set_global("home_msg_list", {}); const home_msg_list = set_global("home_msg_list", {});
const message_list = mock_module("message_list"); const message_list = mock_esm("../../static/js/message_list");
const message_live_update = mock_module("message_live_update"); const message_live_update = mock_esm("../../static/js/message_live_update");
const message_util = mock_module("message_util"); const message_util = mock_esm("../../static/js/message_util");
const message_viewport = mock_module("message_viewport"); const message_viewport = mock_esm("../../static/js/message_viewport");
const notifications = mock_module("notifications"); const notifications = mock_esm("../../static/js/notifications");
const overlays = mock_module("overlays"); const overlays = mock_esm("../../static/js/overlays");
const pm_list = mock_module("pm_list"); const pm_list = mock_esm("../../static/js/pm_list");
const resize = mock_module("resize"); const resize = mock_esm("../../static/js/resize");
const settings_users = mock_module("settings_users"); const settings_users = mock_esm("../../static/js/settings_users");
const topic_list = mock_module("topic_list"); const topic_list = mock_esm("../../static/js/topic_list");
const unread_ui = mock_module("unread_ui"); const unread_ui = mock_esm("../../static/js/unread_ui");
let stream_list = mock_module("stream_list"); let stream_list = mock_esm("../../static/js/stream_list");
let unread_ops = mock_module("unread_ops"); let unread_ops = mock_esm("../../static/js/unread_ops");
set_global("page_params", {}); 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"); unread_ops = zrequire("unread_ops");
run_test("unread_ops", (override) => { 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"); stream_list = zrequire("stream_list");
const social_stream = { const social_stream = {

View File

@ -4,14 +4,14 @@ const {strict: assert} = require("assert");
const _ = require("lodash"); 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 {run_test} = require("../zjsunit/test");
let page_params = set_global("page_params", { let page_params = set_global("page_params", {
realm_push_notifications_enabled: false, realm_push_notifications_enabled: false,
}); });
const message_store = mock_module("message_store", { const message_store = mock_esm("../../static/js/message_store", {
get() {}, get() {},
}); });
const muting = zrequire("muting"); const muting = zrequire("muting");

View File

@ -2,43 +2,43 @@
const {strict: assert} = require("assert"); 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 {run_test} = require("../zjsunit/test");
const message_live_update = mock_module("message_live_update"); const message_live_update = mock_esm("../../static/js/message_live_update");
const settings_account = mock_module("settings_account", { const settings_account = mock_esm("../../static/js/settings_account", {
update_email() {}, update_email() {},
update_full_name() {}, update_full_name() {},
}); });
mock_module("activity", { mock_esm("../../static/js/activity", {
redraw() {}, redraw() {},
}); });
mock_module("compose", { mock_esm("../../static/js/compose", {
update_email() {}, update_email() {},
}); });
mock_module("gear_menu", { mock_esm("../../static/js/gear_menu", {
update_org_settings_menu_item() {}, update_org_settings_menu_item() {},
}); });
mock_module("narrow_state", { mock_esm("../../static/js/narrow_state", {
update_email() {}, update_email() {},
}); });
mock_module("pm_list", { mock_esm("../../static/js/pm_list", {
update_private_messages() {}, update_private_messages() {},
}); });
mock_module("settings_linkifiers", { mock_esm("../../static/js/settings_linkifiers", {
maybe_disable_widgets() {}, maybe_disable_widgets() {},
}); });
mock_module("settings_org", { mock_esm("../../static/js/settings_org", {
maybe_disable_widgets() {}, maybe_disable_widgets() {},
}); });
mock_module("settings_profile_fields", { mock_esm("../../static/js/settings_profile_fields", {
maybe_disable_widgets() {}, maybe_disable_widgets() {},
}); });
mock_module("settings_streams", { mock_esm("../../static/js/settings_streams", {
maybe_disable_widgets() {}, maybe_disable_widgets() {},
}); });
mock_module("settings_users", { mock_esm("../../static/js/settings_users", {
update_user_data() {}, update_user_data() {},
}); });

View File

@ -2,10 +2,10 @@
const {strict: assert} = require("assert"); 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 {run_test} = require("../zjsunit/test");
const channel = mock_module("channel"); const channel = mock_esm("../../static/js/channel");
const user_status = zrequire("user_status"); const user_status = zrequire("user_status");
function initialize() { function initialize() {

View File

@ -2,7 +2,7 @@
const {strict: assert} = require("assert"); 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 {run_test} = require("../zjsunit/test");
const $ = require("../zjsunit/zjquery"); const $ = require("../zjsunit/zjquery");
@ -36,7 +36,7 @@ const events = [
let widget_elem; let widget_elem;
let is_event_handled; let is_event_handled;
let is_widget_activated; let is_widget_activated;
mock_module("poll_widget", { mock_esm("../../static/js/poll_widget", {
activate(data) { activate(data) {
is_widget_activated = true; is_widget_activated = true;
widget_elem = data.elem; widget_elem = data.elem;
@ -52,7 +52,7 @@ mock_module("poll_widget", {
}); });
set_global("document", "document-stub"); 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", {}); set_global("current_msg_list", {});
const widgetize = zrequire("widgetize"); const widgetize = zrequire("widgetize");

View File

@ -3,6 +3,8 @@
const Module = require("module"); const Module = require("module");
const path = require("path"); const path = require("path");
const callsites = require("callsites");
const new_globals = new Set(); const new_globals = new Set();
let old_globals = {}; let old_globals = {};
@ -28,23 +30,16 @@ exports.start = () => {
Module._load = load; Module._load = load;
}; };
exports.mock_module = (short_fn, obj) => { exports.mock_esm = (request, obj = {}) => {
if (obj === undefined) {
obj = {};
}
if (typeof obj !== "object") { 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(".")) { const filename = Module._resolveFilename(
throw new Error(` request,
There is no need for a path like ${short_fn}. require.cache[callsites()[1].getFileName()],
We just assume the file is under static/js. false,
`); );
}
const filename = require.resolve(`../../static/js/${short_fn}`);
if (module_mocks.has(filename)) { if (module_mocks.has(filename)) {
throw new Error(`You already set up a mock for ${filename}`); throw new Error(`You already set up a mock for ${filename}`);
@ -59,8 +54,12 @@ exports.mock_module = (short_fn, obj) => {
return obj; return obj;
}; };
exports.unmock_module = (short_fn) => { exports.unmock_module = (request) => {
const filename = require.resolve(`../../static/js/${short_fn}`); const filename = Module._resolveFilename(
request,
require.cache[callsites()[1].getFileName()],
false,
);
if (!module_mocks.has(filename)) { if (!module_mocks.has(filename)) {
throw new Error(`Cannot unmock ${filename}, which was not mocked`); throw new Error(`Cannot unmock ${filename}, which was not mocked`);

View File

@ -19,6 +19,7 @@
"babel-loader": "^8.0.6", "babel-loader": "^8.0.6",
"blueimp-md5": "^2.10.0", "blueimp-md5": "^2.10.0",
"cache-loader": "^4.0.0", "cache-loader": "^4.0.0",
"callsites": "^3.1.0",
"clean-css": "^5.1.0", "clean-css": "^5.1.0",
"clipboard": "^2.0.4", "clipboard": "^2.0.4",
"core-js": "^3.6.5", "core-js": "^3.6.5",

View File

@ -2740,7 +2740,7 @@ callsites@^2.0.0:
resolved "https://registry.yarnpkg.com/callsites/-/callsites-2.0.0.tgz#06eb84f00eea413da86affefacbffb36093b3c50" resolved "https://registry.yarnpkg.com/callsites/-/callsites-2.0.0.tgz#06eb84f00eea413da86affefacbffb36093b3c50"
integrity sha1-BuuE8A7qQT2oav/vrL/7Ngk7PFA= integrity sha1-BuuE8A7qQT2oav/vrL/7Ngk7PFA=
callsites@^3.0.0: callsites@^3.0.0, callsites@^3.1.0:
version "3.1.0" version "3.1.0"
resolved "https://registry.yarnpkg.com/callsites/-/callsites-3.1.0.tgz#b3630abd8943432f54b3f0519238e33cd7df2f73" resolved "https://registry.yarnpkg.com/callsites/-/callsites-3.1.0.tgz#b3630abd8943432f54b3f0519238e33cd7df2f73"
integrity sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ== integrity sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ==