/
index.js
82 lines (67 loc) · 1.51 KB
/
index.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
'use strict';
const Mocha = require('mocha');
const { promisify } = require('util');
const glob = promisify(require('glob'));
const { buildGrep } = require('./tag');
async function runMocha(mocha) {
let runner;
await new Promise(resolve => {
// `mocha.run` is synchronous if no tests were found,
// otherwise, it's asynchronous...
runner = mocha.run(resolve);
});
return runner;
}
async function runTests({
globs,
retries,
tag: tags = [],
filter = '',
random,
seed,
timeoutsOverride,
disableTimeouts,
reporter,
reporterOptions,
}) {
if (random) {
if (seed) {
process.env.CHOMA_SEED = seed;
}
require('choma');
}
if (reporterOptions) {
reporterOptions = reporterOptions.split(',').reduce((options, option) => {
let [key, value] = option.split('=');
options[key] = value;
return options;
}, {});
}
let grep = buildGrep(tags, filter);
let mochaOpts = {
retries,
grep,
color: true,
reporter,
reporterOptions,
};
if (disableTimeouts) {
mochaOpts.timeout = false;
} else if (timeoutsOverride) {
mochaOpts.timeout = timeoutsOverride;
}
let mocha = new Mocha(mochaOpts);
for (let testsGlob of globs) {
let files = await glob(testsGlob);
for (let file of files) {
mocha.addFile(file);
}
}
let runner = await runMocha(mocha);
return runner.stats;
}
module.exports = {
runTests,
createRolesHelper: require('./role').create,
createFlaggedTest: require('./flag').create,
};