-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathmocha-runner.js
61 lines (52 loc) · 1.53 KB
/
mocha-runner.js
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
process.env.BABEL_ENV = 'test'
process.env.NODE_ENV = 'test'
// Makes the script crash on unhandled rejections instead of silently
// ignoring them. In the future, promise rejections that are not handled will
// terminate the Node.js process with a non-zero exit code.
process.on('unhandledRejection', error => {
throw error
})
require('core-js/stable')
require('regenerator-runtime/runtime')
let options = require('yargs').argv
let getConfig = require('./config')
let config = getConfig(options)
require('@babel/register')({
...config.babel(true, config),
extensions: ['.es6', '.es', '.jsx', '.js', '.mjs', '.ts', '.tsx']
})
let Mocha = require('mocha')
let fs = require('fs')
let path = require('path')
// Instantiate a Mocha instance.
let mocha = new Mocha({
timeout: 20000,
...options
})
function travelDirectoryToAddTestFiles(dir) {
fs.readdirSync(dir).forEach(file => {
let filename = path.join(dir, file)
// ignore node_modules
if (
filename.indexOf('node_modules') !== -1 ||
filename.indexOf('publish') !== -1
) {
return
}
// read file deeply
if (fs.statSync(filename).isDirectory()) {
return travelDirectoryToAddTestFiles(filename)
}
// add *test.js file to the mocha instance
if (filename.substr(-8) === '-test.js') {
return mocha.addFile(filename)
}
})
}
travelDirectoryToAddTestFiles(__dirname)
// Run the tests.
mocha.run(function(failures) {
// exit with non-zero status if there were failures
// Mocha Won't Force Exit
process.exit(failures)
})