mirror of https://github.com/zulip/zulip.git
zjquery: Make zjquery a singleton.
We no longer export make_zjquery(). We now instead have a singleton zjquery instance that we attach to global.$ in index.js. We call $.clear_all_elements() before each module. (We will soon get even more aggressive about doing it in run_test.) Test functions can still override $ with set_global. A good example of this is copy_and_paste using the real jquery module. We no longer exempt $ as a global variable, so test modules that use the zjquery $ need to do: const $ = require("../zjsunit/zjquery");
This commit is contained in:
parent
2e3406f0b8
commit
64c7eb67eb
|
@ -108,7 +108,6 @@
|
|||
{
|
||||
"files": ["frontend_tests/node_tests/**"],
|
||||
"globals": {
|
||||
"$": false,
|
||||
"blueslip": false,
|
||||
"current_msg_list": false,
|
||||
"home_msg_list": false,
|
||||
|
|
|
@ -4,9 +4,8 @@ const {strict: assert} = require("assert");
|
|||
|
||||
const {set_global, zrequire} = require("../zjsunit/namespace");
|
||||
const {run_test} = require("../zjsunit/test");
|
||||
const {make_zjquery} = require("../zjsunit/zjquery");
|
||||
const $ = require("../zjsunit/zjquery");
|
||||
|
||||
set_global("$", make_zjquery());
|
||||
const window_stub = $.create("window-stub");
|
||||
set_global("to_$", () => window_stub);
|
||||
$(window).idle = () => {};
|
||||
|
|
|
@ -5,9 +5,7 @@ const {strict: assert} = require("assert");
|
|||
const {stub_templates} = require("../zjsunit/handlebars");
|
||||
const {set_global, zrequire} = require("../zjsunit/namespace");
|
||||
const {run_test} = require("../zjsunit/test");
|
||||
const {make_zjquery} = require("../zjsunit/zjquery");
|
||||
|
||||
set_global("$", make_zjquery());
|
||||
const $ = require("../zjsunit/zjquery");
|
||||
|
||||
const channel = set_global("channel", {});
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ const {JSDOM} = require("jsdom");
|
|||
|
||||
const {set_global, zrequire} = require("../zjsunit/namespace");
|
||||
const {run_test} = require("../zjsunit/test");
|
||||
const {make_zjquery} = require("../zjsunit/zjquery");
|
||||
const $ = require("../zjsunit/zjquery");
|
||||
|
||||
const noop = () => {};
|
||||
const template = fs.readFileSync("templates/corporate/billing.html", "utf-8");
|
||||
|
@ -21,8 +21,6 @@ const StripeCheckout = set_global("StripeCheckout", {
|
|||
configure: noop,
|
||||
});
|
||||
|
||||
set_global("$", make_zjquery());
|
||||
|
||||
run_test("initialize", () => {
|
||||
let token_func;
|
||||
|
||||
|
|
|
@ -8,13 +8,12 @@ const {JSDOM} = require("jsdom");
|
|||
|
||||
const {set_global, zrequire} = require("../zjsunit/namespace");
|
||||
const {run_test} = require("../zjsunit/test");
|
||||
const {make_zjquery} = require("../zjsunit/zjquery");
|
||||
const $ = require("../zjsunit/zjquery");
|
||||
|
||||
const template = fs.readFileSync("templates/corporate/upgrade.html", "utf-8");
|
||||
const dom = new JSDOM(template, {pretendToBeVisual: true});
|
||||
const jquery = jQueryFactory(dom.window);
|
||||
|
||||
set_global("$", make_zjquery());
|
||||
set_global("page_params", {});
|
||||
const loading = set_global("loading", {});
|
||||
const history = set_global("history", {});
|
||||
|
|
|
@ -6,12 +6,10 @@ const _ = require("lodash");
|
|||
|
||||
const {set_global, zrequire} = require("../zjsunit/namespace");
|
||||
const {run_test} = require("../zjsunit/test");
|
||||
const {make_zjquery} = require("../zjsunit/zjquery");
|
||||
|
||||
const _page_params = {};
|
||||
|
||||
set_global("page_params", _page_params);
|
||||
set_global("$", make_zjquery());
|
||||
const people = zrequire("people");
|
||||
const presence = zrequire("presence");
|
||||
const user_status = zrequire("user_status");
|
||||
|
|
|
@ -6,9 +6,8 @@ const _ = require("lodash");
|
|||
|
||||
const {set_global, zrequire} = require("../zjsunit/namespace");
|
||||
const {run_test} = require("../zjsunit/test");
|
||||
const {make_zjquery} = require("../zjsunit/zjquery");
|
||||
const $ = require("../zjsunit/zjquery");
|
||||
|
||||
set_global("$", make_zjquery());
|
||||
const people = zrequire("people");
|
||||
zrequire("buddy_data");
|
||||
const buddy_list = zrequire("buddy_list");
|
||||
|
|
|
@ -6,8 +6,7 @@ const _ = require("lodash");
|
|||
|
||||
const {set_global, zrequire} = require("../zjsunit/namespace");
|
||||
const {run_test} = require("../zjsunit/test");
|
||||
|
||||
set_global("$", {});
|
||||
const $ = require("../zjsunit/zjquery");
|
||||
|
||||
const reload = set_global("reload", {});
|
||||
zrequire("reload_state");
|
||||
|
|
|
@ -4,11 +4,10 @@ const {strict: assert} = require("assert");
|
|||
|
||||
const {set_global, zrequire} = require("../zjsunit/namespace");
|
||||
const {run_test} = require("../zjsunit/test");
|
||||
const {make_zjquery} = require("../zjsunit/zjquery");
|
||||
const $ = require("../zjsunit/zjquery");
|
||||
|
||||
const noop = () => {};
|
||||
|
||||
set_global("$", make_zjquery());
|
||||
set_global("document", {});
|
||||
|
||||
const common = zrequire("common");
|
||||
|
|
|
@ -9,7 +9,7 @@ const rewiremock = require("rewiremock/node");
|
|||
const {stub_templates} = require("../zjsunit/handlebars");
|
||||
const {set_global, zrequire} = require("../zjsunit/namespace");
|
||||
const {run_test} = require("../zjsunit/test");
|
||||
const {make_zjquery} = require("../zjsunit/zjquery");
|
||||
const $ = require("../zjsunit/zjquery");
|
||||
|
||||
const events = require("./lib/events");
|
||||
|
||||
|
@ -17,7 +17,6 @@ set_global("bridge", false);
|
|||
|
||||
const noop = function () {};
|
||||
|
||||
set_global("$", make_zjquery());
|
||||
set_global("DOMParser", new JSDOM().window.DOMParser);
|
||||
set_global("compose_actions", {
|
||||
update_placeholder_text: noop,
|
||||
|
|
|
@ -4,7 +4,7 @@ const {strict: assert} = require("assert");
|
|||
|
||||
const {set_global, zrequire} = require("../zjsunit/namespace");
|
||||
const {run_test} = require("../zjsunit/test");
|
||||
const {make_zjquery} = require("../zjsunit/zjquery");
|
||||
const $ = require("../zjsunit/zjquery");
|
||||
|
||||
const noop = function () {};
|
||||
const return_false = function () {
|
||||
|
@ -20,8 +20,6 @@ set_global("document", {
|
|||
|
||||
set_global("page_params", {});
|
||||
|
||||
set_global("$", make_zjquery());
|
||||
|
||||
const compose_pm_pill = set_global("compose_pm_pill", {});
|
||||
|
||||
const hash_util = set_global("hash_util", {});
|
||||
|
|
|
@ -2,11 +2,9 @@
|
|||
|
||||
const {strict: assert} = require("assert");
|
||||
|
||||
const {set_global, zrequire} = require("../zjsunit/namespace");
|
||||
const {zrequire} = require("../zjsunit/namespace");
|
||||
const {run_test} = require("../zjsunit/test");
|
||||
const {make_zjquery} = require("../zjsunit/zjquery");
|
||||
|
||||
set_global("$", make_zjquery());
|
||||
const $ = require("../zjsunit/zjquery");
|
||||
|
||||
const people = zrequire("people");
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ const autosize = require("autosize");
|
|||
|
||||
const {set_global, zrequire} = require("../zjsunit/namespace");
|
||||
const {run_test} = require("../zjsunit/test");
|
||||
const {make_zjquery} = require("../zjsunit/zjquery");
|
||||
const $ = require("../zjsunit/zjquery");
|
||||
|
||||
const compose_ui = zrequire("compose_ui");
|
||||
const people = zrequire("people");
|
||||
|
@ -18,8 +18,6 @@ set_global("document", {
|
|||
},
|
||||
});
|
||||
|
||||
set_global("$", make_zjquery());
|
||||
|
||||
const alice = {
|
||||
email: "alice@zulip.com",
|
||||
user_id: 101,
|
||||
|
|
|
@ -4,7 +4,7 @@ const {strict: assert} = require("assert");
|
|||
|
||||
const {set_global, zrequire} = require("../zjsunit/namespace");
|
||||
const {run_test} = require("../zjsunit/test");
|
||||
const {make_zjquery} = require("../zjsunit/zjquery");
|
||||
const $ = require("../zjsunit/zjquery");
|
||||
|
||||
const emoji = zrequire("emoji", "shared/js/emoji");
|
||||
const typeahead = zrequire("typeahead", "shared/js/typeahead");
|
||||
|
@ -171,8 +171,6 @@ stream_data.add_sub(sweden_stream);
|
|||
stream_data.add_sub(denmark_stream);
|
||||
stream_data.add_sub(netherland_stream);
|
||||
|
||||
set_global("$", make_zjquery());
|
||||
|
||||
set_global("page_params", {});
|
||||
const channel = set_global("channel", {});
|
||||
const compose = set_global("compose", {
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
const {strict: assert} = require("assert");
|
||||
|
||||
const jquery = require("jquery");
|
||||
const {JSDOM} = require("jsdom");
|
||||
|
||||
const {set_global, zrequire} = require("../zjsunit/namespace");
|
||||
|
@ -14,7 +15,7 @@ const compose_ui = set_global("compose_ui", {});
|
|||
|
||||
const {window} = new JSDOM("<!DOCTYPE html><p>Hello world</p>");
|
||||
const {DOMParser, document} = window;
|
||||
set_global("$", require("jquery")(window));
|
||||
const $ = set_global("$", jquery(window));
|
||||
|
||||
set_global("DOMParser", DOMParser);
|
||||
set_global("document", document);
|
||||
|
|
|
@ -5,7 +5,7 @@ const {strict: assert} = require("assert");
|
|||
const {set_global, zrequire} = require("../zjsunit/namespace");
|
||||
const {make_stub} = require("../zjsunit/stub");
|
||||
const {run_test} = require("../zjsunit/test");
|
||||
const {make_zjquery} = require("../zjsunit/zjquery");
|
||||
const $ = require("../zjsunit/zjquery");
|
||||
|
||||
const noop = function () {};
|
||||
|
||||
|
@ -16,8 +16,6 @@ const test_message = events.test_message;
|
|||
const test_user = events.test_user;
|
||||
const typing_person1 = events.typing_person1;
|
||||
|
||||
set_global("$", make_zjquery());
|
||||
|
||||
set_global("setTimeout", (func) => func());
|
||||
|
||||
const activity = set_global("activity", {});
|
||||
|
|
|
@ -5,9 +5,7 @@ const {strict: assert} = require("assert");
|
|||
const {stub_templates} = require("../zjsunit/handlebars");
|
||||
const {set_global, zrequire, with_overrides} = require("../zjsunit/namespace");
|
||||
const {run_test} = require("../zjsunit/test");
|
||||
const {make_zjquery} = require("../zjsunit/zjquery");
|
||||
|
||||
set_global("$", make_zjquery());
|
||||
const $ = require("../zjsunit/zjquery");
|
||||
|
||||
const localstorage = zrequire("localstorage");
|
||||
const drafts = zrequire("drafts");
|
||||
|
|
|
@ -4,11 +4,10 @@ const {strict: assert} = require("assert");
|
|||
|
||||
const {set_global, zrequire} = require("../zjsunit/namespace");
|
||||
const {run_test} = require("../zjsunit/test");
|
||||
const {make_zjquery} = require("../zjsunit/zjquery");
|
||||
const $ = require("../zjsunit/zjquery");
|
||||
|
||||
const dropdown_list_widget = zrequire("dropdown_list_widget");
|
||||
zrequire("scroll_util");
|
||||
set_global("$", make_zjquery());
|
||||
|
||||
const noop = () => {};
|
||||
const _ListWidget = {
|
||||
|
|
|
@ -6,9 +6,7 @@ const MockDate = require("mockdate");
|
|||
|
||||
const {set_global, zrequire} = require("../zjsunit/namespace");
|
||||
const {run_test} = require("../zjsunit/test");
|
||||
const {make_zjquery} = require("../zjsunit/zjquery");
|
||||
|
||||
set_global("$", make_zjquery());
|
||||
const local_message = set_global("local_message", {});
|
||||
const markdown = set_global("markdown", {});
|
||||
set_global("page_params", {});
|
||||
|
|
|
@ -4,12 +4,11 @@ const {strict: assert} = require("assert");
|
|||
|
||||
const {set_global, zrequire} = require("../zjsunit/namespace");
|
||||
const {run_test} = require("../zjsunit/test");
|
||||
const {make_zjquery} = require("../zjsunit/zjquery");
|
||||
const $ = require("../zjsunit/zjquery");
|
||||
|
||||
zrequire("unread");
|
||||
const stream_data = zrequire("stream_data");
|
||||
const people = zrequire("people");
|
||||
set_global("$", make_zjquery());
|
||||
zrequire("message_util", "js/message_util");
|
||||
const Filter = zrequire("Filter", "js/filter");
|
||||
|
||||
|
|
|
@ -4,7 +4,6 @@ const {strict: assert} = require("assert");
|
|||
|
||||
const {set_global, zrequire} = require("../zjsunit/namespace");
|
||||
const {run_test} = require("../zjsunit/test");
|
||||
const {make_zjquery} = require("../zjsunit/zjquery");
|
||||
|
||||
const hash_util = zrequire("hash_util");
|
||||
const stream_data = zrequire("stream_data");
|
||||
|
@ -12,8 +11,6 @@ const people = zrequire("people");
|
|||
const Filter = zrequire("Filter", "js/filter");
|
||||
const narrow_state = zrequire("narrow_state");
|
||||
|
||||
set_global("$", make_zjquery());
|
||||
|
||||
const ui_report = set_global("ui_report", {
|
||||
displayed_error: false,
|
||||
error: () => {
|
||||
|
|
|
@ -4,9 +4,8 @@ const {strict: assert} = require("assert");
|
|||
|
||||
const {set_global, zrequire} = require("../zjsunit/namespace");
|
||||
const {run_test} = require("../zjsunit/test");
|
||||
const {make_zjquery} = require("../zjsunit/zjquery");
|
||||
const $ = require("../zjsunit/zjquery");
|
||||
|
||||
set_global("$", make_zjquery());
|
||||
const window_stub = $.create("window-stub");
|
||||
set_global("location", {
|
||||
protocol: "http:",
|
||||
|
|
|
@ -5,7 +5,6 @@ const {strict: assert} = require("assert");
|
|||
const {set_global, with_overrides, zrequire} = require("../zjsunit/namespace");
|
||||
const {make_stub} = require("../zjsunit/stub");
|
||||
const {run_test} = require("../zjsunit/test");
|
||||
const {make_zjquery} = require("../zjsunit/zjquery");
|
||||
|
||||
// Important note on these tests:
|
||||
//
|
||||
|
@ -32,7 +31,6 @@ let overlays = set_global("overlays", {});
|
|||
|
||||
// jQuery stuff should go away if we make an initialize() method.
|
||||
set_global("document", "document-stub");
|
||||
set_global("$", make_zjquery());
|
||||
|
||||
const emoji = zrequire("emoji", "shared/js/emoji");
|
||||
|
||||
|
|
|
@ -4,9 +4,8 @@ const {strict: assert} = require("assert");
|
|||
|
||||
const {set_global, zrequire} = require("../zjsunit/namespace");
|
||||
const {run_test} = require("../zjsunit/test");
|
||||
const {make_zjquery} = require("../zjsunit/zjquery");
|
||||
const $ = require("../zjsunit/zjquery");
|
||||
|
||||
set_global("$", make_zjquery());
|
||||
const input_pill = zrequire("input_pill");
|
||||
|
||||
zrequire("templates");
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
"use strict";
|
||||
|
||||
const {set_global, zrequire} = require("../zjsunit/namespace");
|
||||
const {zrequire} = require("../zjsunit/namespace");
|
||||
const {run_test} = require("../zjsunit/test");
|
||||
const {make_zjquery} = require("../zjsunit/zjquery");
|
||||
|
||||
set_global("$", make_zjquery());
|
||||
const $ = require("../zjsunit/zjquery");
|
||||
|
||||
const keydown_util = zrequire("keydown_util");
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ const {strict: assert} = require("assert");
|
|||
|
||||
const {set_global, zrequire} = require("../zjsunit/namespace");
|
||||
const {run_test} = require("../zjsunit/test");
|
||||
const {make_zjquery} = require("../zjsunit/zjquery");
|
||||
const $ = require("../zjsunit/zjquery");
|
||||
|
||||
const rows = zrequire("rows");
|
||||
const lightbox = zrequire("lightbox");
|
||||
|
@ -22,8 +22,6 @@ set_global("popovers", {
|
|||
|
||||
rows.is_draft_row = () => false;
|
||||
|
||||
set_global("$", make_zjquery());
|
||||
|
||||
run_test("pan_and_zoom", () => {
|
||||
$.clear_all_elements();
|
||||
|
||||
|
|
|
@ -6,7 +6,6 @@ const markdown_test_cases = require("../../zerver/tests/fixtures/markdown_test_c
|
|||
const markdown_assert = require("../zjsunit/markdown_assert");
|
||||
const {set_global, zrequire} = require("../zjsunit/namespace");
|
||||
const {run_test} = require("../zjsunit/test");
|
||||
const {make_zjquery} = require("../zjsunit/zjquery");
|
||||
|
||||
zrequire("hash_util");
|
||||
|
||||
|
@ -62,8 +61,6 @@ fenced_code.initialize(pygments_data);
|
|||
const doc = "";
|
||||
set_global("document", doc);
|
||||
|
||||
set_global("$", make_zjquery());
|
||||
|
||||
const cordelia = {
|
||||
full_name: "Cordelia Lear",
|
||||
user_id: 101,
|
||||
|
|
|
@ -4,7 +4,6 @@ const {strict: assert} = require("assert");
|
|||
|
||||
const {set_global, zrequire} = require("../zjsunit/namespace");
|
||||
const {run_test} = require("../zjsunit/test");
|
||||
const {make_zjquery} = require("../zjsunit/zjquery");
|
||||
|
||||
const message_events = zrequire("message_events");
|
||||
const message_store = zrequire("message_store");
|
||||
|
@ -15,7 +14,6 @@ const stream_data = zrequire("stream_data");
|
|||
const stream_topic_history = zrequire("stream_topic_history");
|
||||
const unread = zrequire("unread");
|
||||
|
||||
set_global("$", make_zjquery());
|
||||
const condense = set_global("condense", {});
|
||||
set_global("current_msg_list", {});
|
||||
const message_edit = set_global("message_edit", {});
|
||||
|
|
|
@ -6,9 +6,8 @@ const _ = require("lodash");
|
|||
|
||||
const {set_global, zrequire} = require("../zjsunit/namespace");
|
||||
const {run_test} = require("../zjsunit/test");
|
||||
const {make_zjquery} = require("../zjsunit/zjquery");
|
||||
const $ = require("../zjsunit/zjquery");
|
||||
|
||||
set_global("$", make_zjquery());
|
||||
set_global("document", "document-stub");
|
||||
|
||||
const message_fetch = zrequire("message_fetch");
|
||||
|
|
|
@ -5,6 +5,7 @@ const {strict: assert} = require("assert");
|
|||
const {set_global, stub_out_jquery, zrequire} = require("../zjsunit/namespace");
|
||||
const {make_stub} = require("../zjsunit/stub");
|
||||
const {run_test} = require("../zjsunit/test");
|
||||
|
||||
// These unit tests for static/js/message_list.js emphasize the model-ish
|
||||
// aspects of the MessageList class. We have to stub out a few functions
|
||||
// related to views and events to get the tests working.
|
||||
|
@ -31,7 +32,7 @@ function accept_all_filter() {
|
|||
return filter;
|
||||
}
|
||||
|
||||
run_test("basics", () => {
|
||||
run_test("basics", (override) => {
|
||||
const filter = accept_all_filter();
|
||||
|
||||
const list = new MessageList({
|
||||
|
@ -74,9 +75,9 @@ run_test("basics", () => {
|
|||
|
||||
assert.deepEqual(list.all_messages(), messages);
|
||||
|
||||
$.Event = function (ev) {
|
||||
override(global.$, "Event", (ev) => {
|
||||
assert.equal(ev, "message_selected.zulip");
|
||||
};
|
||||
});
|
||||
list.select_id(50);
|
||||
|
||||
assert.equal(list.selected_id(), 50);
|
||||
|
|
|
@ -6,9 +6,7 @@ const _ = require("lodash");
|
|||
|
||||
const {set_global, zrequire} = require("../zjsunit/namespace");
|
||||
const {run_test} = require("../zjsunit/test");
|
||||
const {make_zjquery} = require("../zjsunit/zjquery");
|
||||
|
||||
set_global("$", make_zjquery());
|
||||
set_global("document", "document-stub");
|
||||
|
||||
const Filter = zrequire("Filter", "js/filter");
|
||||
|
|
|
@ -5,7 +5,6 @@ const {strict: assert} = require("assert");
|
|||
const {set_global, zrequire} = require("../zjsunit/namespace");
|
||||
const {make_stub} = require("../zjsunit/stub");
|
||||
const {run_test} = require("../zjsunit/test");
|
||||
const {make_zjquery} = require("../zjsunit/zjquery");
|
||||
|
||||
const util = zrequire("util");
|
||||
const people = zrequire("people");
|
||||
|
@ -13,7 +12,6 @@ const message_store = zrequire("message_store");
|
|||
|
||||
const noop = function () {};
|
||||
|
||||
set_global("$", make_zjquery());
|
||||
set_global("document", "document-stub");
|
||||
|
||||
set_global("stream_topic_history", {
|
||||
|
|
|
@ -4,9 +4,8 @@ const {strict: assert} = require("assert");
|
|||
|
||||
const {set_global, zrequire} = require("../zjsunit/namespace");
|
||||
const {run_test} = require("../zjsunit/test");
|
||||
const {make_zjquery} = require("../zjsunit/zjquery");
|
||||
const $ = require("../zjsunit/zjquery");
|
||||
|
||||
set_global("$", make_zjquery());
|
||||
const hash_util = zrequire("hash_util");
|
||||
zrequire("hashchange");
|
||||
const narrow_state = zrequire("narrow_state");
|
||||
|
|
|
@ -4,10 +4,8 @@ const {strict: assert} = require("assert");
|
|||
|
||||
const {set_global, zrequire} = require("../zjsunit/namespace");
|
||||
const {run_test} = require("../zjsunit/test");
|
||||
const {make_zjquery} = require("../zjsunit/zjquery");
|
||||
|
||||
const util = zrequire("util");
|
||||
set_global("$", make_zjquery());
|
||||
|
||||
const narrow_state = zrequire("narrow_state");
|
||||
set_global("resize", {
|
||||
|
|
|
@ -6,10 +6,9 @@ const rewiremock = require("rewiremock/node");
|
|||
|
||||
const {set_global, zrequire} = require("../zjsunit/namespace");
|
||||
const {run_test} = require("../zjsunit/test");
|
||||
const {make_zjquery} = require("../zjsunit/zjquery");
|
||||
|
||||
// Dependencies
|
||||
set_global("$", make_zjquery());
|
||||
|
||||
set_global("document", {
|
||||
hasFocus() {
|
||||
return true;
|
||||
|
|
|
@ -4,9 +4,7 @@ const {strict: assert} = require("assert");
|
|||
|
||||
const {set_global, with_field, zrequire} = require("../zjsunit/namespace");
|
||||
const {run_test} = require("../zjsunit/test");
|
||||
const {make_zjquery} = require("../zjsunit/zjquery");
|
||||
|
||||
set_global("$", make_zjquery());
|
||||
const $ = require("../zjsunit/zjquery");
|
||||
|
||||
const narrow_state = set_global("narrow_state", {});
|
||||
set_global("ui", {
|
||||
|
|
|
@ -3,14 +3,12 @@
|
|||
const {strict: assert} = require("assert");
|
||||
|
||||
const {stub_templates} = require("../zjsunit/handlebars");
|
||||
const {set_global, zrequire} = require("../zjsunit/namespace");
|
||||
const {zrequire} = require("../zjsunit/namespace");
|
||||
const {run_test} = require("../zjsunit/test");
|
||||
const {make_zjquery} = require("../zjsunit/zjquery");
|
||||
const $ = require("../zjsunit/zjquery");
|
||||
|
||||
const poll_widget = zrequire("poll_widget");
|
||||
|
||||
set_global("$", make_zjquery());
|
||||
|
||||
const people = zrequire("people");
|
||||
|
||||
const return_false = () => false;
|
||||
|
|
|
@ -7,9 +7,7 @@ const rewiremock = require("rewiremock/node");
|
|||
const {stub_templates} = require("../zjsunit/handlebars");
|
||||
const {set_global, zrequire} = require("../zjsunit/namespace");
|
||||
const {run_test} = require("../zjsunit/test");
|
||||
const {make_zjquery} = require("../zjsunit/zjquery");
|
||||
|
||||
set_global("$", make_zjquery());
|
||||
const $ = require("../zjsunit/zjquery");
|
||||
|
||||
zrequire("hash_util");
|
||||
zrequire("narrow");
|
||||
|
|
|
@ -6,10 +6,9 @@ const {stub_templates} = require("../zjsunit/handlebars");
|
|||
const {set_global, zrequire} = require("../zjsunit/namespace");
|
||||
const {make_stub} = require("../zjsunit/stub");
|
||||
const {run_test} = require("../zjsunit/test");
|
||||
const {make_zjquery} = require("../zjsunit/zjquery");
|
||||
const $ = require("../zjsunit/zjquery");
|
||||
|
||||
set_global("document", "document-stub");
|
||||
set_global("$", make_zjquery());
|
||||
|
||||
const emoji_codes = zrequire("emoji_codes", "generated/emoji/emoji_codes.json");
|
||||
const emoji = zrequire("emoji", "shared/js/emoji");
|
||||
|
|
|
@ -5,12 +5,12 @@ const {strict: assert} = require("assert");
|
|||
const {stub_templates} = require("../zjsunit/handlebars");
|
||||
const {reset_module, set_global, zrequire} = require("../zjsunit/namespace");
|
||||
const {run_test} = require("../zjsunit/test");
|
||||
const {make_zjquery} = require("../zjsunit/zjquery");
|
||||
const $ = require("../zjsunit/zjquery");
|
||||
|
||||
zrequire("message_util");
|
||||
|
||||
const noop = () => {};
|
||||
set_global("$", make_zjquery());
|
||||
|
||||
set_global("hashchange", {
|
||||
exit_overlay: noop,
|
||||
});
|
||||
|
|
|
@ -4,14 +4,13 @@ const {strict: assert} = require("assert");
|
|||
|
||||
const {set_global, zrequire} = require("../zjsunit/namespace");
|
||||
const {run_test} = require("../zjsunit/test");
|
||||
const {make_zjquery} = require("../zjsunit/zjquery");
|
||||
const $ = require("../zjsunit/zjquery");
|
||||
|
||||
const rm = zrequire("rendered_markdown");
|
||||
const people = zrequire("people");
|
||||
const user_groups = zrequire("user_groups");
|
||||
const stream_data = zrequire("stream_data");
|
||||
zrequire("timerender");
|
||||
set_global("$", make_zjquery());
|
||||
|
||||
set_global("rtl", {
|
||||
get_direction: () => "ltr",
|
||||
|
|
|
@ -4,7 +4,7 @@ const {strict: assert} = require("assert");
|
|||
|
||||
const {set_global, zrequire} = require("../zjsunit/namespace");
|
||||
const {run_test} = require("../zjsunit/test");
|
||||
const {make_zjquery} = require("../zjsunit/zjquery");
|
||||
const $ = require("../zjsunit/zjquery");
|
||||
|
||||
set_global("page_params", {
|
||||
search_pills_enabled: true,
|
||||
|
@ -18,7 +18,6 @@ const noop = () => {};
|
|||
const return_true = () => true;
|
||||
const return_false = () => false;
|
||||
|
||||
set_global("$", make_zjquery());
|
||||
const narrow_state = set_global("narrow_state", {filter: return_false});
|
||||
const search_suggestion = set_global("search_suggestion", {});
|
||||
set_global("ui_util", {
|
||||
|
|
|
@ -4,7 +4,7 @@ const {strict: assert} = require("assert");
|
|||
|
||||
const {set_global, zrequire} = require("../zjsunit/namespace");
|
||||
const {run_test} = require("../zjsunit/test");
|
||||
const {make_zjquery} = require("../zjsunit/zjquery");
|
||||
const $ = require("../zjsunit/zjquery");
|
||||
|
||||
set_global("page_params", {
|
||||
search_pills_enabled: false,
|
||||
|
@ -16,7 +16,6 @@ const noop = () => {};
|
|||
const return_true = () => true;
|
||||
const return_false = () => false;
|
||||
|
||||
set_global("$", make_zjquery());
|
||||
const narrow_state = set_global("narrow_state", {});
|
||||
const search_suggestion = set_global("search_suggestion", {});
|
||||
set_global("ui_util", {
|
||||
|
|
|
@ -6,7 +6,7 @@ const rewiremock = require("rewiremock/node");
|
|||
|
||||
const {set_global, zrequire} = require("../zjsunit/namespace");
|
||||
const {run_test} = require("../zjsunit/test");
|
||||
const {make_zjquery} = require("../zjsunit/zjquery");
|
||||
const $ = require("../zjsunit/zjquery");
|
||||
|
||||
set_global("page_params", {
|
||||
realm_uri: "https://chat.example.com",
|
||||
|
@ -31,8 +31,6 @@ const bot_data_params = {
|
|||
|
||||
const avatar = set_global("avatar", {});
|
||||
|
||||
set_global("$", make_zjquery());
|
||||
|
||||
const bot_data = zrequire("bot_data");
|
||||
|
||||
function ClipboardJS(sel) {
|
||||
|
|
|
@ -4,9 +4,8 @@ const {strict: assert} = require("assert");
|
|||
|
||||
const {set_global, zrequire} = require("../zjsunit/namespace");
|
||||
const {run_test} = require("../zjsunit/test");
|
||||
const {make_zjquery} = require("../zjsunit/zjquery");
|
||||
const $ = require("../zjsunit/zjquery");
|
||||
|
||||
set_global("$", make_zjquery());
|
||||
const upload_widget = set_global("upload_widget", {});
|
||||
const settings_emoji = zrequire("settings_emoji");
|
||||
|
||||
|
|
|
@ -4,9 +4,7 @@ const {strict: assert} = require("assert");
|
|||
|
||||
const {set_global, zrequire} = require("../zjsunit/namespace");
|
||||
const {run_test} = require("../zjsunit/test");
|
||||
const {make_zjquery} = require("../zjsunit/zjquery");
|
||||
|
||||
set_global("$", make_zjquery());
|
||||
const $ = require("../zjsunit/zjquery");
|
||||
|
||||
zrequire("timerender");
|
||||
const settings_muting = zrequire("settings_muting");
|
||||
|
|
|
@ -7,9 +7,7 @@ const rewiremock = require("rewiremock/node");
|
|||
const {stub_templates} = require("../zjsunit/handlebars");
|
||||
const {set_global, zrequire} = require("../zjsunit/namespace");
|
||||
const {run_test} = require("../zjsunit/test");
|
||||
const {make_zjquery} = require("../zjsunit/zjquery");
|
||||
|
||||
set_global("$", make_zjquery());
|
||||
const $ = require("../zjsunit/zjquery");
|
||||
|
||||
const noop = () => {};
|
||||
|
||||
|
|
|
@ -7,10 +7,9 @@ const rewiremock = require("rewiremock/node");
|
|||
const {stub_templates} = require("../zjsunit/handlebars");
|
||||
const {set_global, zrequire} = require("../zjsunit/namespace");
|
||||
const {run_test} = require("../zjsunit/test");
|
||||
const {make_zjquery} = require("../zjsunit/zjquery");
|
||||
const $ = require("../zjsunit/zjquery");
|
||||
|
||||
set_global("page_params", {});
|
||||
set_global("$", make_zjquery());
|
||||
const loading = set_global("loading", {});
|
||||
|
||||
const SHORT_TEXT_ID = 1;
|
||||
|
|
|
@ -7,12 +7,11 @@ const _ = require("lodash");
|
|||
const {stub_templates} = require("../zjsunit/handlebars");
|
||||
const {set_global, zrequire} = require("../zjsunit/namespace");
|
||||
const {run_test} = require("../zjsunit/test");
|
||||
const {make_zjquery} = require("../zjsunit/zjquery");
|
||||
const $ = require("../zjsunit/zjquery");
|
||||
|
||||
const user_pill = zrequire("user_pill");
|
||||
const settings_user_groups = zrequire("settings_user_groups");
|
||||
|
||||
set_global("$", make_zjquery());
|
||||
const confirm_dialog = set_global("confirm_dialog", {});
|
||||
|
||||
const noop = function () {};
|
||||
|
|
|
@ -2,11 +2,10 @@
|
|||
|
||||
const {strict: assert} = require("assert");
|
||||
|
||||
const {set_global, zrequire} = require("../zjsunit/namespace");
|
||||
const {zrequire} = require("../zjsunit/namespace");
|
||||
const {run_test} = require("../zjsunit/test");
|
||||
const {make_zjquery} = require("../zjsunit/zjquery");
|
||||
const $ = require("../zjsunit/zjquery");
|
||||
|
||||
set_global("$", make_zjquery());
|
||||
const spoilers = zrequire("spoilers");
|
||||
|
||||
// This function is taken from rendered_markdown.js and slightly modified.
|
||||
|
|
|
@ -5,7 +5,7 @@ const {strict: assert} = require("assert");
|
|||
const {stub_templates} = require("../zjsunit/handlebars");
|
||||
const {set_global, zrequire} = require("../zjsunit/namespace");
|
||||
const {run_test} = require("../zjsunit/test");
|
||||
const {make_zjquery} = require("../zjsunit/zjquery");
|
||||
const $ = require("../zjsunit/zjquery");
|
||||
|
||||
const noop = () => {};
|
||||
stub_templates(() => noop);
|
||||
|
@ -30,7 +30,6 @@ const typeahead_helper = set_global("typeahead_helper", {});
|
|||
const ui = set_global("ui", {
|
||||
get_scroll_element: noop,
|
||||
});
|
||||
set_global("$", make_zjquery());
|
||||
|
||||
zrequire("input_pill");
|
||||
const peer_data = zrequire("peer_data");
|
||||
|
|
|
@ -5,13 +5,12 @@ const {strict: assert} = require("assert");
|
|||
const {set_global, zrequire} = require("../zjsunit/namespace");
|
||||
const {make_stub} = require("../zjsunit/stub");
|
||||
const {run_test} = require("../zjsunit/test");
|
||||
const {make_zjquery} = require("../zjsunit/zjquery");
|
||||
const $ = require("../zjsunit/zjquery");
|
||||
|
||||
const noop = function () {};
|
||||
const return_true = function () {
|
||||
return true;
|
||||
};
|
||||
set_global("$", make_zjquery());
|
||||
const _settings_notifications = {
|
||||
update_page: () => {},
|
||||
};
|
||||
|
|
|
@ -5,10 +5,9 @@ const {strict: assert} = require("assert");
|
|||
const {stub_templates} = require("../zjsunit/handlebars");
|
||||
const {set_global, zrequire} = require("../zjsunit/namespace");
|
||||
const {run_test} = require("../zjsunit/test");
|
||||
const {make_zjquery} = require("../zjsunit/zjquery");
|
||||
const $ = require("../zjsunit/zjquery");
|
||||
|
||||
set_global("document", "document-stub");
|
||||
set_global("$", make_zjquery());
|
||||
|
||||
zrequire("unread_ui");
|
||||
const Filter = zrequire("Filter", "js/filter");
|
||||
|
|
|
@ -4,11 +4,10 @@ const {strict: assert} = require("assert");
|
|||
|
||||
const {set_global, zrequire} = require("../zjsunit/namespace");
|
||||
const {run_test} = require("../zjsunit/test");
|
||||
const {make_zjquery} = require("../zjsunit/zjquery");
|
||||
// This tests the stream searching functionality which currently
|
||||
const $ = require("../zjsunit/zjquery");
|
||||
|
||||
// lives in stream_list.js.
|
||||
|
||||
set_global("$", make_zjquery());
|
||||
const stream_list = zrequire("stream_list");
|
||||
|
||||
const noop = () => {};
|
||||
|
|
|
@ -5,7 +5,7 @@ const {strict: assert} = require("assert");
|
|||
const {stub_templates} = require("../zjsunit/handlebars");
|
||||
const {set_global, zrequire} = require("../zjsunit/namespace");
|
||||
const {run_test} = require("../zjsunit/test");
|
||||
const {make_zjquery} = require("../zjsunit/zjquery");
|
||||
const $ = require("../zjsunit/zjquery");
|
||||
|
||||
const ui = set_global("ui", {
|
||||
get_content_element: (element) => element,
|
||||
|
@ -22,7 +22,6 @@ set_global("location", {
|
|||
|
||||
const subs = zrequire("subs");
|
||||
|
||||
set_global("$", make_zjquery());
|
||||
set_global("hash_util", {
|
||||
by_stream_uri: () => {},
|
||||
});
|
||||
|
|
|
@ -5,16 +5,14 @@ const fs = require("fs");
|
|||
|
||||
const {JSDOM} = require("jsdom");
|
||||
|
||||
const {set_global, zrequire} = require("../zjsunit/namespace");
|
||||
const {zrequire} = require("../zjsunit/namespace");
|
||||
const {run_test} = require("../zjsunit/test");
|
||||
const {make_zjquery} = require("../zjsunit/zjquery");
|
||||
const $ = require("../zjsunit/zjquery");
|
||||
|
||||
const template = fs.readFileSync("templates/analytics/realm_details.html", "utf-8");
|
||||
const dom = new JSDOM(template, {pretendToBeVisual: true});
|
||||
const document = dom.window.document;
|
||||
|
||||
set_global("$", make_zjquery());
|
||||
|
||||
run_test("scrub_realm", () => {
|
||||
zrequire("support", "js/analytics/support");
|
||||
const click_handler = $("body").get_on_handler("click", ".scrub-realm-button");
|
||||
|
|
|
@ -7,9 +7,8 @@ const MockDate = require("mockdate");
|
|||
|
||||
const {set_global, zrequire} = require("../zjsunit/namespace");
|
||||
const {run_test} = require("../zjsunit/test");
|
||||
const {make_zjquery} = require("../zjsunit/zjquery");
|
||||
const $ = require("../zjsunit/zjquery");
|
||||
|
||||
set_global("$", make_zjquery());
|
||||
set_global("page_params", {
|
||||
twenty_four_hour_time: true,
|
||||
});
|
||||
|
|
|
@ -4,9 +4,7 @@ const {strict: assert} = require("assert");
|
|||
|
||||
const {set_global, zrequire} = require("../zjsunit/namespace");
|
||||
const {run_test} = require("../zjsunit/test");
|
||||
const {make_zjquery} = require("../zjsunit/zjquery");
|
||||
|
||||
set_global("$", make_zjquery());
|
||||
const $ = require("../zjsunit/zjquery");
|
||||
|
||||
const Filter = zrequire("Filter", "js/filter");
|
||||
zrequire("unread_ui");
|
||||
|
|
|
@ -4,11 +4,9 @@ const {strict: assert} = require("assert");
|
|||
|
||||
const {set_global, zrequire} = require("../zjsunit/namespace");
|
||||
const {run_test} = require("../zjsunit/test");
|
||||
const {make_zjquery} = require("../zjsunit/zjquery");
|
||||
|
||||
const noop = function () {};
|
||||
|
||||
set_global("$", make_zjquery());
|
||||
set_global("page_params", {});
|
||||
const channel = set_global("channel", {});
|
||||
const reload = set_global("reload", {});
|
||||
|
|
|
@ -5,7 +5,7 @@ const rewiremock = require("rewiremock/node");
|
|||
const {stub_templates} = require("../zjsunit/handlebars");
|
||||
const {set_global, zrequire} = require("../zjsunit/namespace");
|
||||
const {run_test} = require("../zjsunit/test");
|
||||
const {make_zjquery} = require("../zjsunit/zjquery");
|
||||
const $ = require("../zjsunit/zjquery");
|
||||
|
||||
/*
|
||||
This test suite is designed to find errors
|
||||
|
@ -27,6 +27,7 @@ const {make_zjquery} = require("../zjsunit/zjquery");
|
|||
some things can happen later in a `launch` method.
|
||||
|
||||
*/
|
||||
|
||||
const util = zrequire("util");
|
||||
|
||||
set_global("document", {
|
||||
|
@ -118,7 +119,7 @@ const ui_init = rewiremock.proxy(() => zrequire("ui_init"), {
|
|||
},
|
||||
});
|
||||
|
||||
set_global("$", make_zjquery());
|
||||
set_global("$", $);
|
||||
|
||||
run_test("initialize_everything", () => {
|
||||
util.is_mobile = () => false;
|
||||
|
|
|
@ -7,7 +7,7 @@ const {JSDOM} = require("jsdom");
|
|||
|
||||
const {set_global, zrequire} = require("../zjsunit/namespace");
|
||||
const {run_test} = require("../zjsunit/test");
|
||||
const {make_zjquery} = require("../zjsunit/zjquery");
|
||||
const $ = require("../zjsunit/zjquery");
|
||||
|
||||
const noop = () => {};
|
||||
const template = fs.readFileSync("templates/corporate/upgrade.html", "utf-8");
|
||||
|
@ -26,7 +26,6 @@ set_global("page_params", {
|
|||
});
|
||||
|
||||
const helpers = zrequire("helpers", "js/billing/helpers");
|
||||
set_global("$", make_zjquery());
|
||||
|
||||
run_test("initialize", () => {
|
||||
let token_func;
|
||||
|
|
|
@ -6,9 +6,8 @@ const rewiremock = require("rewiremock/node");
|
|||
|
||||
const {set_global, zrequire} = require("../zjsunit/namespace");
|
||||
const {run_test} = require("../zjsunit/test");
|
||||
const {make_zjquery} = require("../zjsunit/zjquery");
|
||||
const $ = require("../zjsunit/zjquery");
|
||||
|
||||
set_global("$", make_zjquery());
|
||||
set_global("document", {
|
||||
location: {},
|
||||
});
|
||||
|
|
|
@ -4,9 +4,6 @@ const {strict: assert} = require("assert");
|
|||
|
||||
const {set_global, zrequire} = require("../zjsunit/namespace");
|
||||
const {run_test} = require("../zjsunit/test");
|
||||
const {make_zjquery} = require("../zjsunit/zjquery");
|
||||
|
||||
set_global("$", make_zjquery());
|
||||
|
||||
const people = zrequire("people");
|
||||
const settings_config = zrequire("settings_config");
|
||||
|
|
|
@ -7,9 +7,7 @@ const _ = require("lodash");
|
|||
|
||||
const {set_global, with_field, zrequire} = require("../zjsunit/namespace");
|
||||
const {run_test} = require("../zjsunit/test");
|
||||
const {make_zjquery} = require("../zjsunit/zjquery");
|
||||
|
||||
set_global("$", make_zjquery());
|
||||
set_global("DOMParser", new JSDOM().window.DOMParser);
|
||||
set_global("document", {});
|
||||
const util = zrequire("util");
|
||||
|
|
|
@ -4,9 +4,8 @@ const {strict: assert} = require("assert");
|
|||
|
||||
const {set_global, zrequire} = require("../zjsunit/namespace");
|
||||
const {run_test} = require("../zjsunit/test");
|
||||
const {make_zjquery} = require("../zjsunit/zjquery");
|
||||
const $ = require("../zjsunit/zjquery");
|
||||
|
||||
set_global("$", make_zjquery());
|
||||
const poll_widget = set_global("poll_widget", {});
|
||||
set_global("document", "document-stub");
|
||||
|
||||
|
|
|
@ -2,9 +2,8 @@
|
|||
|
||||
const {strict: assert} = require("assert");
|
||||
|
||||
const {set_global} = require("../zjsunit/namespace");
|
||||
const {run_test} = require("../zjsunit/test");
|
||||
const {make_zjquery} = require("../zjsunit/zjquery");
|
||||
const $ = require("../zjsunit/zjquery");
|
||||
|
||||
/*
|
||||
|
||||
|
@ -30,12 +29,6 @@ The code we are testing lives here:
|
|||
|
||||
*/
|
||||
|
||||
// The first thing we do to use zjquery is patch our global namespace
|
||||
// with zjquery as follows. This call gives us our own instance of a
|
||||
// zjquery stub variable. Like with real jQuery, the '$' function will
|
||||
// be the gateway to a bigger API.
|
||||
set_global("$", make_zjquery());
|
||||
|
||||
run_test("basics", () => {
|
||||
// Let's create a sample piece of code to test:
|
||||
|
||||
|
|
|
@ -13,6 +13,8 @@ const namespace = require("./namespace");
|
|||
const test = require("./test");
|
||||
const {make_zblueslip} = require("./zblueslip");
|
||||
|
||||
global.$ = require("./zjquery");
|
||||
|
||||
require("@babel/register")({
|
||||
extensions: [".es6", ".es", ".jsx", ".js", ".mjs", ".ts"],
|
||||
only: [
|
||||
|
@ -66,6 +68,7 @@ function short_tb(tb) {
|
|||
}
|
||||
|
||||
function run_one_module(file) {
|
||||
global.$.clear_all_elements();
|
||||
console.info("running test " + path.basename(file, ".js"));
|
||||
test.set_current_file_name(file);
|
||||
require(file);
|
||||
|
|
|
@ -16,7 +16,7 @@ class Event {
|
|||
stopPropagation() {}
|
||||
}
|
||||
|
||||
exports.make_event_store = (selector) => {
|
||||
function make_event_store(selector) {
|
||||
/*
|
||||
|
||||
This function returns an event_store object that
|
||||
|
@ -144,9 +144,9 @@ exports.make_event_store = (selector) => {
|
|||
};
|
||||
|
||||
return self;
|
||||
};
|
||||
}
|
||||
|
||||
exports.make_new_elem = function (selector, opts) {
|
||||
function make_new_elem(selector, opts) {
|
||||
let html = "never-been-set";
|
||||
let text = "never-been-set";
|
||||
let value;
|
||||
|
@ -160,7 +160,7 @@ exports.make_new_elem = function (selector, opts) {
|
|||
const properties = new Map();
|
||||
const attrs = new Map();
|
||||
const classes = new Map();
|
||||
const event_store = exports.make_event_store(selector);
|
||||
const event_store = make_event_store(selector);
|
||||
|
||||
const self = {
|
||||
addClass(class_name) {
|
||||
|
@ -402,16 +402,16 @@ exports.make_new_elem = function (selector, opts) {
|
|||
self.length = 1;
|
||||
|
||||
return self;
|
||||
};
|
||||
}
|
||||
|
||||
exports.make_zjquery = function () {
|
||||
function make_zjquery() {
|
||||
const elems = new Map();
|
||||
|
||||
// Our fn structure helps us simulate extending jQuery.
|
||||
const fn = {};
|
||||
|
||||
function new_elem(selector, create_opts) {
|
||||
const elem = exports.make_new_elem(selector, {...create_opts});
|
||||
const elem = make_new_elem(selector, {...create_opts});
|
||||
Object.assign(elem, fn);
|
||||
|
||||
// Create a proxy handler to detect missing stubs.
|
||||
|
@ -550,4 +550,6 @@ exports.make_zjquery = function () {
|
|||
};
|
||||
|
||||
return zjquery;
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = make_zjquery();
|
||||
|
|
Loading…
Reference in New Issue