2018-04-12 22:50:09 +02:00
|
|
|
var path = require('path');
|
|
|
|
var fs = require('fs');
|
|
|
|
|
2014-02-03 16:48:04 +01:00
|
|
|
global.assert = require('assert');
|
2017-01-08 07:43:10 +01:00
|
|
|
require('node_modules/string.prototype.codepointat/codepointat.js');
|
2013-08-20 06:15:41 +02:00
|
|
|
|
2014-02-01 15:44:52 +01:00
|
|
|
global.Dict = require('js/dict');
|
2017-01-08 09:36:18 +01:00
|
|
|
global._ = require('node_modules/underscore/underscore.js');
|
2014-02-01 15:44:52 +01:00
|
|
|
var _ = global._;
|
|
|
|
|
2018-04-25 15:25:30 +02:00
|
|
|
// Create a helper function to avoid sneaky delays in tests.
|
|
|
|
function immediate(f) {
|
|
|
|
return () => {
|
|
|
|
return f();
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-07-30 18:14:42 +02:00
|
|
|
// Find the files we need to run.
|
|
|
|
var finder = require('./finder.js');
|
|
|
|
var files = finder.find_files_to_run(); // may write to console
|
|
|
|
if (_.isEmpty(files)) {
|
|
|
|
throw "No tests found";
|
|
|
|
}
|
|
|
|
|
2016-07-30 17:00:12 +02:00
|
|
|
// Set up our namespace helpers.
|
|
|
|
var namespace = require('./namespace.js');
|
|
|
|
global.set_global = namespace.set_global;
|
|
|
|
global.patch_builtin = namespace.patch_builtin;
|
2017-08-09 18:26:03 +02:00
|
|
|
global.zrequire = namespace.zrequire;
|
2016-07-30 20:01:15 +02:00
|
|
|
global.stub_out_jquery = namespace.stub_out_jquery;
|
2017-03-11 21:07:24 +01:00
|
|
|
global.with_overrides = namespace.with_overrides;
|
2016-07-30 17:00:12 +02:00
|
|
|
|
2017-03-11 19:45:10 +01:00
|
|
|
// Set up stub helpers.
|
|
|
|
var stub = require('./stub.js');
|
|
|
|
global.with_stub = stub.with_stub;
|
|
|
|
|
2016-07-30 17:18:38 +02:00
|
|
|
// Set up helpers to render templates.
|
|
|
|
var render = require('./render.js');
|
2016-11-04 16:07:00 +01:00
|
|
|
global.find_included_partials = render.find_included_partials;
|
2016-11-04 16:34:27 +01:00
|
|
|
global.compile_template = render.compile_template;
|
|
|
|
global.render_template = render.render_template;
|
2016-11-02 06:45:06 +01:00
|
|
|
global.walk = render.walk;
|
2016-07-30 17:18:38 +02:00
|
|
|
|
2017-05-23 03:20:15 +02:00
|
|
|
// Set up fake jQuery
|
2017-05-25 01:49:29 +02:00
|
|
|
global.make_zjquery = require('./zjquery.js').make_zjquery;
|
2017-05-23 03:20:15 +02:00
|
|
|
|
2018-04-09 10:01:24 +02:00
|
|
|
// Set up fake blueslip
|
|
|
|
global.make_zblueslip = require('./zblueslip.js').make_zblueslip;
|
|
|
|
|
2017-06-28 10:16:34 +02:00
|
|
|
// Set up fake translation
|
2017-06-29 20:46:27 +02:00
|
|
|
global.stub_i18n = require('./i18n.js');
|
2017-06-28 10:16:34 +02:00
|
|
|
|
2016-08-05 21:42:19 +02:00
|
|
|
var noop = function () {};
|
2013-08-21 23:53:00 +02:00
|
|
|
|
2017-07-16 21:14:03 +02:00
|
|
|
// Set up fake module.hot
|
|
|
|
// eslint-disable-next-line no-native-reassign
|
|
|
|
module = require('module');
|
|
|
|
module.prototype.hot = {
|
|
|
|
accept: noop,
|
|
|
|
};
|
|
|
|
|
2018-04-12 22:50:09 +02:00
|
|
|
// Set up fixtures.
|
|
|
|
global.read_fixture_data = (fn) => {
|
2018-04-19 20:17:24 +02:00
|
|
|
var full_fn = path.join(__dirname, '../../zerver/tests/fixtures/', fn);
|
2018-04-12 22:50:09 +02:00
|
|
|
var data = JSON.parse(fs.readFileSync(full_fn, 'utf8', 'r'));
|
|
|
|
return data;
|
|
|
|
};
|
|
|
|
|
2018-05-14 21:37:36 +02:00
|
|
|
function short_tb(tb) {
|
|
|
|
const lines = tb.split('\n');
|
|
|
|
|
|
|
|
var i = _.findIndex(lines, (line) => {
|
2018-05-15 12:40:07 +02:00
|
|
|
return line.includes('run_test') || line.includes('run_one_module');
|
2018-05-14 21:37:36 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
if (i === -1) {
|
|
|
|
return tb;
|
|
|
|
}
|
|
|
|
|
|
|
|
return lines.splice(0, i+1).join('\n') + '\n(...)\n';
|
|
|
|
}
|
|
|
|
|
2017-12-10 09:01:37 +01:00
|
|
|
// Set up bugdown comparison helper
|
|
|
|
global.bugdown_assert = require('./bugdown_assert.js');
|
|
|
|
|
2018-05-14 21:37:36 +02:00
|
|
|
function run_one_module(file) {
|
2016-07-30 18:14:42 +02:00
|
|
|
console.info('running tests for ' + file.name);
|
|
|
|
require(file.full_name);
|
2018-05-14 21:37:36 +02:00
|
|
|
}
|
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
global.run_test = (label, f) => {
|
|
|
|
if (files.length === 1) {
|
|
|
|
console.info(' test: ' + label);
|
|
|
|
}
|
|
|
|
f();
|
|
|
|
};
|
|
|
|
|
2018-05-14 21:37:36 +02:00
|
|
|
try {
|
|
|
|
files.forEach(function (file) {
|
|
|
|
global.patch_builtin('setTimeout', noop);
|
|
|
|
global.patch_builtin('setInterval', noop);
|
|
|
|
_.throttle = immediate;
|
|
|
|
_.debounce = immediate;
|
|
|
|
|
|
|
|
render.init();
|
|
|
|
run_one_module(file);
|
|
|
|
namespace.restore();
|
|
|
|
});
|
|
|
|
} catch (e) {
|
|
|
|
if (e.stack) {
|
|
|
|
console.info(short_tb(e.stack));
|
|
|
|
} else {
|
|
|
|
console.info(e);
|
|
|
|
}
|
|
|
|
process.exit(1);
|
|
|
|
}
|