-
Notifications
You must be signed in to change notification settings - Fork 3
/
merge-reports.ts
37 lines (32 loc) · 1.05 KB
/
merge-reports.ts
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
const glob = require('glob');
const fs = require('fs');
const path = require('path');
const getLcovFiles = function (src) {
return new Promise((resolve, reject) => {
glob(`${src}/**/lcov.info`, (error, result) => {
if (error) return reject(error);
resolve(result);
});
})
};
(async function(){
const files:any = await getLcovFiles('coverage');
// if no files reset directory
// if (files.length === 0) {
// // remove directory
// fs.rmdirSync('coverage', { recursive: true });
// fs.mkdirSync('coverage');
// }
// const cypressFiles = await getLcovFiles('apps/**/coverage')
// files = [...files, ...cypressFiles];
const mergedReport = files.reduce((mergedReport, currFile) => mergedReport += fs.readFileSync(currFile), '');
const mergedFile = path.resolve('./coverage/lcov.info');
// remove old merged file
if (fs.existsSync(mergedFile)) {
fs.unlinkSync(mergedFile);
}
await fs.writeFile(mergedFile, mergedReport, (err) => {
if (err) throw err;
console.log('The file has been saved!');
});
})();