@@ -8,6 +8,11 @@ const assert = require('node:assert/strict');
88const stackFramesRegexp = / (?< = \n ) ( \s + ) ( ( .+ ?) \s + \( ) ? (?: \( ? ( .+ ?) : ( \d + ) (?: : ( \d + ) ) ? ) \) ? ( \s + \{ ) ? ( \[ \d + m ) ? ( \n | $ ) / g;
99const windowNewlineRegexp = / \r / g;
1010
11+ function replaceExperimentalWarning ( str ) {
12+ return str . replace ( / \( n o d e : \d + \) E x p e r i m e n t a l W a r n i n g : ( .* ) \n / g, '' )
13+ . replace ( '(Use `node --trace-warnings ...` to show where the warning was created)\n' , '' ) ;
14+ }
15+
1116function replaceNodeVersion ( str ) {
1217 return str . replaceAll ( process . version , '*' ) ;
1318}
@@ -16,6 +21,10 @@ function replaceStackTrace(str, replacement = '$1*$7$8\n') {
1621 return str . replace ( stackFramesRegexp , replacement ) ;
1722}
1823
24+ function replaceInternalStackTrace ( str ) {
25+ return str . replaceAll ( / ( \W + ) .* n o d e : i n t e r n a l .* / g, '$1*' ) ;
26+ }
27+
1928function replaceWindowsLineEndings ( str ) {
2029 return str . replace ( windowNewlineRegexp , '' ) ;
2130}
@@ -24,8 +33,20 @@ function replaceWindowsPaths(str) {
2433 return common . isWindows ? str . replaceAll ( path . win32 . sep , path . posix . sep ) : str ;
2534}
2635
27- function replaceFullPaths ( str ) {
28- return str . replaceAll ( '\\\'' , "'" ) . replaceAll ( path . resolve ( __dirname , '../..' ) , '' ) ;
36+ function replaceWindowsDriveLetter ( str ) {
37+ if ( ! common . isWindows ) {
38+ return str ;
39+ }
40+ const currentDriveLetter = path . parse ( process . cwd ( ) ) . root . substring ( 0 , 1 ) . toLowerCase ( ) ;
41+ const regex = new RegExp ( `${ currentDriveLetter } :` , 'gi' ) ;
42+ return str . replaceAll ( '\\\'' , "'" ) . replaceAll ( regex , '' ) ;
43+ }
44+
45+ function transformCwd ( replacement = '' ) {
46+ const cwd = process . cwd ( ) ;
47+ return ( str ) => {
48+ return str . replaceAll ( '\\\'' , "'" ) . replaceAll ( cwd , replacement ) ;
49+ } ;
2950}
3051
3152function transform ( ...args ) {
@@ -94,11 +115,14 @@ async function spawnAndAssert(filename, transform = (x) => x, { tty = false, ...
94115module . exports = {
95116 assertSnapshot,
96117 getSnapshotPath,
97- replaceFullPaths ,
118+ replaceExperimentalWarning ,
98119 replaceNodeVersion,
99120 replaceStackTrace,
121+ replaceInternalStackTrace,
100122 replaceWindowsLineEndings,
101123 replaceWindowsPaths,
124+ replaceWindowsDriveLetter,
102125 spawnAndAssert,
103126 transform,
127+ transformCwd,
104128} ;
0 commit comments