2019-03-10 22:38:44 +00:00
|
|
|
const Module = require('module')
|
|
|
|
const path = require('path')
|
|
|
|
const v8 = require('v8')
|
|
|
|
|
|
|
|
Module.globalPaths.push(path.resolve(__dirname, '../spec/node_modules'))
|
|
|
|
|
|
|
|
// We want to terminate on errors, not throw up a dialog
|
|
|
|
process.on('uncaughtException', (err) => {
|
|
|
|
console.error('Unhandled exception in main spec runner:', err)
|
|
|
|
process.exit(1)
|
|
|
|
})
|
|
|
|
|
|
|
|
// Tell ts-node which tsconfig to use
|
|
|
|
process.env.TS_NODE_PROJECT = path.resolve(__dirname, '../tsconfig.spec.json')
|
2019-07-16 20:43:00 +00:00
|
|
|
process.env.ELECTRON_DISABLE_SECURITY_WARNINGS = 'true'
|
2019-03-10 22:38:44 +00:00
|
|
|
|
2019-05-28 21:12:59 +00:00
|
|
|
const { app, protocol } = require('electron')
|
2019-03-10 22:38:44 +00:00
|
|
|
|
|
|
|
v8.setFlagsFromString('--expose_gc')
|
|
|
|
app.commandLine.appendSwitch('js-flags', '--expose_gc')
|
|
|
|
// Prevent the spec runner quiting when the first window closes
|
|
|
|
app.on('window-all-closed', () => null)
|
|
|
|
// TODO: This API should _probably_ only be enabled for the specific test that needs it
|
|
|
|
// not the entire test suite
|
|
|
|
app.commandLine.appendSwitch('ignore-certificate-errors')
|
|
|
|
|
2019-10-11 20:55:50 +00:00
|
|
|
// Use fake device for Media Stream to replace actual camera and microphone.
|
|
|
|
app.commandLine.appendSwitch('use-fake-device-for-media-stream')
|
|
|
|
|
2019-05-28 21:12:59 +00:00
|
|
|
global.standardScheme = 'app'
|
2019-08-30 00:45:41 +00:00
|
|
|
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 } },
|
|
|
|
{ scheme: 'no-fetch', privileges: { corsEnabled: true } }
|
2019-05-28 21:12:59 +00:00
|
|
|
])
|
|
|
|
|
2019-03-10 22:38:44 +00:00
|
|
|
app.whenReady().then(() => {
|
|
|
|
require('ts-node/register')
|
|
|
|
|
|
|
|
const argv = require('yargs')
|
|
|
|
.boolean('ci')
|
|
|
|
.string('g').alias('g', 'grep')
|
|
|
|
.boolean('i').alias('i', 'invert')
|
|
|
|
.argv
|
|
|
|
|
|
|
|
const Mocha = require('mocha')
|
|
|
|
const mochaOptions = {}
|
|
|
|
if (process.env.MOCHA_REPORTER) {
|
|
|
|
mochaOptions.reporter = process.env.MOCHA_REPORTER
|
|
|
|
}
|
|
|
|
if (process.env.MOCHA_MULTI_REPORTERS) {
|
|
|
|
mochaOptions.reporterOptions = {
|
|
|
|
reporterEnabled: process.env.MOCHA_MULTI_REPORTERS
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const mocha = new Mocha(mochaOptions)
|
|
|
|
|
|
|
|
if (!process.env.MOCHA_REPORTER) {
|
|
|
|
mocha.ui('bdd').reporter('tap')
|
|
|
|
}
|
2019-10-30 23:38:21 +00:00
|
|
|
mocha.timeout(30000)
|
2019-03-10 22:38:44 +00:00
|
|
|
|
|
|
|
if (argv.grep) mocha.grep(argv.grep)
|
|
|
|
if (argv.invert) mocha.invert()
|
|
|
|
|
|
|
|
// Read all test files.
|
|
|
|
const walker = require('walkdir').walk(__dirname, {
|
|
|
|
no_recurse: true
|
|
|
|
})
|
|
|
|
|
|
|
|
// 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')
|
|
|
|
: null
|
|
|
|
|
2019-09-03 17:13:06 +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))) {
|
2019-09-03 17:13:06 +00:00
|
|
|
testFiles.push(file)
|
2019-03-10 22:38:44 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
walker.on('end', () => {
|
2019-09-03 17:13:06 +00:00
|
|
|
testFiles.sort()
|
2019-10-14 21:38:54 +00:00
|
|
|
sortToEnd(testFiles, f => f.includes('crash-reporter')).forEach((file) => mocha.addFile(file))
|
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(() => {
|
|
|
|
process.exit(runner.failures)
|
|
|
|
})
|
2019-04-03 18:19:39 +00:00
|
|
|
}
|
2019-06-07 00:12:22 +00:00
|
|
|
const runner = mocha.run(cb)
|
2019-03-10 22:38:44 +00:00
|
|
|
})
|
|
|
|
})
|
2019-10-14 21:38:54 +00:00
|
|
|
|
|
|
|
function partition (xs, f) {
|
|
|
|
const trues = []
|
|
|
|
const falses = []
|
|
|
|
xs.forEach(x => (f(x) ? trues : falses).push(x))
|
|
|
|
return [trues, falses]
|
|
|
|
}
|
|
|
|
|
|
|
|
function sortToEnd (xs, f) {
|
|
|
|
const [end, beginning] = partition(xs, f)
|
|
|
|
return beginning.concat(end)
|
|
|
|
}
|