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