diff options
author | Ruben Bridgewater <ruben@bridgewater.de> | 2019-04-02 07:56:14 +0200 |
---|---|---|
committer | Ruben Bridgewater <ruben@bridgewater.de> | 2019-04-15 17:30:50 +0200 |
commit | 1940114ac323695c758f21a00394b958a68d8428 (patch) | |
tree | ac64cc180479672da3eb6dfee02642fde784cbd0 /test/parallel/test-util-inspect.js | |
parent | 693401d0ddd752e5fa47b882e56e252c42c94c0e (diff) | |
download | android-node-v8-1940114ac323695c758f21a00394b958a68d8428.tar.gz android-node-v8-1940114ac323695c758f21a00394b958a68d8428.tar.bz2 android-node-v8-1940114ac323695c758f21a00394b958a68d8428.zip |
util: highlight stack frames
Using `util.inspect` on errors is going to highlight userland and
node_module stack frames from now on. This is done by marking Node.js
core frames grey and frames that contain `node_modules` in their path
yellow.
That way it's easy to grasp what frames belong to what code.
PR-URL: https://github.com/nodejs/node/pull/27052
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'test/parallel/test-util-inspect.js')
-rw-r--r-- | test/parallel/test-util-inspect.js | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/test/parallel/test-util-inspect.js b/test/parallel/test-util-inspect.js index 140fb22f0d..c1b6e3f98d 100644 --- a/test/parallel/test-util-inspect.js +++ b/test/parallel/test-util-inspect.js @@ -2311,3 +2311,43 @@ assert.strictEqual( assert.strictEqual(out, expected); } + +{ + // Use a fake stack to verify the expected colored outcome. + const stack = [ + 'TypedError: Wonderful message!', + ' at A.<anonymous> (/test/node_modules/foo/node_modules/bar/baz.js:2:7)', + ' at Module._compile (internal/modules/cjs/loader.js:827:30)', + ' at Fancy (vm.js:697:32)', + // This file is not an actual Node.js core file. + ' at tryModuleLoad (internal/modules/cjs/foo.js:629:12)', + ' at Function.Module._load (internal/modules/cjs/loader.js:621:3)', + // This file is not an actual Node.js core file. + ' at Module.require [as weird/name] (internal/aaaaaa/loader.js:735:19)', + ' at require (internal/modules/cjs/helpers.js:14:16)', + ' at /test/test-util-inspect.js:2239:9', + ' at getActual (assert.js:592:5)' + ]; + const isNodeCoreFile = [ + false, false, true, true, false, true, false, true, false, true + ]; + const err = new TypeError('Wonderful message!'); + err.stack = stack.join('\n'); + util.inspect(err, { colors: true }).split('\n').forEach((line, i) => { + let actual = stack[i].replace(/node_modules\/([a-z]+)/g, (a, m) => { + return `node_modules/\u001b[4m${m}\u001b[24m`; + }); + if (isNodeCoreFile[i]) { + actual = `\u001b[90m${actual}\u001b[39m`; + } + assert.strictEqual(actual, line); + }); +} + +{ + // Cross platform checks. + const err = new Error('foo'); + util.inspect(err, { colors: true }).split('\n').forEach((line, i) => { + assert(i < 2 || line.startsWith('\u001b[90m')); + }); +} |