From ae4ec78a0ba1e0a9056879aff5683ca783a98c7d Mon Sep 17 00:00:00 2001 From: Fabian Wiles Date: Tue, 2 Feb 2021 15:15:25 +1300 Subject: [PATCH] fix(builtin): fix coverage source file paths --- internal/coverage/lcov_merger-js.js | 11 ++++++++++- internal/coverage/lcov_merger.ts | 15 +++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/internal/coverage/lcov_merger-js.js b/internal/coverage/lcov_merger-js.js index 7d6ac99d77..a016af7273 100644 --- a/internal/coverage/lcov_merger-js.js +++ b/internal/coverage/lcov_merger-js.js @@ -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]; } @@ -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) { diff --git a/internal/coverage/lcov_merger.ts b/internal/coverage/lcov_merger.ts index 1185dd7c8c..3f66c490ac 100644 --- a/internal/coverage/lcov_merger.ts +++ b/internal/coverage/lcov_merger.ts @@ -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]; @@ -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) {