mirror of https://github.com/zulip/zulip.git
zjsunit: Remove set_global side effect from zrequire.
ES6 and TS modules don’t insert themselves into `window`, so our tests shouldn’t insert them either. Since the test `window` behaves like `global` now, we can rely on legacy modules that do insert themselves to do it themselves. Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
This commit is contained in:
parent
99563eb150
commit
428956c086
|
@ -3,7 +3,7 @@ set_global('i18n', global.stub_i18n);
|
|||
|
||||
zrequire('localstorage');
|
||||
zrequire('drafts');
|
||||
zrequire('XDate', 'xdate');
|
||||
set_global('XDate', zrequire('XDate', 'xdate'));
|
||||
zrequire('timerender');
|
||||
set_global('Handlebars', global.make_handlebars());
|
||||
zrequire('util');
|
||||
|
|
|
@ -5,7 +5,7 @@ set_global('page_params', {
|
|||
set_global('upload_widget', {});
|
||||
set_global('blueslip', global.make_zblueslip());
|
||||
|
||||
zrequire('emoji_codes', 'generated/emoji/emoji_codes');
|
||||
set_global('emoji_codes', zrequire('emoji_codes', 'generated/emoji/emoji_codes'));
|
||||
zrequire('emoji');
|
||||
zrequire('markdown');
|
||||
zrequire('util');
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
zrequire('emoji_codes', 'generated/emoji/emoji_codes');
|
||||
set_global('emoji_codes', zrequire('emoji_codes', 'generated/emoji/emoji_codes'));
|
||||
zrequire('emoji');
|
||||
zrequire('emoji_picker');
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
set_global('Handlebars', global.make_handlebars());
|
||||
zrequire('templates');
|
||||
zrequire('i18n', 'i18next');
|
||||
set_global('i18n', zrequire('i18n', 'i18next'));
|
||||
|
||||
i18n.init({
|
||||
nsSeparator: false,
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
zrequire('hash_util');
|
||||
zrequire('katex', 'katex/dist/katex.min.js');
|
||||
zrequire('marked', 'third/marked/lib/marked');
|
||||
set_global('katex', zrequire('katex', 'katex/dist/katex.min.js'));
|
||||
set_global('marked', zrequire('marked', 'third/marked/lib/marked'));
|
||||
zrequire('util');
|
||||
zrequire('fenced_code');
|
||||
zrequire('stream_data');
|
||||
zrequire('people');
|
||||
zrequire('user_groups');
|
||||
zrequire('emoji_codes', 'generated/emoji/emoji_codes');
|
||||
set_global('emoji_codes', zrequire('emoji_codes', 'generated/emoji/emoji_codes'));
|
||||
zrequire('emoji');
|
||||
zrequire('message_store');
|
||||
zrequire('markdown');
|
||||
|
|
|
@ -3,7 +3,7 @@ set_global('page_params', {});
|
|||
|
||||
global.stub_out_jquery();
|
||||
|
||||
zrequire('XDate', 'xdate/src/xdate');
|
||||
set_global('XDate', zrequire('XDate', 'xdate/src/xdate'));
|
||||
zrequire('message_edit');
|
||||
|
||||
const get_editability = message_edit.get_editability;
|
||||
|
|
|
@ -2,7 +2,7 @@ set_global('$', global.make_zjquery());
|
|||
set_global('document', 'document-stub');
|
||||
|
||||
zrequire('util');
|
||||
zrequire('XDate', 'xdate/src/xdate');
|
||||
set_global('XDate', zrequire('XDate', 'xdate/src/xdate'));
|
||||
zrequire('Filter', 'js/filter');
|
||||
zrequire('FetchStatus', 'js/fetch_status');
|
||||
zrequire('MessageListData', 'js/message_list_data');
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
zrequire('zxcvbn', 'zxcvbn');
|
||||
set_global('zxcvbn', zrequire('zxcvbn', 'zxcvbn'));
|
||||
zrequire('common');
|
||||
|
||||
set_global('i18n', global.stub_i18n);
|
||||
|
|
|
@ -172,8 +172,8 @@ run_test('user_timezone', () => {
|
|||
global.page_params.twenty_four_hour_time = false;
|
||||
assert.deepEqual(people.get_user_time_preferences(me.user_id), expected_pref);
|
||||
|
||||
zrequire('actual_moment', 'moment-timezone');
|
||||
set_global('moment', function () { return global.actual_moment('20130208T080910'); });
|
||||
const actual_moment = zrequire('actual_moment', 'moment-timezone');
|
||||
set_global('moment', function () { return actual_moment('20130208T080910'); });
|
||||
|
||||
global.page_params.twenty_four_hour_time = true;
|
||||
assert.equal(people.get_user_time(me.user_id), '0:09');
|
||||
|
|
|
@ -3,7 +3,7 @@ set_global('i18n', global.stub_i18n);
|
|||
set_global('page_params', {
|
||||
twenty_four_hour_time: true,
|
||||
});
|
||||
zrequire('XDate', 'xdate');
|
||||
set_global('XDate', zrequire('XDate', 'xdate'));
|
||||
zrequire('timerender');
|
||||
|
||||
run_test('render_now_returns_today', () => {
|
||||
|
|
|
@ -14,7 +14,7 @@ zrequire('stream_data');
|
|||
zrequire('narrow');
|
||||
zrequire('hash_util');
|
||||
zrequire('marked', 'third/marked/lib/marked');
|
||||
zrequire('actual_pygments_data', 'generated/pygments_data');
|
||||
const actual_pygments_data = zrequire('actual_pygments_data', 'generated/pygments_data');
|
||||
zrequire('settings_org');
|
||||
const th = zrequire('typeahead_helper');
|
||||
|
||||
|
@ -111,7 +111,7 @@ run_test('sort_languages', () => {
|
|||
// We may eventually want to use human-readable names like
|
||||
// "JavaScript" with several machine-readable aliases for what the
|
||||
// user typed, which might help provide a better user experience.
|
||||
global.pygments_data = global.actual_pygments_data;
|
||||
global.pygments_data = actual_pygments_data;
|
||||
test_langs = ["j", "java", "javascript", "js"];
|
||||
|
||||
// Sort acccording to priority only.
|
||||
|
|
|
@ -92,7 +92,7 @@ zrequire('user_groups');
|
|||
zrequire('unread');
|
||||
zrequire('bot_data');
|
||||
zrequire('message_fetch');
|
||||
zrequire('marked', 'third/marked/lib/marked');
|
||||
set_global('marked', zrequire('marked', 'third/marked/lib/marked'));
|
||||
zrequire('fenced_code');
|
||||
zrequire('markdown');
|
||||
zrequire('upload');
|
||||
|
@ -117,7 +117,8 @@ zrequire('top_left_corner');
|
|||
zrequire('starred_messages');
|
||||
zrequire('user_status');
|
||||
zrequire('user_status_ui');
|
||||
zrequire('ui_init');
|
||||
const ui_init = zrequire('ui_init');
|
||||
|
||||
zrequire('settings_display');
|
||||
|
||||
set_global('$', global.make_zjquery());
|
||||
|
|
|
@ -23,10 +23,8 @@ exports.zrequire = function (name, fn) {
|
|||
fn = '../../static/' + fn;
|
||||
}
|
||||
delete require.cache[require.resolve(fn)];
|
||||
const obj = require(fn);
|
||||
requires.push(fn);
|
||||
set_global(name, obj);
|
||||
return obj;
|
||||
return require(fn);
|
||||
};
|
||||
|
||||
exports.restore = function () {
|
||||
|
|
Loading…
Reference in New Issue