Skip to content

Commit

Permalink
fix(builtin): fix coverage source file paths
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabian Wiles authored and alexeagle committed Feb 11, 2021
1 parent 17e535f commit ae4ec78
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
11 changes: 10 additions & 1 deletion internal/coverage/lcov_merger-js.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
const crypto = require("crypto");
const fs = require("fs");
const path = require("path");
const readline = require("readline");
function _getArg(argv, key) {
return argv.find(a => a.startsWith(key)).split('=')[1];
}
Expand Down Expand Up @@ -62,7 +63,15 @@ function main() {
reporter: ['lcovonly']
})
.run();
fs.copyFileSync(path.join(c8OutputDir, 'lcov.info'), outputFile);
const inputFile = path.join(c8OutputDir, 'lcov.info');
const input = readline.createInterface({
input: fs.createReadStream(inputFile),
});
const output = fs.createWriteStream(outputFile);
input.on('line', line => {
const patched = line.replace('SF:../../../', 'SF:');
output.write(patched + '\n');
});
});
}
if (require.main === module) {
Expand Down
15 changes: 13 additions & 2 deletions internal/coverage/lcov_merger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import * as crypto from 'crypto';
import * as fs from 'fs';
import * as path from 'path';
import * as readline from 'readline';

function _getArg(argv: string[], key: string): string {
return argv.find(a => a.startsWith(key))!.split('=')[1];
Expand Down Expand Up @@ -103,8 +104,18 @@ async function main() {
})
.run();
// moves the report into the files bazel expects
// lcovonly names this file lcov.info
fs.copyFileSync(path.join(c8OutputDir, 'lcov.info'), outputFile);
// and fixes the paths as we're moving it up 3 dirs
const inputFile = path.join(c8OutputDir, 'lcov.info');
// we want to do this 1 line at a time to avoid using too much memory
const input = readline.createInterface({
input: fs.createReadStream(inputFile),
});
const output = fs.createWriteStream(outputFile);

input.on('line', line => {
const patched = line.replace('SF:../../../', 'SF:')
output.write(patched + '\n');
});
}

if (require.main === module) {
Expand Down

0 comments on commit ae4ec78

Please sign in to comment.