@@ -3,27 +3,22 @@ import { test } from 'node:test';
33import * as fixtures from '../common/fixtures.mjs' ;
44import { spawnSync } from 'node:child_process' ;
55import assert from 'node:assert' ;
6- import { EOL } from 'node:os' ;
76
87test ( 'correctly reports error for a longer stack trace' , ( ) => {
98 // The following regex matches the error message that is expected to be thrown
109 //
11- // package-type-module/require-esm-error-annotation/longer-stack .cjs:6
10+ // package-type-module/require-esm-error-annotation/index .cjs:6
1211 // require('./app.js')
1312 // ^
1413
1514 const fixture = fixtures . path ( 'es-modules/package-type-module/require-esm-error-annotation/index.cjs' ) ;
1615 const args = [ '--no-experimental-require-module' , fixture ] ;
17-
18- const lineNumber = 6 ;
19- const lineContent = "require('./app.js')" ;
20- const fullMessage = `${ fixture } :${ lineNumber } ${ EOL } ${ lineContent } ${ EOL } ^${ EOL } ` ;
16+ const regex = / i n d e x \. c j s : 6 [ \n \r ] + \s { 2 } r e q u i r e \( ' \. \/ a p p \. j s ' \) [ \n \r ] + \s { 2 } \^ / ;
2117
2218 const result = spawnSync ( process . execPath , args ) ;
23-
24- console . log ( `STDERR: ${ result . stderr . toString ( ) } ` ) ;
19+ const stderr = result . stderr . toString ( ) ;
2520
2621 assert . strictEqual ( result . status , 1 ) ;
2722 assert . strictEqual ( result . stdout . toString ( ) , '' ) ;
28- assert ( result . stderr . toString ( ) . indexOf ( fullMessage ) > - 1 ) ;
23+ assert . match ( stderr , regex ) ;
2924} ) ;
0 commit comments