-
Notifications
You must be signed in to change notification settings - Fork 23
/
combine-packages-coverage.js
53 lines (42 loc) · 1.44 KB
/
combine-packages-coverage.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
const fs = require("fs");
const StreamConcat = require("stream-concat");
// add the reports of all the different Stark packages to be combined
const fileNames = [
"reports/coverage/packages/stark-core/lcov.info",
"reports/coverage/packages/stark-ui/lcov.info",
"reports/coverage/packages/stark-rbac/lcov.info"
];
function replaceValuesInFile(fileName, valueReplacements) {
fs.readFile(fileName, "utf8", function (err, data) {
if (err) {
return console.error("Error while reading file => " + err);
}
let result = data;
for (const replacement of valueReplacements) {
const searchValueRegex = new RegExp(replacement.searchValue, "g");
result = result.replace(searchValueRegex, replacement.replaceValue);
}
fs.writeFile(fileName, result, "utf8", function (err) {
if (err) {
return console.error(err);
} else {
return console.log(`${fileName} updated successfully`);
}
});
});
}
let fileIndex = 0;
const nextStream = function () {
if (fileIndex === fileNames.length) {
return null;
}
const file = fileNames[fileIndex++];
console.log("Concatenating coverage report: ", file);
return fs.createReadStream(file);
};
// then concatenate the files (but wait X milliseconds for the files to be overwritten in the previous step)
setTimeout(() => {
const combinedStream = new StreamConcat(nextStream);
const combinedLcovFileName = fs.createWriteStream("combined-lcov.info");
combinedStream.pipe(combinedLcovFileName);
}, 250);