2013-07-17 16:28:14 +08:00
|
|
|
<html>
|
|
|
|
<head>
|
2013-08-27 11:37:06 +08:00
|
|
|
<meta name="referrer" content="always">
|
2014-04-29 11:51:49 +08:00
|
|
|
<link href="../node_modules/mocha/mocha.css" rel="stylesheet">
|
2013-08-25 16:23:40 +08:00
|
|
|
<script src="jquery-2.0.3.min.js"></script>
|
2013-07-17 16:28:14 +08:00
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
|
|
|
|
<div id="mocha"></div>
|
|
|
|
|
|
|
|
<script type="text/javascript" charset="utf-8">
|
|
|
|
(function() {
|
2018-07-29 18:27:58 -07:00
|
|
|
// Deprecated APIs are still supported and should be tested.
|
|
|
|
process.throwDeprecation = false
|
2013-12-15 17:02:43 +08:00
|
|
|
|
2017-12-28 12:18:33 +01:00
|
|
|
const path = require('path')
|
|
|
|
const electron = require('electron')
|
|
|
|
const { remote, ipcRenderer } = electron
|
2015-11-12 18:28:04 +08:00
|
|
|
|
2016-08-03 14:12:05 -07:00
|
|
|
// Check if we are running in CI.
|
2017-12-28 12:18:33 +01:00
|
|
|
const isCi = remote.getGlobal('isCi')
|
2013-08-21 11:35:39 +08:00
|
|
|
|
|
|
|
if (!isCi) {
|
2017-12-28 12:18:33 +01:00
|
|
|
const win = remote.getCurrentWindow()
|
|
|
|
win.show()
|
|
|
|
win.focus()
|
2013-08-21 11:35:39 +08:00
|
|
|
}
|
|
|
|
|
2013-07-31 10:55:47 +08:00
|
|
|
// Show DevTools.
|
2017-12-28 12:18:33 +01:00
|
|
|
document.oncontextmenu = (e) => {
|
|
|
|
remote.getCurrentWindow().inspectElement(e.clientX, e.clientY)
|
2013-07-31 10:55:47 +08:00
|
|
|
}
|
|
|
|
|
2013-08-21 11:15:22 +08:00
|
|
|
// Rediret all output to browser.
|
2013-08-25 20:54:15 +08:00
|
|
|
if (isCi) {
|
2017-12-28 12:18:33 +01:00
|
|
|
global.__defineGetter__('console', function () {
|
2013-08-25 20:54:15 +08:00
|
|
|
return {
|
2017-12-28 12:18:33 +01:00
|
|
|
log: (...args) => ipcRenderer.send('console.log', args),
|
|
|
|
error: (...args) => ipcRenderer.send('console.error', args)
|
2013-08-25 20:54:15 +08:00
|
|
|
}
|
2017-12-28 12:18:33 +01:00
|
|
|
})
|
2013-08-25 20:54:15 +08:00
|
|
|
}
|
2013-08-21 11:15:22 +08:00
|
|
|
|
2017-12-28 12:18:33 +01:00
|
|
|
const Mocha = require('mocha')
|
2018-09-14 14:56:16 -04:00
|
|
|
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)
|
2013-07-17 16:28:14 +08:00
|
|
|
|
2017-09-28 13:05:42 -04:00
|
|
|
if (!process.env.MOCHA_REPORTER) {
|
2017-12-28 12:18:33 +01:00
|
|
|
mocha.ui('bdd').reporter(isCi ? 'tap' : 'html')
|
2017-09-28 13:05:42 -04:00
|
|
|
}
|
2016-11-29 14:29:35 -08:00
|
|
|
mocha.timeout(isCi ? 30000 : 10000)
|
2013-07-17 16:28:14 +08:00
|
|
|
|
2017-12-28 12:18:33 +01:00
|
|
|
const query = Mocha.utils.parseQuery(window.location.search || '')
|
|
|
|
if (query.grep) mocha.grep(query.grep)
|
|
|
|
if (query.invert) mocha.invert()
|
2013-07-17 16:28:14 +08:00
|
|
|
|
|
|
|
// Read all test files.
|
2017-12-28 12:18:33 +01:00
|
|
|
const walker = require('walkdir').walk(path.dirname(__dirname), {
|
2013-12-06 22:23:02 +08:00
|
|
|
no_recurse: true
|
2017-12-28 12:18:33 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
const crashSpec = 'api-crash-reporter-spec.js'
|
|
|
|
|
|
|
|
// 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')
|
2018-01-01 15:46:39 +09:00
|
|
|
: null
|
2013-07-17 16:28:14 +08:00
|
|
|
|
2017-12-28 12:18:33 +01:00
|
|
|
walker.on('file', (file) => {
|
2018-01-01 15:46:39 +09:00
|
|
|
if (/-spec\.js$/.test(file) && !file.includes(crashSpec) &&
|
|
|
|
(!moduleMatch || moduleMatch.test(file))) {
|
2017-12-28 12:18:33 +01:00
|
|
|
mocha.addFile(file)
|
|
|
|
}
|
|
|
|
})
|
2013-07-17 16:28:14 +08:00
|
|
|
|
2017-12-28 12:18:33 +01:00
|
|
|
walker.on('end', () => {
|
|
|
|
if (!process.env.npm_config_match || new RegExp(process.env.npm_config_match, 'g').test(crashSpec)) {
|
|
|
|
mocha.addFile(path.resolve(__dirname, '..', crashSpec))
|
|
|
|
}
|
|
|
|
|
|
|
|
const runner = mocha.run(() => {
|
2016-11-22 13:06:18 -08:00
|
|
|
if (isCi && runner.hasOnly) {
|
|
|
|
try {
|
|
|
|
throw new Error('A spec contains a call to it.only or describe.only and should be reverted.')
|
|
|
|
} catch (error) {
|
|
|
|
console.error(error.stack || error)
|
|
|
|
}
|
|
|
|
ipcRenderer.send('process.exit', 1)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2017-12-28 12:18:33 +01:00
|
|
|
Mocha.utils.highlightTags('code')
|
2016-08-03 14:12:05 -07:00
|
|
|
|
2017-12-28 12:18:33 +01:00
|
|
|
if (isCi) {
|
|
|
|
ipcRenderer.send('process.exit', runner.failures)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})()
|
2013-07-17 16:28:14 +08:00
|
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html>
|