-
Notifications
You must be signed in to change notification settings - Fork 15k
/
index.html
102 lines (87 loc) · 2.94 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<body>
<script src="jquery-2.0.3.min.js"></script>
<script type="text/javascript" charset="utf-8">
(async function() {
// Deprecated APIs are still supported and should be tested.
process.throwDeprecation = false
const Module = require('module');
const path = require('path')
const electron = require('electron')
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.globalPaths.push(modulePath);
}
}
// 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'))
// Rediret all output to browser.
const fakeConsole = {}
for (const k in console) {
if (console.hasOwnProperty(k) && k !== 'assert') {
fakeConsole[k] = (...args) => ipcRenderer.send('console-call', k, args)
}
}
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)
if (!process.env.MOCHA_REPORTER) {
mocha.ui('bdd').reporter('tap')
}
const mochaTimeout = process.env.MOCHA_TIMEOUT || 30000
mocha.timeout(mochaTimeout)
const query = Mocha.utils.parseQuery(window.location.search || '')
if (query.grep) mocha.grep(query.grep)
if (query.invert) mocha.invert()
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
}
const files = query.files ? query.files.split(',') : undefined
const baseElectronDir = path.resolve(__dirname, '..', '..')
if (files && !files.includes(path.relative(baseElectronDir, file))) {
return false
}
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'))
const runner = mocha.run(() => {
// Ensure the callback is called after runner is defined
setTimeout(() => {
ipcRenderer.send('process.exit', runner.failures)
}, 0)
})
})()
</script>
</body>