Skip to content

Commit ae4ec78

Browse files
Fabian Wilesalexeagle
authored andcommitted
fix(builtin): fix coverage source file paths
1 parent 17e535f commit ae4ec78

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

internal/coverage/lcov_merger-js.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
1212
const crypto = require("crypto");
1313
const fs = require("fs");
1414
const path = require("path");
15+
const readline = require("readline");
1516
function _getArg(argv, key) {
1617
return argv.find(a => a.startsWith(key)).split('=')[1];
1718
}
@@ -62,7 +63,15 @@ function main() {
6263
reporter: ['lcovonly']
6364
})
6465
.run();
65-
fs.copyFileSync(path.join(c8OutputDir, 'lcov.info'), outputFile);
66+
const inputFile = path.join(c8OutputDir, 'lcov.info');
67+
const input = readline.createInterface({
68+
input: fs.createReadStream(inputFile),
69+
});
70+
const output = fs.createWriteStream(outputFile);
71+
input.on('line', line => {
72+
const patched = line.replace('SF:../../../', 'SF:');
73+
output.write(patched + '\n');
74+
});
6675
});
6776
}
6877
if (require.main === module) {

internal/coverage/lcov_merger.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import * as crypto from 'crypto';
1919
import * as fs from 'fs';
2020
import * as path from 'path';
21+
import * as readline from 'readline';
2122

2223
function _getArg(argv: string[], key: string): string {
2324
return argv.find(a => a.startsWith(key))!.split('=')[1];
@@ -103,8 +104,18 @@ async function main() {
103104
})
104105
.run();
105106
// moves the report into the files bazel expects
106-
// lcovonly names this file lcov.info
107-
fs.copyFileSync(path.join(c8OutputDir, 'lcov.info'), outputFile);
107+
// and fixes the paths as we're moving it up 3 dirs
108+
const inputFile = path.join(c8OutputDir, 'lcov.info');
109+
// we want to do this 1 line at a time to avoid using too much memory
110+
const input = readline.createInterface({
111+
input: fs.createReadStream(inputFile),
112+
});
113+
const output = fs.createWriteStream(outputFile);
114+
115+
input.on('line', line => {
116+
const patched = line.replace('SF:../../../', 'SF:')
117+
output.write(patched + '\n');
118+
});
108119
}
109120

110121
if (require.main === module) {

0 commit comments

Comments
 (0)