@@ -4,13 +4,14 @@ const path = require('node:path');
44const test = require ( 'node:test' ) ;
55const fs = require ( 'node:fs/promises' ) ;
66const assert = require ( 'node:assert/strict' ) ;
7+ const { pathToFileURL } = require ( 'node:url' ) ;
78const { hostname } = require ( 'node:os' ) ;
89
910const stackFramesRegexp = / (?< = \n ) ( \s + ) ( ( .+ ?) \s + \( ) ? (?: \( ? ( .+ ?) : ( \d + ) (?: : ( \d + ) ) ? ) \) ? ( \s + \{ ) ? ( \[ \d + m ) ? ( \n | $ ) / g;
1011const windowNewlineRegexp = / \r / g;
1112
1213function replaceNodeVersion ( str ) {
13- return str . replaceAll ( process . version , '* ' ) ;
14+ return str . replaceAll ( process . version , '<node-version> ' ) ;
1415}
1516
1617function replaceStackTrace ( str , replacement = '$1*$7$8\n' ) {
@@ -31,10 +32,28 @@ function replaceWindowsPaths(str) {
3132 return common . isWindows ? str . replaceAll ( path . win32 . sep , path . posix . sep ) : str ;
3233}
3334
35+ function replaceTrailingSpaces ( str ) {
36+ return str . replaceAll ( / [ \t ] + \n / g, '\n' ) ;
37+ }
38+
39+ // Replaces customized or platform specific executable names to be `node`.
40+ function generalizeExeName ( str ) {
41+ const baseName = path . basename ( process . argv0 || 'node' , '.exe' ) ;
42+ return str . replaceAll ( `${ baseName } --` , 'node --' ) ;
43+ }
44+
45+ function replaceWarningPid ( str ) {
46+ return str . replaceAll ( / \( n o d e : \d + \) / g, '(node:<pid>)' ) ;
47+ }
48+
3449function transformProjectRoot ( replacement = '' ) {
3550 const projectRoot = path . resolve ( __dirname , '../..' ) ;
51+ // Handles URL encoded project root in file URL strings as well.
52+ const urlEncoded = pathToFileURL ( projectRoot ) . pathname ;
3653 return ( str ) => {
37- return str . replaceAll ( '\\\'' , "'" ) . replaceAll ( projectRoot , replacement ) ;
54+ return str . replaceAll ( '\\\'' , "'" )
55+ . replaceAll ( projectRoot , replacement )
56+ . replaceAll ( urlEncoded , replacement ) ;
3857 } ;
3958}
4059
@@ -152,32 +171,41 @@ function pickTestFileFromLcov(str) {
152171 ) ;
153172}
154173
155- const defaultTransform = transform (
174+ // Transforms basic patterns like:
175+ // - platform specific path and line endings,
176+ // - line trailing spaces,
177+ // - executable specific path and versions.
178+ const basicTransform = transform (
156179 replaceWindowsLineEndings ,
157- replaceStackTrace ,
180+ replaceTrailingSpaces ,
158181 removeWindowsPathEscaping ,
159- transformProjectRoot ( ) ,
160182 replaceWindowsPaths ,
183+ replaceNodeVersion ,
184+ generalizeExeName ,
185+ replaceWarningPid ,
186+ ) ;
187+
188+ const defaultTransform = transform (
189+ basicTransform ,
190+ replaceStackTrace ,
191+ transformProjectRoot ( ) ,
161192 replaceTestDuration ,
162193 replaceTestLocationLine ,
163194) ;
164195const specTransform = transform (
165196 replaceSpecDuration ,
166- replaceWindowsLineEndings ,
197+ basicTransform ,
167198 replaceStackTrace ,
168- replaceWindowsPaths ,
169199) ;
170200const junitTransform = transform (
171201 replaceJunitDuration ,
172- replaceWindowsLineEndings ,
202+ basicTransform ,
173203 replaceStackTrace ,
174- replaceWindowsPaths ,
175204) ;
176205const lcovTransform = transform (
177- replaceWindowsLineEndings ,
206+ basicTransform ,
178207 replaceStackTrace ,
179208 transformProjectRoot ( ) ,
180- replaceWindowsPaths ,
181209 pickTestFileFromLcov ,
182210) ;
183211
@@ -204,6 +232,7 @@ module.exports = {
204232 transform,
205233 transformProjectRoot,
206234 replaceTestDuration,
235+ basicTransform,
207236 defaultTransform,
208237 specTransform,
209238 junitTransform,
0 commit comments