-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcoverage-transform.js
40 lines (37 loc) · 1.19 KB
/
coverage-transform.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
/* eslint-disable @typescript-eslint/no-var-requires */
const path = require('path');
const { readFileSync, writeFileSync } = require('fs');
function fixLcovFilepaths() {
const lcovFile = path.resolve(__dirname, './coverage/lcov.info');
const rawFile = readFileSync(lcovFile, 'utf8');
const rebuiltPaths = rawFile
.split('\n')
.map((singleLine) => {
if (singleLine.startsWith('SF:')) {
return singleLine.replace('SF:../', `SF:${__dirname}/packages/`);
}
return singleLine;
})
.join('\n');
writeFileSync(lcovFile, rebuiltPaths, 'utf8');
return rebuiltPaths;
}
function fixSonarReportFilePaths() {
const sonarReportFile = path.resolve(__dirname, './coverage/sonar-report.xml');
const rawFile = readFileSync(sonarReportFile, 'utf8');
const rebuiltPaths = rawFile
.split('\n')
.map((singleLine) => {
if (singleLine.startsWith('<file path=')) {
return singleLine.replace('<file path="packages/', `<file path="${__dirname}/packages/`);
}
return singleLine;
})
.join('\n');
writeFileSync(sonarReportFile, rebuiltPaths, 'utf8');
return rebuiltPaths;
}
(() => {
fixLcovFilepaths();
fixSonarReportFilePaths();
})();