node: Provide a default window object for the node tests.

This is preparation for our migration of our JS pipeline to webpack,
which includes as part of the process a hack of exporting globals via
the window object.
This commit is contained in:
Tim Abbott 2018-05-31 14:55:28 -07:00
parent 47824a97a4
commit c8db7b7dd7
12 changed files with 23 additions and 19 deletions

View File

@ -75,7 +75,6 @@ set_global('reload', {
set_global('resize', {
resize_page_components: () => {},
});
set_global('window', 'window-stub');
const me = {
email: 'me@zulip.com',

View File

@ -13,7 +13,7 @@ set_global('document', {
location: {},
});
set_global('transmit', {});
set_global('window', {
global.patch_builtin('window', {
bridge: false,
});
set_global('channel', {});

View File

@ -1,7 +1,6 @@
var noop = function () {};
set_global('document', 'document-stub');
set_global('window', {});
set_global('$', function () {
return {
trigger: noop,

View File

@ -1,6 +1,5 @@
set_global('$', global.make_zjquery());
set_global('i18n', global.stub_i18n);
set_global('window', {});
zrequire('localstorage');
zrequire('drafts');

View File

@ -1,3 +1,9 @@
global.patch_builtin('window', {
location: {
protocol: 'http:',
host: 'example.com',
},
});
zrequire('people');
zrequire('hash_util');
zrequire('hashchange');
@ -5,12 +11,6 @@ zrequire('stream_data');
set_global('document', 'document-stub');
set_global('history', {});
set_global('window', {
location: {
protocol: 'http:',
host: 'example.com',
},
});
set_global('admin', {});
set_global('drafts', {});
@ -346,4 +346,3 @@ run_test('save_narrow', () => {
]);
assert.equal(url_pushed, 'http://example.com/#narrow/is/starred');
});

View File

@ -12,7 +12,7 @@ zrequire('emoji');
zrequire('message_store');
zrequire('markdown');
set_global('window', {
global.patch_builtin('window', {
location: {
origin: 'http://zulip.zulipdev.com',
},

View File

@ -8,7 +8,6 @@ set_global('document', {
return true;
},
});
set_global('window', {});
set_global('page_params', {
is_admin: false,
realm_users: [],

View File

@ -1,7 +1,7 @@
var noop = function () {};
set_global('document', {});
set_global('window', {
global.patch_builtin('window', {
addEventListener: noop,
});
global.stub_out_jquery();

View File

@ -2,7 +2,7 @@ global.stub_out_jquery();
set_global('ui', {});
set_global('stream_data', {});
set_global('window', {
global.patch_builtin('window', {
location: {
hash: "#streams/1/announce",
},
@ -212,4 +212,3 @@ run_test('filter_table', () => {
subs.filter_table({input: "", subscribed_only: false});
assert($(".stream-row[data-stream-id='1']").hasClass("active"));
});

View File

@ -8,7 +8,7 @@ set_global('navigator', {
set_global('i18n', global.stub_i18n);
set_global('page_params', { });
set_global('csrf_token', { });
set_global('window', {
global.patch_builtin('window', {
bridge: false,
});

View File

@ -1,6 +1,5 @@
set_global('$', global.make_zjquery());
set_global('document', {});
set_global('window', {});
zrequire('util');

View File

@ -4,9 +4,20 @@ var fs = require('fs');
global.assert = require('assert');
require('node_modules/string.prototype.codepointat/codepointat.js');
global.Dict = require('js/dict');
global._ = require('node_modules/underscore/underscore.js');
var _ = global._;
const windowObj = {
location: {
hash: '#',
},
};
global.window = _.extend({}, windowObj, {
to_$: () => {
return windowObj;
},
});
global.Dict = require('js/dict');
// Create a helper function to avoid sneaky delays in tests.
function immediate(f) {