electron/spec/static/index.html

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

108 lines
3.1 KiB
HTML
Raw Normal View History

2013-07-17 08:28:14 +00:00
<body>
<script type="text/javascript" charset="utf-8">
(async function() {
// Deprecated APIs are still supported and should be tested.
process.throwDeprecation = false
const path = require('path')
const electron = require('electron')
2019-10-30 23:38:21 +00:00
const { ipcRenderer } = electron
// Extra module paths which can be used to load Mocha reporters
if (process.env.ELECTRON_TEST_EXTRA_MODULE_PATHS) {
for (const modulePath of process.env.ELECTRON_TEST_EXTRA_MODULE_PATHS.split(':')) {
module.paths.push(modulePath);
}
}
// Add search paths for loaded spec files
require('../global-paths')(module.paths);
2019-03-12 00:07:11 +00:00
// Set up chai-as-promised here first to avoid conflicts
// It must be loaded first or really strange things happen inside
// chai that cause test failures
// DO NOT MOVE, REMOVE OR EDIT THIS LINE
require('chai').use(require('chai-as-promised'))
// Redirect all output to browser.
2019-10-30 23:38:21 +00:00
const fakeConsole = {}
for (const k in console) {
if (console.hasOwnProperty(k) && k !== 'assert') {
fakeConsole[k] = (...args) => ipcRenderer.send('console-call', k, args)
}
}
2019-10-30 23:38:21 +00:00
global.__defineGetter__('console', function () {
return fakeConsole
})
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)
2013-07-17 08:28:14 +00:00
if (!process.env.MOCHA_REPORTER) {
2019-10-30 23:38:21 +00:00
mocha.ui('bdd').reporter('tap')
}
const mochaTimeout = process.env.MOCHA_TIMEOUT || 30000
mocha.timeout(mochaTimeout)
2013-07-17 08:28:14 +00:00
const query = Mocha.utils.parseQuery(window.location.search || '')
if (query.grep) mocha.grep(query.grep)
if (query.invert) mocha.invert()
2013-07-17 08:28:14 +00:00
const filter = (file) => {
if (!/-spec\.js$/.test(file)) {
return false
}
// 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
if (moduleMatch && !moduleMatch.test(file)) {
return false
}
2013-07-17 08:28:14 +00:00
const files = query.files ? query.files.split(',') : undefined
const baseElectronDir = path.resolve(__dirname, '..', '..')
if (files && !files.includes(path.relative(baseElectronDir, file))) {
return false
}
2013-07-17 08:28:14 +00:00
return true
}
const getFiles = require('./get-files')
const testFiles = await getFiles(path.dirname(__dirname), { filter })
testFiles.sort().forEach((file) => {
mocha.addFile(file)
})
// Set up chai in the correct order
const chai = require('chai')
chai.use(require('chai-as-promised'))
chai.use(require('dirty-chai'))
2021-03-09 07:05:02 +00:00
// Show full object diff
// https://github.com/chaijs/chai/issues/469
chai.config.truncateThreshold = 0;
const runner = mocha.run(() => {
// Ensure the callback is called after runner is defined
setTimeout(() => {
ipcRenderer.send('process.exit', runner.failures)
}, 0)
})
})()
2013-07-17 08:28:14 +00:00
</script>
</body>