@@ -6,6 +6,7 @@ const { readdirSync } = require('node:fs');
66const { test } = require ( 'node:test' ) ;
77const fixtures = require ( '../common/fixtures' ) ;
88const tmpdir = require ( '../common/tmpdir' ) ;
9+ const { pathToFileURL } = require ( 'node:url' ) ;
910const skipIfNoInspector = {
1011 skip : ! process . features . inspector ? 'inspector disabled' : false
1112} ;
@@ -320,6 +321,20 @@ test('coverage with source maps', skipIfNoInspector, () => {
320321 assert . strictEqual ( result . status , 1 ) ;
321322} ) ;
322323
324+ test ( 'coverage with source maps missing sources' , skipIfNoInspector , ( ) => {
325+ const file = fixtures . path ( 'test-runner' , 'source-map' , 'missing-sources' , 'index.js' ) ;
326+ const missing = fixtures . path ( 'test-runner' , 'source-map' , 'missing-sources' , 'nonexistent.js' ) ;
327+ const result = spawnSync ( process . execPath , [
328+ '--test' ,
329+ '--experimental-test-coverage' ,
330+ file ,
331+ ] ) ;
332+
333+ const error = `Cannot find '${ pathToFileURL ( missing ) } ' imported from the source map for '${ pathToFileURL ( file ) } '` ;
334+ assert ( result . stdout . toString ( ) . includes ( error ) ) ;
335+ assert . strictEqual ( result . status , 1 ) ;
336+ } ) ;
337+
323338test ( 'coverage with ESM hook - source irrelevant' , skipIfNoInspector , ( ) => {
324339 let report = [
325340 '# start of coverage report' ,
@@ -487,24 +502,25 @@ test('coverage with included and excluded files', skipIfNoInspector, () => {
487502} ) ;
488503
489504test ( 'properly accounts for line endings in source maps' , skipIfNoInspector , ( ) => {
490- const fixture = fixtures . path ( 'test-runner' , 'source-map- line-lengths' , 'index.js' ) ;
505+ const fixture = fixtures . path ( 'test-runner' , 'source-map' , ' line-lengths', 'index.js' ) ;
491506 const args = [
492507 '--test' , '--experimental-test-coverage' , '--test-reporter' , 'tap' ,
493508 fixture ,
494509 ] ;
495510 const report = [
496511 '# start of coverage report' ,
497- '# ----------------------------------------------------------------------------' ,
498- '# file | line % | branch % | funcs % | uncovered lines' ,
499- '# ----------------------------------------------------------------------------' ,
500- '# test | | | | ' ,
501- '# fixtures | | | | ' ,
502- '# test-runner | | | | ' ,
503- '# source-map-line-lengths | | | | ' ,
504- '# index.ts | 100.00 | 100.00 | 100.00 | ' ,
505- '# ----------------------------------------------------------------------------' ,
506- '# all files | 100.00 | 100.00 | 100.00 | ' ,
507- '# ----------------------------------------------------------------------------' ,
512+ '# ------------------------------------------------------------------' ,
513+ '# file | line % | branch % | funcs % | uncovered lines' ,
514+ '# ------------------------------------------------------------------' ,
515+ '# test | | | | ' ,
516+ '# fixtures | | | | ' ,
517+ '# test-runner | | | | ' ,
518+ '# source-map | | | | ' ,
519+ '# line-lengths | | | | ' ,
520+ '# index.ts | 100.00 | 100.00 | 100.00 | ' ,
521+ '# ------------------------------------------------------------------' ,
522+ '# all files | 100.00 | 100.00 | 100.00 | ' ,
523+ '# ------------------------------------------------------------------' ,
508524 '# end of coverage report' ,
509525 ] . join ( '\n' ) ;
510526
0 commit comments