@@ -2920,6 +2920,175 @@ assert.strictEqual(
29202920 process . cwd = originalCWD ;
29212921}
29222922
2923+ {
2924+ // Use a fake stack to verify the expected colored outcome.
2925+ const err = new Error ( 'Hide duplicate frames in long stack' ) ;
2926+ err . stack = [
2927+ 'Error: Hide duplicate frames in long stack' ,
2928+ ' at A.<anonymous> (/foo/node_modules/bar/baz.js:2:7)' ,
2929+ ' at A.<anonymous> (/foo/node_modules/bar/baz.js:2:7)' ,
2930+ ' at Module._compile (node:internal/modules/cjs/loader:827:30)' ,
2931+ ' at Fancy (node:vm:697:32)' ,
2932+ ' at tryModuleLoad (node:internal/modules/cjs/foo:629:12)' ,
2933+ ' at Function.Module._load (node:internal/modules/cjs/loader:621:3)' ,
2934+ ' at Fancy (node:vm:697:32)' ,
2935+ ' at tryModuleLoad (node:internal/modules/cjs/foo:629:12)' ,
2936+ ' at Function.Module._load (node:internal/modules/cjs/loader:621:3)' ,
2937+ ' at Function.Module._load (node:internal/modules/cjs/loader:621:3)' ,
2938+ ' at Function.Module._load (node:internal/modules/cjs/loader:621:3)' ,
2939+ ' at Function.Module._load (node:internal/modules/cjs/loader:621:3)' ,
2940+ ' at Function.Module._load (node:internal/modules/cjs/loader:621:3)' ,
2941+ ' at Function.Module._load (node:internal/modules/cjs/loader:621:3)' ,
2942+ ' at Function.Module._load (node:internal/modules/cjs/loader:621:3)' ,
2943+ ' at Module.require [as weird/name] (node:internal/aaaaa/loader:735:19)' ,
2944+ ' at require (node:internal/modules/helpers:14:16)' ,
2945+ ' at Array.forEach (<anonymous>)' ,
2946+ ' at require (node:internal/modules/helpers:14:16)' ,
2947+ ' at Array.forEach (<anonymous>)' ,
2948+ ` at foobar/test/parallel/test-util-inspect.js:2760:12` ,
2949+ ` at Object.<anonymous> (foobar/node_modules/m/folder/file.js:2753:10)` ,
2950+ ' at Module.require [as weird/name] (node:internal/aaaaa/loader:735:19)' ,
2951+ ' at require (node:internal/modules/helpers:14:16)' ,
2952+ ' at Array.forEach (<anonymous>)' ,
2953+ ` at foobar/test/parallel/test-util-inspect.js:2760:12` ,
2954+ ` at Object.<anonymous> (foobar/node_modules/m/folder/file.js:2753:10)` ,
2955+ ' at Module.require [as weird/name] (node:internal/aaaaa/loader:735:19)' ,
2956+ ' at require (node:internal/modules/helpers:14:16)' ,
2957+ ' at Array.forEach (<anonymous>)' ,
2958+ ` at foobar/test/parallel/test-util-inspect.js:2760:12` ,
2959+ ` at Object.<anonymous> (foobar/node_modules/m/folder/file.js:2753:10)` ,
2960+ ' at Module.require [as weird/name] (node:internal/aaaaa/loader:735:19)' ,
2961+ ' at require (node:internal/modules/helpers:14:16)' ,
2962+ ' at Array.forEach (<anonymous>)' ,
2963+ ` at foobar/test/parallel/test-util-inspect.js:2760:12` ,
2964+ ` at Object.<anonymous> (foobar/node_modules/m/folder/file.js:2753:10)` ,
2965+ ' at /test/test-util-inspect.js:2239:9' ,
2966+ ' at getActual (node:assert:592:5)' ,
2967+ ' at /test/test-util-inspect.js:2239:9' ,
2968+ ' at getActual (node:assert:592:5)' ,
2969+ ' at /test/test-util-inspect.js:2239:9' ,
2970+ ' at getActual (node:assert:592:5)' ,
2971+ ] . join ( '\n' ) ;
2972+
2973+ assert . strictEqual (
2974+ util . inspect ( err , { colors : true } ) ,
2975+ 'Error: Hide duplicate frames in long stack\n' +
2976+ ' at A.<anonymous> (/foo/node_modules/\x1B[4mbar\x1B[24m/baz.js:2:7)\n' +
2977+ ' at A.<anonymous> (/foo/node_modules/\x1B[4mbar\x1B[24m/baz.js:2:7)\n' +
2978+ '\x1B[90m at Module._compile (node:internal/modules/cjs/loader:827:30)\x1B[39m\n' +
2979+ '\x1B[90m at Fancy (node:vm:697:32)\x1B[39m\n' +
2980+ ' at tryModuleLoad (node:internal/modules/cjs/foo:629:12)\n' +
2981+ '\x1B[90m at Function.Module._load (node:internal/modules/cjs/loader:621:3)\x1B[39m\n' +
2982+ '\x1B[90m ... collapsed 3 duplicate lines matching above lines ...\x1B[39m\n' +
2983+
2984+ '\x1B[90m at Function.Module._load (node:internal/modules/cjs/loader:621:3)\x1B[39m\n' +
2985+ '\x1B[90m ... collapsed 5 duplicate lines matching above 1 lines 5 times...\x1B[39m\n' +
2986+
2987+ ' at Module.require [as weird/name] (node:internal/aaaaa/loader:735:19)\n' +
2988+ '\x1B[90m at require (node:internal/modules/helpers:14:16)\x1B[39m\n' +
2989+ ' at Array.forEach (<anonymous>)\n' +
2990+ '\x1B[90m at require (node:internal/modules/helpers:14:16)\x1B[39m\n' +
2991+ ' at Array.forEach (<anonymous>)\n' +
2992+ ' at foobar/test/parallel/test-util-inspect.js:2760:12\n' +
2993+ ' at Object.<anonymous> (foobar/node_modules/\x1B[4mm\x1B[24m/folder/file.js:2753:10)\n' +
2994+ ' at Module.require [as weird/name] (node:internal/aaaaa/loader:735:19)\n' +
2995+ '\x1B[90m ... collapsed 10 duplicate lines matching above 5 lines 2 times...\x1B[39m\n' +
2996+
2997+ '\x1B[90m at require (node:internal/modules/helpers:14:16)\x1B[39m\n' +
2998+ ' at Array.forEach (<anonymous>)\n' +
2999+ ' at foobar/test/parallel/test-util-inspect.js:2760:12\n' +
3000+ ' at Object.<anonymous> (foobar/node_modules/\x1B[4mm\x1B[24m/folder/file.js:2753:10)\n' +
3001+ ' at /test/test-util-inspect.js:2239:9\n' +
3002+ '\x1B[90m at getActual (node:assert:592:5)\x1B[39m\n' +
3003+ '\x1B[90m ... collapsed 4 duplicate lines matching above 2 lines 2 times...\x1B[39m' ,
3004+ ) ;
3005+
3006+ // Use a fake stack to verify the expected colored outcome.
3007+ const err2 = new Error ( 'Hide duplicate frames in long stack' ) ;
3008+ err2 . stack = [
3009+ 'Error: Hide duplicate frames in long stack' ,
3010+ ' at A.<anonymous> (/foo/node_modules/bar/baz.js:2:7)' ,
3011+ ' at A.<anonymous> (/foo/node_modules/bar/baz.js:2:7)' ,
3012+ ' at Module._compile (node:internal/modules/cjs/loader:827:30)' ,
3013+
3014+ // 3
3015+ ' at Fancy (node:vm:697:32)' ,
3016+ ' at tryModuleLoad (node:internal/modules/cjs/foo:629:12)' ,
3017+ ' at Function.Module._load (node:internal/modules/cjs/loader:621:3)' ,
3018+ ' at Fancy (node:vm:697:32)' ,
3019+ ' at tryModuleLoad (node:internal/modules/cjs/foo:629:12)' ,
3020+ ' at Function.Module._load (node:internal/modules/cjs/loader:621:3)' ,
3021+
3022+ // 6 * 1
3023+ ' at Function.Module._load (node:internal/modules/cjs/loader:621:3)' ,
3024+ ' at Function.Module._load (node:internal/modules/cjs/loader:621:3)' ,
3025+ ' at Function.Module._load (node:internal/modules/cjs/loader:621:3)' ,
3026+ ' at Function.Module._load (node:internal/modules/cjs/loader:621:3)' ,
3027+ ' at Function.Module._load (node:internal/modules/cjs/loader:621:3)' ,
3028+ ' at Function.Module._load (node:internal/modules/cjs/loader:621:3)' ,
3029+ ' at Function.Module._load (node:internal/modules/cjs/loader:621:3)' ,
3030+
3031+ // 10
3032+ ' at require (node:internal/modules/helpers:14:16)' ,
3033+ ' at Array.forEach (<anonymous>)' ,
3034+ ` at foobar/test/parallel/test-util-inspect.js:2760:12` ,
3035+ ` at Object.<anonymous> (foobar/node_modules/m/folder/file.js:2753:10)` ,
3036+ ' at Module.require [as weird/name] (node:internal/aaaaa/loader:735:19)' ,
3037+ ' at Module.require [as weird/name] (node:internal/aaaaa/loader:735:19)' ,
3038+ ' at require (node:internal/modules/helpers:14:16)' ,
3039+ ' at Array.forEach (<anonymous>)' ,
3040+ ` at foobar/test/parallel/test-util-inspect.js:2760:12` ,
3041+ ` at Object.<anonymous> (foobar/node_modules/m/folder/file.js:2753:10)` ,
3042+
3043+ ' at require (node:internal/modules/helpers:14:16)' ,
3044+ ' at Array.forEach (<anonymous>)' ,
3045+ ` at foobar/test/parallel/test-util-inspect.js:2760:12` ,
3046+ ` at Object.<anonymous> (foobar/node_modules/m/folder/file.js:2753:10)` ,
3047+ ' at Module.require [as weird/name] (node:internal/aaaaa/loader:735:19)' ,
3048+ ' at Module.require [as weird/name] (node:internal/aaaaa/loader:735:19)' ,
3049+ ' at require (node:internal/modules/helpers:14:16)' ,
3050+ ' at Array.forEach (<anonymous>)' ,
3051+ ` at foobar/test/parallel/test-util-inspect.js:2760:12` ,
3052+ ` at Object.<anonymous> (foobar/node_modules/m/folder/file.js:2753:10)` ,
3053+
3054+ // 2 * 2
3055+ ' at /test/test-util-inspect.js:2239:9' ,
3056+ ' at getActual (node:assert:592:5)' ,
3057+ ' at /test/test-util-inspect.js:2239:9' ,
3058+ ' at getActual (node:assert:592:5)' ,
3059+ ' at /test/test-util-inspect.js:2239:9' ,
3060+ ' at getActual (node:assert:592:5)' ,
3061+ ] . join ( '\n' ) ;
3062+
3063+ assert . strictEqual (
3064+ util . inspect ( err2 , { colors : true } ) ,
3065+ 'Error: Hide duplicate frames in long stack\n' +
3066+ ' at A.<anonymous> (/foo/node_modules/\x1B[4mbar\x1B[24m/baz.js:2:7)\n' +
3067+ ' at A.<anonymous> (/foo/node_modules/\x1B[4mbar\x1B[24m/baz.js:2:7)\n' +
3068+ '\x1B[90m at Module._compile (node:internal/modules/cjs/loader:827:30)\x1B[39m\n' +
3069+ '\x1B[90m at Fancy (node:vm:697:32)\x1B[39m\n' +
3070+ ' at tryModuleLoad (node:internal/modules/cjs/foo:629:12)\n' +
3071+ '\x1B[90m at Function.Module._load (node:internal/modules/cjs/loader:621:3)\x1B[39m\n' +
3072+ '\x1B[90m ... collapsed 3 duplicate lines matching above lines ...\x1B[39m\n' +
3073+ '\x1B[90m at Function.Module._load (node:internal/modules/cjs/loader:621:3)\x1B[39m\n' +
3074+ '\x1B[90m ... collapsed 6 duplicate lines matching above 1 lines 6 times...\x1B[39m\n' +
3075+ '\x1B[90m at require (node:internal/modules/helpers:14:16)\x1B[39m\n' +
3076+ ' at Array.forEach (<anonymous>)\n' +
3077+ ' at foobar/test/parallel/test-util-inspect.js:2760:12\n' +
3078+ ' at Object.<anonymous> (foobar/node_modules/\x1B[4mm\x1B[24m/folder/file.js:2753:10)\n' +
3079+ ' at Module.require [as weird/name] (node:internal/aaaaa/loader:735:19)\n' +
3080+ ' at Module.require [as weird/name] (node:internal/aaaaa/loader:735:19)\n' +
3081+ '\x1B[90m at require (node:internal/modules/helpers:14:16)\x1B[39m\n' +
3082+ ' at Array.forEach (<anonymous>)\n' +
3083+ ' at foobar/test/parallel/test-util-inspect.js:2760:12\n' +
3084+ ' at Object.<anonymous> (foobar/node_modules/\x1B[4mm\x1B[24m/folder/file.js:2753:10)\n' +
3085+ '\x1B[90m ... collapsed 10 duplicate lines matching above lines ...\x1B[39m\n' +
3086+ ' at /test/test-util-inspect.js:2239:9\n' +
3087+ '\x1B[90m at getActual (node:assert:592:5)\x1B[39m\n' +
3088+ '\x1B[90m ... collapsed 4 duplicate lines matching above 2 lines 2 times...\x1B[39m' ,
3089+ ) ;
3090+ }
3091+
29233092{
29243093 // Cross platform checks.
29253094 const err = new Error ( 'foo' ) ;
0 commit comments