-
Notifications
You must be signed in to change notification settings - Fork 158
/
Copy pathsave-coverage-file.js
executable file
·65 lines (58 loc) · 2.16 KB
/
save-coverage-file.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
#!/usr/bin/env node
import { createRequire } from "module";
const require = createRequire(import.meta.url);
const fs = require("fs");
/**
* This takes a large combined Jest-format coverage file, and a collection of JSON test reports, and combines them into one master file.
*/
const coveragePackages = ["cli", "cli-kit", "app"];
const masterCoverageFile = process.cwd() + "/coverage.raw.json";
const masterReportFile = process.cwd() + "/report.json";
// Create the starting file -- the master coverage file and empty test results
const masterCoverage = {
numTotalTestSuites: 0,
numPassedTestSuites: 0,
numFailedTestSuites: 0,
numPendingTestSuites: 0,
numTotalTests: 0,
numPassedTests: 0,
numFailedTests: 0,
numPendingTests: 0,
numTodoTests: 0,
startTime: 999999999999999,
success: true,
testResults: [],
coverageMap: require(masterCoverageFile),
};
// merge each package's test results into the master file
coveragePackages.forEach((pkg) => {
const testReportFilename =
process.cwd() + `/packages/${pkg}/coverage/report.json`;
const testReport = require(testReportFilename);
masterCoverage.numTotalTestSuites += testReport.numTotalTestSuites;
masterCoverage.numPassedTestSuites += testReport.numPassedTestSuites;
masterCoverage.numFailedTestSuites += testReport.numFailedTestSuites;
masterCoverage.numPendingTestSuites += testReport.numPendingTestSuites;
masterCoverage.numTotalTests += testReport.numTotalTests;
masterCoverage.numPassedTests += testReport.numPassedTests;
masterCoverage.numFailedTests += testReport.numFailedTests;
masterCoverage.numPendingTests += testReport.numPendingTests;
masterCoverage.numTodoTests += testReport.numTodoTests;
masterCoverage.startTime = Math.min(
masterCoverage.startTime,
testReport.startTime
);
masterCoverage.success = masterCoverage.success && testReport.success;
masterCoverage.testResults = [
...masterCoverage.testResults,
...testReport.testResults,
];
});
// write it out
fs.writeFile(masterReportFile, JSON.stringify(masterCoverage), (err) => {
if (err) {
console.error(err);
process.exit(1);
}
console.log("Coverage report appended to " + masterReportFile);
});