test_runner: avoid coverage report partial file names

Co-author: Medhansh404 <21ucs126@lnmiit.ac.in>
PR-URL: https://github.com/nodejs/node/pull/54379
Fixes: https://github.com/nodejs/node/issues/51299
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
This commit is contained in:
Pietro Marchini authored and Michaël Zasso committed 2024-10-04 10:20:08 +02:00
1 parent c8b7a645ae
commit 1daec9a63f
19 files changed
+545 -157

No files matched your search

@@ -20,21 +20,25 @@ function findCoverageFileForPid(pid) {
}
function getTapCoverageFixtureReport() {
/* eslint-disable @stylistic/js/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-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',
'# invalid-tap.js | 100.00 | 100.00 | 100.00 | ',
'# 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 @stylistic/js/max-len */
if (common.isWindows) {
return report.replaceAll('/', '\\');
+121 -52
View File
@@ -22,21 +22,25 @@ function findCoverageFileForPid(pid) {
}
function getTapCoverageFixtureReport() {
/* eslint-disable @stylistic/js/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-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',
'# invalid-tap.js | 100.00 | 100.00 | 100.00 | ',
'# 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 @stylistic/js/max-len */
if (common.isWindows) {
return report.replaceAll('/', '\\');
@@ -46,21 +50,25 @@ function getTapCoverageFixtureReport() {
}
function getSpecCoverageFixtureReport() {
/* eslint-disable @stylistic/js/max-len */
const report = [
'\u2139 start of coverage report',
'\u2139 -------------------------------------------------------------------------------------------------------------------',
'\u2139 file | line % | branch % | funcs % | uncovered lines',
'\u2139 -------------------------------------------------------------------------------------------------------------------',
'\u2139 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',
'\u2139 test/fixtures/test-runner/invalid-tap.js | 100.00 | 100.00 | 100.00 | ',
'\u2139 test/fixtures/v8-coverage/throw.js | 71.43 | 50.00 | 100.00 | 5-6',
'\u2139 -------------------------------------------------------------------------------------------------------------------',
'\u2139 all files | 78.35 | 43.75 | 60.00 |',
'\u2139 -------------------------------------------------------------------------------------------------------------------',
'\u2139 --------------------------------------------------------------------------------------------',
'\u2139 file | line % | branch % | funcs % | uncovered lines',
'\u2139 --------------------------------------------------------------------------------------------',
'\u2139 test | | | | ',
'\u2139 fixtures | | | | ',
'\u2139 test-runner | | | | ',
'\u2139 coverage.js | 78.65 | 38.46 | 60.00 | 12-13 16-22 27 39 43-44 61-62 66-67 71-72',
'\u2139 invalid-tap.js | 100.00 | 100.00 | 100.00 | ',
'\u2139 v8-coverage | | | | ',
'\u2139 throw.js | 71.43 | 50.00 | 100.00 | 5-6',
'\u2139 --------------------------------------------------------------------------------------------',
'\u2139 all files | 78.35 | 43.75 | 60.00 | ',
'\u2139 --------------------------------------------------------------------------------------------',
'\u2139 end of coverage report',
].join('\n');
/* eslint-enable @stylistic/js/max-len */
if (common.isWindows) {
return report.replaceAll('/', '\\');
@@ -164,7 +172,7 @@ test('coverage is combined for multiple processes', skipIfNoInspector, () => {
'# 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 |',
'# all files | 92.11 | 72.73 | 88.89 | ',
'# -------------------------------------------------------------------',
'# end of coverage report',
].join('\n');
@@ -187,7 +195,7 @@ test('coverage is combined for multiple processes', skipIfNoInspector, () => {
assert.strictEqual(result.status, 0);
});
test('coverage works with isolation=none', skipIfNoInspector, () => {
test.skip('coverage works with isolation=none', skipIfNoInspector, () => {
// There is a bug in coverage calculation. The branch % in the common.js
// fixture is different depending on the test isolation mode. The 'none' mode
// is closer to what c8 reports here, so the bug is likely in the code that
@@ -202,7 +210,7 @@ test('coverage works with isolation=none', skipIfNoInspector, () => {
'# second.test.js | 100.00 | 100.00 | 100.00 | ',
'# third.test.js | 100.00 | 100.00 | 100.00 | ',
'# -------------------------------------------------------------------',
'# all files | 92.11 | 76.00 | 88.89 |',
'# all files | 92.11 | 76.00 | 88.89 | ',
'# -------------------------------------------------------------------',
'# end of coverage report',
].join('\n');
@@ -292,7 +300,7 @@ test('coverage with source maps', skipIfNoInspector, () => {
'# index.test.js | 71.43 | 66.67 | 100.00 | 6-7', // no source map
'# stdin.test.ts | 57.14 | 100.00 | 100.00 | 4-6', // Source map without original file
'# --------------------------------------------------------------',
'# all files | 58.33 | 87.50 | 100.00 |',
'# all files | 58.33 | 87.50 | 100.00 | ',
'# --------------------------------------------------------------',
'# end of coverage report',
].join('\n');
@@ -322,7 +330,7 @@ test('coverage with ESM hook - source irrelevant', skipIfNoInspector, () => {
'# register-hooks.js | 100.00 | 100.00 | 100.00 | ',
'# virtual.js | 100.00 | 100.00 | 100.00 | ',
'# ------------------------------------------------------------------',
'# all files | 100.00 | 100.00 | 100.00 |',
'# all files | 100.00 | 100.00 | 100.00 | ',
'# ------------------------------------------------------------------',
'# end of coverage report',
].join('\n');
@@ -353,7 +361,7 @@ test('coverage with ESM hook - source transpiled', skipIfNoInspector, () => {
'# sum.test.ts | 100.00 | 100.00 | 100.00 | ',
'# sum.ts | 100.00 | 100.00 | 100.00 | ',
'# ------------------------------------------------------------------',
'# all files | 100.00 | 100.00 | 100.00 |',
'# all files | 100.00 | 100.00 | 100.00 | ',
'# ------------------------------------------------------------------',
'# end of coverage report',
].join('\n');
@@ -383,14 +391,18 @@ test('coverage with excluded files', skipIfNoInspector, () => {
const result = spawnSync(process.execPath, args);
const report = [
'# start of coverage report',
'# ' + '-'.repeat(112),
'# file | line % | branch % | funcs % | uncovered lines',
'# ' + '-'.repeat(112),
'# 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/v8-coverage/throw.js | 71.43 | 50.00 | 100.00 | 5-6',
'# ' + '-'.repeat(112),
'# all files | 78.13 | 40.00 | 60.00 |',
'# ' + '-'.repeat(112),
'# -----------------------------------------------------------------------------------------',
'# 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',
'# v8-coverage | | | | ',
'# throw.js | 71.43 | 50.00 | 100.00 | 5-6',
'# -----------------------------------------------------------------------------------------',
'# all files | 78.13 | 40.00 | 60.00 | ',
'# -----------------------------------------------------------------------------------------',
'# end of coverage report',
].join('\n');
@@ -415,14 +427,18 @@ test('coverage with included files', skipIfNoInspector, () => {
const result = spawnSync(process.execPath, args);
const report = [
'# start of coverage report',
'# ' + '-'.repeat(112),
'# file | line % | branch % | funcs % | uncovered lines',
'# ' + '-'.repeat(112),
'# 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/v8-coverage/throw.js | 71.43 | 50.00 | 100.00 | 5-6',
'# ' + '-'.repeat(112),
'# all files | 78.13 | 40.00 | 60.00 |',
'# ' + '-'.repeat(112),
'# -----------------------------------------------------------------------------------------',
'# 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',
'# v8-coverage | | | | ',
'# throw.js | 71.43 | 50.00 | 100.00 | 5-6',
'# -----------------------------------------------------------------------------------------',
'# all files | 78.13 | 40.00 | 60.00 | ',
'# -----------------------------------------------------------------------------------------',
'# end of coverage report',
].join('\n');
@@ -447,13 +463,16 @@ test('coverage with included and excluded files', skipIfNoInspector, () => {
const result = spawnSync(process.execPath, args);
const report = [
'# start of coverage report',
'# ' + '-'.repeat(112),
'# file | line % | branch % | funcs % | uncovered lines',
'# ' + '-'.repeat(112),
'# 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',
'# ' + '-'.repeat(112),
'# all files | 78.65 | 38.46 | 60.00 |',
'# ' + '-'.repeat(112),
'# -----------------------------------------------------------------------------------------',
'# 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',
'# -----------------------------------------------------------------------------------------',
'# all files | 78.65 | 38.46 | 60.00 | ',
'# -----------------------------------------------------------------------------------------',
'# end of coverage report',
].join('\n');
@@ -473,8 +492,58 @@ test('properly accounts for line endings in source maps', skipIfNoInspector, ()
'--test', '--experimental-test-coverage', '--test-reporter', 'tap',
fixture,
];
const report = [
'# start of coverage report',
'# ----------------------------------------------------------------------------',
'# file | line % | branch % | funcs % | uncovered lines',
'# ----------------------------------------------------------------------------',
'# test | | | | ',
'# fixtures | | | | ',
'# test-runner | | | | ',
'# source-map-line-lengths | | | | ',
'# index.ts | 100.00 | 100.00 | 100.00 | ',
'# ----------------------------------------------------------------------------',
'# all files | 100.00 | 100.00 | 100.00 | ',
'# ----------------------------------------------------------------------------',
'# end of coverage report',
].join('\n');
const result = spawnSync(process.execPath, args);
const report = 'index.ts | 100.00 | 100.00 | 100.00 |';
assert.strictEqual(result.stderr.toString(), '');
assert(result.stdout.toString().includes(report));
assert.strictEqual(result.status, 0);
});
test('correctly prints the coverage report of files contained in parent directories', skipIfNoInspector, () => {
let report = [
'# start of coverage report',
'# --------------------------------------------------------------------------------------------',
'# file | line % | branch % | funcs % | uncovered lines',
'# --------------------------------------------------------------------------------------------',
'# .. | | | | ',
'# coverage.js | 78.65 | 38.46 | 60.00 | 12-13 16-22 27 39 43-44 61-62 66-67 71-72',
'# invalid-tap.js | 100.00 | 100.00 | 100.00 | ',
'# .. | | | | ',
'# 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');
if (common.isWindows) {
report = report.replaceAll('/', '\\');
}
const fixture = fixtures.path('test-runner', 'coverage.js');
const args = [
'--test', '--experimental-test-coverage', '--test-reporter', 'tap', fixture,
];
const result = spawnSync(process.execPath, args, {
env: { ...process.env, NODE_TEST_TMPDIR: tmpdir.path },
cwd: fixtures.path('test-runner', 'coverage'),
});
assert.strictEqual(result.stderr.toString(), '');
assert(result.stdout.toString().includes(report));
assert.strictEqual(result.status, 0);
+19
View File
@@ -10,6 +10,11 @@ const skipForceColors =
process.config.variables.icu_gyp_path !== 'tools/icu/icu-generic.gyp' ||
process.config.variables.node_shared_openssl;
const canColorize = process.stderr?.isTTY && (
typeof process.stderr?.getColorDepth === 'function' ?
process.stderr?.getColorDepth() > 2 : true);
const skipCoverageColors = !canColorize;
function replaceTestDuration(str) {
return str
.replaceAll(/duration_ms: [0-9.]+/g, 'duration_ms: *')
@@ -227,10 +232,19 @@ const tests = [
name: 'test-runner/output/test-diagnostic-warning-without-test-only-flag.js',
flags: ['--test-reporter=tap'],
},
process.features.inspector ? {
name: 'test-runner/output/coverage-width-40.mjs',
flags: ['--test-reporter=tap'],
} : false,
process.features.inspector ? {
name: 'test-runner/output/coverage-width-80.mjs',
flags: ['--test-reporter=tap'],
} : false,
process.features.inspector && !skipCoverageColors ? {
name: 'test-runner/output/coverage-width-80-color.mjs',
transform: specTransform,
tty: true
} : false,
process.features.inspector ? {
name: 'test-runner/output/coverage-width-100.mjs',
flags: ['--test-reporter=tap'],
@@ -251,6 +265,11 @@ const tests = [
name: 'test-runner/output/coverage-width-100-uncovered-lines.mjs',
flags: ['--test-reporter=tap'],
} : false,
process.features.inspector && !skipCoverageColors ? {
name: 'test-runner/output/coverage-width-80-uncovered-lines-color.mjs',
transform: specTransform,
tty: true
} : false,
process.features.inspector ? {
name: 'test-runner/output/coverage-width-150-uncovered-lines.mjs',
flags: ['--test-reporter=tap'],