2020-03-20 20:28:31 +00:00
|
|
|
const Module = require('module');
|
|
|
|
const path = require('path');
|
|
|
|
const v8 = require('v8');
|
2019-03-10 22:38:44 +00:00
|
|
|
|
2020-03-20 20:28:31 +00:00
|
|
|
Module.globalPaths.push(path.resolve(__dirname, '../spec/node_modules'));
|
2019-03-10 22:38:44 +00:00
|
|
|
|
|
|
|
// We want to terminate on errors, not throw up a dialog
|
|
|
|
process.on('uncaughtException', (err) => {
|
2020-03-20 20:28:31 +00:00
|
|
|
console.error('Unhandled exception in main spec runner:', err);
|
|
|
|
process.exit(1);
|
|
|
|
});
|
2019-03-10 22:38:44 +00:00
|
|
|
|
|
|
|
// Tell ts-node which tsconfig to use
|
2020-03-20 20:28:31 +00:00
|
|
|
process.env.TS_NODE_PROJECT = path.resolve(__dirname, '../tsconfig.spec.json');
|
|
|
|
process.env.ELECTRON_DISABLE_SECURITY_WARNINGS = 'true';
|
2019-03-10 22:38:44 +00:00
|
|
|
|
2020-03-20 20:28:31 +00:00
|
|
|
const { app, protocol } = require('electron');
|
2019-03-10 22:38:44 +00:00
|
|
|
|
2020-03-20 20:28:31 +00:00
|
|
|
v8.setFlagsFromString('--expose_gc');
|
|
|
|
app.commandLine.appendSwitch('js-flags', '--expose_gc');
|
2019-03-10 22:38:44 +00:00
|
|
|
// Prevent the spec runner quiting when the first window closes
|
2020-03-20 20:28:31 +00:00
|
|
|
app.on('window-all-closed', () => null);
|
2019-03-10 22:38:44 +00:00
|
|
|
|
2019-10-11 20:55:50 +00:00
|
|
|
// Use fake device for Media Stream to replace actual camera and microphone.
|
2020-03-20 20:28:31 +00:00
|
|
|
app.commandLine.appendSwitch('use-fake-device-for-media-stream');
|
2019-10-11 20:55:50 +00:00
|
|
|
|
2020-03-20 20:28:31 +00:00
|
|
|
global.standardScheme = 'app';
|
|
|
|
global.zoomScheme = 'zoom';
|
2019-05-28 21:12:59 +00:00
|
|
|
protocol.registerSchemesAsPrivileged([
|
|
|
|
{ scheme: global.standardScheme, privileges: { standard: true, secure: true } },
|
2019-08-30 00:45:41 +00:00
|
|
|
{ scheme: global.zoomScheme, privileges: { standard: true, secure: true } },
|
2019-05-28 21:12:59 +00:00
|
|
|
{ scheme: 'cors-blob', privileges: { corsEnabled: true, supportFetchAPI: true } },
|
2019-06-27 21:20:29 +00:00
|
|
|
{ scheme: 'cors', privileges: { corsEnabled: true, supportFetchAPI: true } },
|
|
|
|
{ scheme: 'no-cors', privileges: { supportFetchAPI: true } },
|
2020-01-29 12:01:37 +00:00
|
|
|
{ scheme: 'no-fetch', privileges: { corsEnabled: true } },
|
|
|
|
{ scheme: 'foo', privileges: { standard: true } },
|
|
|
|
{ scheme: 'bar', privileges: { standard: true } }
|
2020-03-20 20:28:31 +00:00
|
|
|
]);
|
2019-05-28 21:12:59 +00:00
|
|
|
|
2019-03-10 22:38:44 +00:00
|
|
|
app.whenReady().then(() => {
|
2020-03-20 20:28:31 +00:00
|
|
|
require('ts-node/register');
|
2019-03-10 22:38:44 +00:00
|
|
|
|
|
|
|
const argv = require('yargs')
|
|
|
|
.boolean('ci')
|
2019-11-07 00:15:55 +00:00
|
|
|
.array('files')
|
2019-03-10 22:38:44 +00:00
|
|
|
.string('g').alias('g', 'grep')
|
|
|
|
.boolean('i').alias('i', 'invert')
|
2020-03-20 20:28:31 +00:00
|
|
|
.argv;
|
2019-03-10 22:38:44 +00:00
|
|
|
|
2020-03-20 20:28:31 +00:00
|
|
|
const Mocha = require('mocha');
|
|
|
|
const mochaOptions = {};
|
2019-03-10 22:38:44 +00:00
|
|
|
if (process.env.MOCHA_REPORTER) {
|
2020-03-20 20:28:31 +00:00
|
|
|
mochaOptions.reporter = process.env.MOCHA_REPORTER;
|
2019-03-10 22:38:44 +00:00
|
|
|
}
|
|
|
|
if (process.env.MOCHA_MULTI_REPORTERS) {
|
|
|
|
mochaOptions.reporterOptions = {
|
|
|
|
reporterEnabled: process.env.MOCHA_MULTI_REPORTERS
|
2020-03-20 20:28:31 +00:00
|
|
|
};
|
2019-03-10 22:38:44 +00:00
|
|
|
}
|
2020-03-20 20:28:31 +00:00
|
|
|
const mocha = new Mocha(mochaOptions);
|
2019-03-10 22:38:44 +00:00
|
|
|
|
|
|
|
if (!process.env.MOCHA_REPORTER) {
|
2020-03-20 20:28:31 +00:00
|
|
|
mocha.ui('bdd').reporter('tap');
|
2019-03-10 22:38:44 +00:00
|
|
|
}
|
2020-05-18 16:33:54 +00:00
|
|
|
const mochaTimeout = process.env.MOCHA_TIMEOUT || 30000;
|
|
|
|
mocha.timeout(mochaTimeout);
|
2019-03-10 22:38:44 +00:00
|
|
|
|
2020-03-20 20:28:31 +00:00
|
|
|
if (argv.grep) mocha.grep(argv.grep);
|
|
|
|
if (argv.invert) mocha.invert();
|
2019-03-10 22:38:44 +00:00
|
|
|
|
|
|
|
// Read all test files.
|
|
|
|
const walker = require('walkdir').walk(__dirname, {
|
|
|
|
no_recurse: true
|
2020-03-20 20:28:31 +00:00
|
|
|
});
|
2019-03-10 22:38:44 +00:00
|
|
|
|
|
|
|
// This allows you to run specific modules only:
|
|
|
|
// npm run test -match=menu
|
|
|
|
const moduleMatch = process.env.npm_config_match
|
|
|
|
? new RegExp(process.env.npm_config_match, 'g')
|
2020-03-20 20:28:31 +00:00
|
|
|
: null;
|
2019-03-10 22:38:44 +00:00
|
|
|
|
2020-03-20 20:28:31 +00:00
|
|
|
const testFiles = [];
|
2019-03-10 22:38:44 +00:00
|
|
|
walker.on('file', (file) => {
|
|
|
|
if (/-spec\.[tj]s$/.test(file) &&
|
|
|
|
(!moduleMatch || moduleMatch.test(file))) {
|
2020-03-20 20:28:31 +00:00
|
|
|
testFiles.push(file);
|
2019-03-10 22:38:44 +00:00
|
|
|
}
|
2020-03-20 20:28:31 +00:00
|
|
|
});
|
2019-03-10 22:38:44 +00:00
|
|
|
|
2020-03-20 20:28:31 +00:00
|
|
|
const baseElectronDir = path.resolve(__dirname, '..');
|
2019-11-07 00:15:55 +00:00
|
|
|
|
2019-03-10 22:38:44 +00:00
|
|
|
walker.on('end', () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
testFiles.sort();
|
2020-04-22 22:53:12 +00:00
|
|
|
testFiles.forEach((file) => {
|
2019-11-07 00:15:55 +00:00
|
|
|
if (!argv.files || argv.files.includes(path.relative(baseElectronDir, file))) {
|
2020-03-20 20:28:31 +00:00
|
|
|
mocha.addFile(file);
|
2019-11-07 00:15:55 +00:00
|
|
|
}
|
2020-03-20 20:28:31 +00:00
|
|
|
});
|
2019-04-03 18:19:39 +00:00
|
|
|
const cb = () => {
|
2019-04-03 01:25:45 +00:00
|
|
|
// Ensure the callback is called after runner is defined
|
|
|
|
process.nextTick(() => {
|
2020-03-20 20:28:31 +00:00
|
|
|
process.exit(runner.failures);
|
|
|
|
});
|
|
|
|
};
|
2019-11-07 00:15:55 +00:00
|
|
|
|
|
|
|
// Set up chai in the correct order
|
2020-03-20 20:28:31 +00:00
|
|
|
const chai = require('chai');
|
|
|
|
chai.use(require('chai-as-promised'));
|
|
|
|
chai.use(require('dirty-chai'));
|
2019-11-07 00:15:55 +00:00
|
|
|
|
2020-03-20 20:28:31 +00:00
|
|
|
const runner = mocha.run(cb);
|
|
|
|
});
|
|
|
|
});
|
2019-10-14 21:38:54 +00:00
|
|
|
|
|
|
|
function partition (xs, f) {
|
2020-03-20 20:28:31 +00:00
|
|
|
const trues = [];
|
|
|
|
const falses = [];
|
|
|
|
xs.forEach(x => (f(x) ? trues : falses).push(x));
|
|
|
|
return [trues, falses];
|
2019-10-14 21:38:54 +00:00
|
|
|
}
|