From 452d29c62bb0817114d1bd573ce61093180e5bd0 Mon Sep 17 00:00:00 2001 From: Pulkit Gupta Date: Fri, 15 Dec 2023 12:23:08 +0530 Subject: [PATCH] test_runner: format coverage report for tap reporter PR-URL: https://github.com/nodejs/node/pull/51119 Reviewed-By: Raz Luvaton Reviewed-By: Luigi Pinca Reviewed-By: Moshe Atlow Reviewed-By: Debadree Chatterjee --- lib/internal/test_runner/reporter/tap.js | 2 +- test/parallel/test-runner-coverage.js | 38 +++++++++++++----------- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/lib/internal/test_runner/reporter/tap.js b/lib/internal/test_runner/reporter/tap.js index 1f60cfa619886e..e8cf727daede64 100644 --- a/lib/internal/test_runner/reporter/tap.js +++ b/lib/internal/test_runner/reporter/tap.js @@ -58,7 +58,7 @@ async function * tapReporter(source) { yield `${indent(data.nesting)}# ${tapEscape(data.message)}\n`; break; case 'test:coverage': - yield getCoverageReport(indent(data.nesting), data.summary, '# ', ''); + yield getCoverageReport(indent(data.nesting), data.summary, '# ', '', true); break; } } diff --git a/test/parallel/test-runner-coverage.js b/test/parallel/test-runner-coverage.js index 2532f9971c213d..d8181417205b46 100644 --- a/test/parallel/test-runner-coverage.js +++ b/test/parallel/test-runner-coverage.js @@ -22,16 +22,21 @@ function findCoverageFileForPid(pid) { } function getTapCoverageFixtureReport() { + /* eslint-disable max-len */ const report = [ '# start of coverage report', - '# file | line % | branch % | funcs % | uncovered lines', - '# test/fixtures/test-runner/coverage.js | 78.65 | 38.46 | 60.00 | 12, ' + - '13, 16, 17, 18, 19, 20, 21, 22, 27, 39, 43, 44, 61, 62, 66, 67, 71, 72', - '# test/fixtures/test-runner/invalid-tap.js | 100.00 | 100.00 | 100.00 | ', - '# test/fixtures/v8-coverage/throw.js | 71.43 | 50.00 | 100.00 | 5, 6', - '# all files | 78.35 | 43.75 | 60.00 |', + '# -------------------------------------------------------------------------------------------------------------------', + '# file | line % | branch % | funcs % | uncovered lines', + '# -------------------------------------------------------------------------------------------------------------------', + '# test/fixtures/test-runner/coverage.js | 78.65 | 38.46 | 60.00 | 12-13 16-22 27 39 43-44 61-62 66-67 71-72', + '# test/fixtures/test-runner/invalid-tap.js | 100.00 | 100.00 | 100.00 | ', + '# test/fixtures/v8-coverage/throw.js | 71.43 | 50.00 | 100.00 | 5-6', + '# -------------------------------------------------------------------------------------------------------------------', + '# all files | 78.35 | 43.75 | 60.00 |', + '# -------------------------------------------------------------------------------------------------------------------', '# end of coverage report', ].join('\n'); + /* eslint-enable max-len */ if (common.isWindows) { return report.replaceAll('/', '\\'); @@ -88,7 +93,6 @@ test('test tap coverage reporter', skipIfNoInspector, async (t) => { const options = { env: { ...process.env, NODE_V8_COVERAGE: tmpdir.path } }; const result = spawnSync(process.execPath, args, options); const report = getTapCoverageFixtureReport(); - assert(result.stdout.toString().includes(report)); assert.strictEqual(result.stderr.toString(), ''); assert.strictEqual(result.status, 0); @@ -152,16 +156,16 @@ test('single process coverage is the same with --test', skipIfNoInspector, () => test('coverage is combined for multiple processes', skipIfNoInspector, () => { let report = [ '# start of coverage report', - '# file | line % | branch % | funcs % | uncovered lines', - '# common.js | 89.86 | ' + - '62.50 | 100.00 | 8, 13, 14, 18, 34, 35, 53', - '# first.test.js | 83.33 | ' + - '100.00 | 50.00 | 5, 6', - '# second.test.js | 100.00 ' + - '| 100.00 | 100.00 | ', - '# third.test.js | 100.00 | ' + - '100.00 | 100.00 | ', - '# all files | 92.11 | 72.73 | 88.89 |', + '# -------------------------------------------------------------------', + '# file | line % | branch % | funcs % | uncovered lines', + '# -------------------------------------------------------------------', + '# common.js | 89.86 | 62.50 | 100.00 | 8 13-14 18 34-35 53', + '# first.test.js | 83.33 | 100.00 | 50.00 | 5-6', + '# second.test.js | 100.00 | 100.00 | 100.00 | ', + '# third.test.js | 100.00 | 100.00 | 100.00 | ', + '# -------------------------------------------------------------------', + '# all files | 92.11 | 72.73 | 88.89 |', + '# -------------------------------------------------------------------', '# end of coverage report', ].join('\n');