Skip to content

Commit e440d39

Browse files
committed
test: test case when --enable-source-maps is provided
1 parent 38126ee commit e440d39

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

Diff for: lib/internal/test_runner/test.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ const {
1414
Number,
1515
NumberPrototypeToFixed,
1616
ObjectDefineProperty,
17-
ObjectKeys,
1817
ObjectSeal,
1918
Promise,
2019
PromisePrototypeThen,
@@ -561,7 +560,7 @@ class Test extends AsyncResource {
561560
const map = lazyFindSourceMap(this.loc.file);
562561
const entry = map?.findEntry(this.loc.line - 1, this.loc.column - 1);
563562

564-
if (entry !== undefined && ObjectKeys(entry).length > 0) {
563+
if (entry?.originalSource !== undefined) {
565564
this.loc.line = entry.originalLine + 1;
566565
this.loc.column = entry.originalColumn + 1;
567566
this.loc.file = entry.originalSource;

Diff for: test/parallel/test-runner-coverage.js

+37
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,43 @@ test('coverage with source maps', skipIfNoInspector, () => {
321321
assert.strictEqual(result.status, 1);
322322
});
323323

324+
325+
test('coverage with --enable-source-maps option', skipIfNoInspector, () => {
326+
const fixture = fixtures.path('test-runner', 'coverage', 'stdin.test.js');
327+
const args = [
328+
'--test', '--experimental-test-coverage', '--enable-source-maps', '--test-reporter', 'tap',
329+
fixture,
330+
];
331+
332+
let report = [
333+
'# start of coverage report',
334+
'# ------------------------------------------------------------------',
335+
'# file | line % | branch % | funcs % | uncovered lines',
336+
'# ------------------------------------------------------------------',
337+
'# test | | | | ',
338+
'# fixtures | | | | ',
339+
'# test-runner | | | | ',
340+
'# coverage | | | | ',
341+
'# stdin.test.ts | 57.14 | 100.00 | 100.00 | 4-6',
342+
'# ------------------------------------------------------------------',
343+
'# all files | 57.14 | 100.00 | 100.00 | ',
344+
'# ------------------------------------------------------------------',
345+
'# end of coverage report',
346+
].join('\n');
347+
348+
if (common.isWindows) {
349+
report = report.replaceAll('/', '\\');
350+
}
351+
352+
const result = spawnSync(process.execPath, args);
353+
const stdOut = result.stdout.toString();
354+
355+
assert.strictEqual(result.stderr.toString(), '');
356+
assert(!stdOut.includes('TypeError'));
357+
assert(stdOut.includes(report));
358+
assert.strictEqual(result.status, 0);
359+
});
360+
324361
test('coverage with source maps missing sources', skipIfNoInspector, () => {
325362
const file = fixtures.path('test-runner', 'source-map-missing-sources', 'index.js');
326363
const missing = fixtures.path('test-runner', 'source-map-missing-sources', 'nonexistent.js');

0 commit comments

Comments
 (0)