@@ -289,6 +289,88 @@ test('coverage reports on lines, functions, and branches', skipIfNoInspector, as
289289 } ) ;
290290} ) ;
291291
292+ test ( 'coverage with source maps' , skipIfNoInspector , ( ) => {
293+ let report = [
294+ '# start of coverage report' ,
295+ '# --------------------------------------------------------------' ,
296+ '# file | line % | branch % | funcs % | uncovered lines' ,
297+ '# --------------------------------------------------------------' ,
298+ '# a.test.ts | 53.85 | 100.00 | 100.00 | 8-13' , // part of a bundle
299+ '# b.test.ts | 55.56 | 100.00 | 100.00 | 1 7-9' , // part of a bundle
300+ '# index.test.js | 71.43 | 66.67 | 100.00 | 6-7' , // no source map
301+ '# stdin.test.ts | 57.14 | 100.00 | 100.00 | 4-6' , // Source map without original file
302+ '# --------------------------------------------------------------' ,
303+ '# all files | 58.33 | 87.50 | 100.00 | ' ,
304+ '# --------------------------------------------------------------' ,
305+ '# end of coverage report' ,
306+ ] . join ( '\n' ) ;
307+
308+ if ( common . isWindows ) {
309+ report = report . replaceAll ( '/' , '\\' ) ;
310+ }
311+
312+ const fixture = fixtures . path ( 'test-runner' , 'coverage' ) ;
313+ const args = [
314+ '--test' , '--experimental-test-coverage' , '--test-reporter' , 'tap' ,
315+ ] ;
316+ const result = spawnSync ( process . execPath , args , { cwd : fixture } ) ;
317+
318+ assert . strictEqual ( result . stderr . toString ( ) , '' ) ;
319+ assert ( result . stdout . toString ( ) . includes ( report ) ) ;
320+ assert . strictEqual ( result . status , 1 ) ;
321+ } ) ;
322+
323+
324+ test ( 'coverage with --enable-source-maps option' , skipIfNoInspector , ( ) => {
325+ const fixture = fixtures . path ( 'test-runner' , 'coverage' , 'stdin.test.js' ) ;
326+ const args = [
327+ '--test' , '--experimental-test-coverage' , '--enable-source-maps' , '--test-reporter' , 'tap' ,
328+ fixture ,
329+ ] ;
330+
331+ let report = [
332+ '# start of coverage report' ,
333+ '# ------------------------------------------------------------------' ,
334+ '# file | line % | branch % | funcs % | uncovered lines' ,
335+ '# ------------------------------------------------------------------' ,
336+ '# test | | | | ' ,
337+ '# fixtures | | | | ' ,
338+ '# test-runner | | | | ' ,
339+ '# coverage | | | | ' ,
340+ '# stdin.test.ts | 57.14 | 100.00 | 100.00 | 4-6' ,
341+ '# ------------------------------------------------------------------' ,
342+ '# all files | 57.14 | 100.00 | 100.00 | ' ,
343+ '# ------------------------------------------------------------------' ,
344+ '# end of coverage report' ,
345+ ] . join ( '\n' ) ;
346+
347+ if ( common . isWindows ) {
348+ report = report . replaceAll ( '/' , '\\' ) ;
349+ }
350+
351+ const result = spawnSync ( process . execPath , args ) ;
352+ const stdOut = result . stdout . toString ( ) ;
353+
354+ assert . strictEqual ( result . stderr . toString ( ) , '' ) ;
355+ assert ( ! stdOut . includes ( 'TypeError' ) ) ;
356+ assert ( stdOut . includes ( report ) ) ;
357+ assert . strictEqual ( result . status , 0 ) ;
358+ } ) ;
359+
360+ test ( 'coverage with source maps missing sources' , skipIfNoInspector , ( ) => {
361+ const file = fixtures . path ( 'test-runner' , 'source-map-missing-sources' , 'index.js' ) ;
362+ const missing = fixtures . path ( 'test-runner' , 'source-map-missing-sources' , 'nonexistent.js' ) ;
363+ const result = spawnSync ( process . execPath , [
364+ '--test' ,
365+ '--experimental-test-coverage' ,
366+ file ,
367+ ] ) ;
368+
369+ const error = `Cannot find '${ pathToFileURL ( missing ) } ' imported from the source map for '${ pathToFileURL ( file ) } '` ;
370+ assert ( result . stdout . toString ( ) . includes ( error ) ) ;
371+ assert . strictEqual ( result . status , 1 ) ;
372+ } ) ;
373+
292374test ( 'coverage with ESM hook - source irrelevant' , skipIfNoInspector , ( ) => {
293375 let report = [
294376 '# start of coverage report' ,
0 commit comments