@@ -10,14 +10,15 @@ const skipForceColors =
10
10
( common . isWindows && ( Number ( os . release ( ) . split ( '.' ) [ 0 ] ) !== 10 || Number ( os . release ( ) . split ( '.' ) [ 2 ] ) < 14393 ) ) ; // See https://github.com/nodejs/node/pull/33132
11
11
12
12
13
- function replaceNodeVersion ( str ) {
14
- return str . replaceAll ( process . version , '*' ) ;
15
- }
16
-
17
13
function replaceStackTrace ( str ) {
18
14
return snapshot . replaceStackTrace ( str , '$1at *$7\n' ) ;
19
15
}
20
16
17
+ function replaceForceColorsStackTrace ( str ) {
18
+ // eslint-disable-next-line no-control-regex
19
+ return str . replaceAll ( / ( \[ 9 0 m \W + ) a t .* n o d e : .* / g, '$1at *[39m' ) ;
20
+ }
21
+
21
22
describe ( 'errors output' , { concurrency : true } , ( ) => {
22
23
function normalize ( str ) {
23
24
return str . replaceAll ( snapshot . replaceWindowsPaths ( process . cwd ( ) ) , '' ) . replaceAll ( '//' , '*' ) . replaceAll ( / \/ ( \w ) / g, '*$1' ) . replaceAll ( '*test*' , '*' ) . replaceAll ( '*fixtures*errors*' , '*' ) . replaceAll ( 'file:**' , 'file:*/' ) ;
@@ -28,9 +29,12 @@ describe('errors output', { concurrency: true }, () => {
28
29
}
29
30
const common = snapshot
30
31
. transform ( snapshot . replaceWindowsLineEndings , snapshot . replaceWindowsPaths ) ;
31
- const defaultTransform = snapshot . transform ( common , normalize , replaceNodeVersion ) ;
32
- const errTransform = snapshot . transform ( common , normalizeNoNumbers , replaceNodeVersion ) ;
33
- const promiseTransform = snapshot . transform ( common , replaceStackTrace , normalizeNoNumbers , replaceNodeVersion ) ;
32
+ const defaultTransform = snapshot . transform ( common , normalize , snapshot . replaceNodeVersion ) ;
33
+ const errTransform = snapshot . transform ( common , normalizeNoNumbers , snapshot . replaceNodeVersion ) ;
34
+ const promiseTransform = snapshot . transform ( common , replaceStackTrace ,
35
+ normalizeNoNumbers , snapshot . replaceNodeVersion ) ;
36
+ const forceColorsTransform = snapshot . transform ( common , normalize ,
37
+ replaceForceColorsStackTrace , snapshot . replaceNodeVersion ) ;
34
38
35
39
const tests = [
36
40
{ name : 'errors/async_error_eval_cjs.js' } ,
@@ -50,7 +54,11 @@ describe('errors output', { concurrency: true }, () => {
50
54
{ name : 'errors/throw_in_line_with_tabs.js' , transform : errTransform } ,
51
55
{ name : 'errors/throw_non_error.js' , transform : errTransform } ,
52
56
{ name : 'errors/promise_always_throw_unhandled.js' , transform : promiseTransform } ,
53
- ! skipForceColors ? { name : 'errors/force_colors.js' , env : { FORCE_COLOR : 1 } } : null ,
57
+ ! skipForceColors ? {
58
+ name : 'errors/force_colors.js' ,
59
+ transform : forceColorsTransform ,
60
+ env : { FORCE_COLOR : 1 }
61
+ } : null ,
54
62
] . filter ( Boolean ) ;
55
63
for ( const { name, transform, env } of tests ) {
56
64
it ( name , async ( ) => {
0 commit comments