-
Notifications
You must be signed in to change notification settings - Fork 22
/
verify.js
68 lines (61 loc) · 1.8 KB
/
verify.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
const Mocha = require('mocha');
const should = require('should');
const fs = require('fs');
const debug = require('debug')('mocha:verify:multi');
const async = require('async');
const chalk = require('chalk');
const reporters = [
'dot', 'doc', 'spec', 'json', 'progress',
'list', 'tap', 'landing', 'xunit', 'min',
'json-stream', 'markdown', 'nyan',
];
const now = new Date();
function tempName(reporter) {
return `/tmp/mocha-multi.${reporter}.${+now}`;
}
const reportersWithOptions = []
.concat(reporters.map((reporter) => {
const outFilename = tempName(`${reporter}-stdout`);
const options = {};
options[reporter] = {
stdout: outFilename,
};
return {
testName: `${reporter} (with options.stdout)`,
outFilename,
options,
};
}))
.concat(reporters.map((reporter) => {
const outFilename = tempName(`${reporter}-str`);
const options = {};
options[reporter] = outFilename;
return {
testName: `${reporter} (with options as string)`,
outFilename,
options,
};
}));
should(process.env.multi).not.be.ok;
process.setMaxListeners(reportersWithOptions.length);
async.eachSeries(reportersWithOptions, (reporter, next) => {
debug('reporter %s', reporter.testName);
debug('reporterOptions %j', reporter.options);
const mocha = new Mocha({
ui: 'bdd',
reporter: 'mocha-multi',
reporterOptions: reporter.options,
});
mocha.addFile('test/dummy-spec.js');
mocha.run(() => {
debug('done running %j', reporter.testName);
process.nextTick(next);
});
}, () => {
reportersWithOptions.forEach((reporter) => {
fs.statSync.bind(fs, reporter.outFilename).should.not.throw();
fs.unlinkSync(reporter.outFilename);
// eslint-disable-next-line no-console
console.log(chalk.green('%s OK'), reporter.testName);
});
});