/
jest-simple-dot-reporter.js
83 lines (71 loc) · 2.62 KB
/
jest-simple-dot-reporter.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
const pluralize = (word, count) => `${count} ${word}${count === 1 ? '' : 's'}`;
class JestSimpleDotReporter {
constructor(globalConfig, options) {
this._globalConfig = globalConfig;
this._options = options;
}
onRunStart(test) {
this._numTestSuitesLeft = test.numTotalTestSuites;
console.log()
console.log(`Found ${test.numTotalTestSuites} test suites`);
}
onRunComplete(test, results) {
const {
numFailedTests,
numPassedTests,
numTodoTests,
numPendingTests,
testResults,
numTotalTests,
startTime
} = results;
console.log();
testResults.map(({failureMessage}) => {
if (failureMessage) {
console.error(failureMessage);
}
});
if (!results.snapshot.didUpdate && results.snapshot.unchecked) {
const obsoleteError = pluralize('obsolete snapshot', results.snapshot.unchecked) + ' found.';
if (this._options.color)
console.error(`\x1b[31m${obsoleteError}\x1b[0m`);
else
console.error(obsoleteError);
}
console.log(`Ran ${numTotalTests} tests in ${testDuration()}`);
process.stdout.write(` ${numPassedTests || 0} passing`);
process.stdout.write(` ${numFailedTests || 0} failing`);
process.stdout.write(` ${(numTodoTests || 0) + (numPendingTests || 0)} skipped`);
console.log();
function testDuration() {
const end = new Date();
const start = new Date(startTime);
const seconds = (end - start) / 1000;
return `${seconds} s`;
}
}
onTestResult(test, testResult) {
for (var i = 0; i < testResult.testResults.length; i++) {
switch (testResult.testResults[i].status) {
case "passed":
process.stdout.write(".")
break
case "skipped":
case "pending":
case "todo":
case "disabled":
process.stdout.write("*")
break
case "failed":
process.stdout.write("F")
break
default:
process.stdout.write(`(${testResult.testResults[i].status})`)
}
}
if (!--this._numTestSuitesLeft && this._globalConfig.collectCoverage) {
console.log()
}
}
}
module.exports = JestSimpleDotReporter;