/
run.js
134 lines (114 loc) 路 2.72 KB
/
run.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
'use strict';
const childProcess = require('child_process');
const path = require('path');
const fs = require('fs');
const Promise = require('bluebird');
const arrify = require('arrify');
const makeDir = require('make-dir');
const branch = require('git-branch').sync(path.join(__dirname, '..'));
const cliPath = require.resolve('../cli');
function runTests(_args) {
return new Promise(resolve => {
const args = [cliPath].concat(arrify(_args));
const start = Date.now();
childProcess.execFile(process.execPath, args, {
cwd: __dirname,
maxBuffer: 100000 * 200
}, (err, stdout, stderr) => {
const end = Date.now();
resolve({
args: arrify(_args),
time: end - start,
err,
stdout,
stderr
});
});
});
}
let list;
if (process.argv.length === 2) {
list = [
{
args: 'other/failures.js',
shouldFail: true
},
'serial/alternating-sync-async.js',
'serial/async-immediate.js',
'serial/async-timeout.js',
'serial/sync.js',
'concurrent/alternating-sync-async.js',
'concurrent/async-immediate.js',
'concurrent/async-timeout.js',
'concurrent/sync.js',
['concurrent/*.js', 'serial/*.js']
].map(definition => {
if (Array.isArray(definition) || typeof definition === 'string') {
definition = {
shouldFail: false,
args: definition
};
}
return definition;
});
} else {
list = [];
let currentArgs = [];
let shouldFail = false;
for (const arg of process.argv.slice(2)) {
if (arg === '--') {
list.push({
args: currentArgs,
shouldFail
});
currentArgs = [];
shouldFail = false;
continue;
}
if (arg === '--should-fail') {
shouldFail = true;
continue;
}
currentArgs.push(arg);
}
if (currentArgs.length > 0) {
list.push({
args: currentArgs,
shouldFail
});
}
}
for (const definition of list) {
definition.args = ['--verbose'].concat(definition.args);
}
let combined = [];
for (let i = 0; i < 11; i++) {
combined = combined.concat(list);
}
const results = {};
Promise.each(combined, async definition => {
const {args} = definition;
const result = await runTests(args);
const key = result.args.join(' ');
const passedOrFaild = result.err ? 'failed' : 'passed';
const seconds = result.time / 1000;
console.log('%s %s in %d seconds', key, passedOrFaild, seconds);
if (result.err && !definition.shouldFail) {
console.log(result.stdout);
console.log(result.stderr);
throw result.err;
}
results[key] = results[key] || [];
results[key].push({
passed: !results.err,
shouldFail: definition.shouldFail,
time: seconds
});
}).then(() => {
makeDir.sync(path.join(__dirname, '.results'));
results['.time'] = Date.now();
fs.writeFileSync(
path.join(__dirname, '.results', `${branch}.json`),
JSON.stringify(results, null, 4)
);
});