-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
64 lines (56 loc) · 2.21 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
var fs = require('fs');
var util = require('./util');
var filename = process.env.JEST_REPORT_JSON || 'report.json';
var output = {
stats: {},
failures: [],
passes: [],
skipped: [],
};
module.exports = function reporter(results) {
output.stats.skipped = 0;
output.stats.pending = 0;
output.stats.tests = results.numTotalTests;
output.stats.passes = results.numPassedTests;
output.stats.failures = results.numFailedTests;
output.stats.testsRegistered = results.numTotalTests;
output.stats.duration = Date.now() - results.startTime;
results.testResults.forEach(function suiteIterator(suiteResult) {
if (suiteResult.testExecError) {
throw new Error(suiteResult.testExecError.message);
}
suiteResult.testResults.forEach(function testIterator(testResult) {
/* istanbul ignore else */
if (testResult.status === 'passed') {
output.passes.push({
title: testResult.title,
fullTitle: testResult.ancestorTitles + ' ' + testResult.title,
duration: suiteResult.perfStats.end - suiteResult.perfStats.start,
errorCount: testResult.failureMessages.length,
});
} else if (testResult.status === 'failed') {
output.failures.push({
title: testResult.title,
fullTitle: testResult.ancestorTitles + ' ' + testResult.title,
duration: suiteResult.perfStats.end - suiteResult.perfStats.start,
errorCount: testResult.failureMessages.length,
error: util.format(testResult.failureMessages),
});
} else if (testResult.status === 'pending') {
output.stats.pending += 1;
output.stats.skipped += 1;
output.skipped.push({
title: testResult.title,
fullTitle: testResult.ancestorTitles + ' ' + testResult.title,
duration: suiteResult.perfStats.end - suiteResult.perfStats.start,
errorCount: testResult.failureMessages.length,
});
}
});
});
output.stats.passPercent = Number(((output.stats.passes / output.stats.tests) * 100).toFixed(2));
output.stats.start = new Date(results.startTime);
output.stats.end = new Date();
fs.writeFileSync(filename, JSON.stringify(output, null, 2), 'utf-8');
return results;
};