Repository navigation
Expand file tree
/
Copy pathtestRunner.js
More file actions
74 lines (64 loc) · 2.09 KB
/
Copy pathtestRunner.js
File metadata and controls
74 lines (64 loc) · 2.09 KB
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
/* @flow */
import colors from 'colors/safe';
import {format} from 'util';
import {drain} from '../async';
import Builder from './builder';
import findTests from './finder';
import RunQueue from './RunQueue';
import type {Args} from './testCommand';
/* We potentially have a ton of info to dump into stdout. Let's handle drain
* events properly */
async function write(fmt: string, ...args: Array<mixed>): Promise<void> {
if (false == process.stdout.write(format(fmt, ...args))) {
await drain(process.stdout);
}
}
export default async function(args: Args): Promise<void> {
const builder = new Builder(args.errorCheckCommand);
const suites = await findTests(args.suites);
const runQueue = new RunQueue(
args.bin,
args.parallelism,
args.fbmakeJson,
suites,
builder,
);
await runQueue.go();
const results = runQueue.results;
let exitCode = 0;
for (const suiteName of Object.keys(results).sort()) {
for (let testNum = 0; testNum < results[suiteName].length; testNum++) {
const testResult = results[suiteName][testNum];
for (let stepNum = 0; stepNum < testResult.stepResults.length; stepNum++) {
const result = testResult.stepResults[stepNum];
if(!result.passed) {
exitCode = 1;
await write(
colors.red.bold("FAILED")+
colors.grey(": suite ")+
colors.blue("%s")+
colors.grey(", test ")+
colors.blue("%s")+
colors.grey(" (%d of %d), step %d of %d") + "\n",
suiteName,
testResult.name || "unnamed test",
testNum+1,
results[suiteName].length,
stepNum+1,
testResult.stepResults.length,
);
const messages = [];
for (const assertionResult of result.assertionResults) {
if (assertionResult.type === "fail") {
messages.push(...assertionResult.messages);
}
}
for (const message of messages) {
await write("%s\n", message);
}
}
}
}
}
process.exit(exitCode);
}