diff options
author | Ruben Bridgewater <ruben@bridgewater.de> | 2017-12-28 23:40:30 +0100 |
---|---|---|
committer | Ruben Bridgewater <ruben@bridgewater.de> | 2018-10-02 22:43:09 +0200 |
commit | ac7450a09a4c167cd43c14d7c88721d22f077529 (patch) | |
tree | 296de2457293a1eab58de5fa997d0302794a87d5 /test/parallel/test-util-inspect.js | |
parent | 83d0404971471b3d4f711ba9690394e9df54eb5f (diff) | |
download | android-node-v8-ac7450a09a4c167cd43c14d7c88721d22f077529.tar.gz android-node-v8-ac7450a09a4c167cd43c14d7c88721d22f077529.tar.bz2 android-node-v8-ac7450a09a4c167cd43c14d7c88721d22f077529.zip |
util: change util.inspect depth default
The current default is not ideal in most use cases. Therefore it is
changed to inspect objects to a maximum depth of 20 in case
util.inspect is called with it's defaults. The default is kept at 2
when using console.log() and similar in the repl.
PR-URL: https://github.com/nodejs/node/pull/17907
Refs: https://github.com/nodejs/node/issues/12693
PR-URL: https://github.com/nodejs/node/pull/22846
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
Reviewed-By: Roman Reiss <me@silverwind.io>
Diffstat (limited to 'test/parallel/test-util-inspect.js')
-rw-r--r-- | test/parallel/test-util-inspect.js | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/test/parallel/test-util-inspect.js b/test/parallel/test-util-inspect.js index c0fc3219ce..713bf047dd 100644 --- a/test/parallel/test-util-inspect.js +++ b/test/parallel/test-util-inspect.js @@ -71,7 +71,7 @@ assert.strictEqual(util.inspect({ a: 1, b: 2 }), '{ a: 1, b: 2 }'); assert.strictEqual(util.inspect({ 'a': {} }), '{ a: {} }'); assert.strictEqual(util.inspect({ 'a': { 'b': 2 } }), '{ a: { b: 2 } }'); assert.strictEqual(util.inspect({ 'a': { 'b': { 'c': { 'd': 2 } } } }), - '{ a: { b: { c: [Object] } } }'); + '{ a: { b: { c: { d: 2 } } } }'); assert.strictEqual( util.inspect({ 'a': { 'b': { 'c': { 'd': 2 } } } }, false, null), '{ a: { b: { c: { d: 2 } } } }'); @@ -110,7 +110,7 @@ assert.strictEqual(util.inspect((new JSStream())._externalStream), assert.strictEqual(util.inspect({ a: regexp }, false, 0), '{ a: /regexp/ }'); } -assert(/Object/.test( +assert(!/Object/.test( util.inspect({ a: { a: { a: { a: {} } } } }, undefined, undefined, true) )); assert(!/Object/.test( @@ -1055,15 +1055,15 @@ if (typeof Symbol !== 'undefined') { // Empty and circular before depth. { const arr = [[[[]]]]; - assert.strictEqual(util.inspect(arr), '[ [ [ [] ] ] ]'); + assert.strictEqual(util.inspect(arr, { depth: 2 }), '[ [ [ [] ] ] ]'); arr[0][0][0][0] = []; - assert.strictEqual(util.inspect(arr), '[ [ [ [Array] ] ] ]'); + assert.strictEqual(util.inspect(arr, { depth: 2 }), '[ [ [ [Array] ] ] ]'); arr[0][0][0] = {}; - assert.strictEqual(util.inspect(arr), '[ [ [ {} ] ] ]'); + assert.strictEqual(util.inspect(arr, { depth: 2 }), '[ [ [ {} ] ] ]'); arr[0][0][0] = { a: 2 }; - assert.strictEqual(util.inspect(arr), '[ [ [ [Object] ] ] ]'); + assert.strictEqual(util.inspect(arr, { depth: 2 }), '[ [ [ [Object] ] ] ]'); arr[0][0][0] = arr; - assert.strictEqual(util.inspect(arr), '[ [ [ [Circular] ] ] ]'); + assert.strictEqual(util.inspect(arr, { depth: 2 }), '[ [ [ [Circular] ] ] ]'); } // Corner cases. @@ -1160,10 +1160,10 @@ if (typeof Symbol !== 'undefined') { assert(!/1 more item/.test(util.inspect(arr))); util.inspect.defaultOptions.maxArrayLength = oldOptions.maxArrayLength; assert(/1 more item/.test(util.inspect(arr))); - util.inspect.defaultOptions.depth = null; - assert(!/Object/.test(util.inspect(obj))); - util.inspect.defaultOptions.depth = oldOptions.depth; + util.inspect.defaultOptions.depth = 2; assert(/Object/.test(util.inspect(obj))); + util.inspect.defaultOptions.depth = oldOptions.depth; + assert(!/Object/.test(util.inspect(obj))); assert.strictEqual( JSON.stringify(util.inspect.defaultOptions), JSON.stringify(oldOptions) @@ -1175,7 +1175,7 @@ if (typeof Symbol !== 'undefined') { assert(/Object/.test(util.inspect(obj))); util.inspect.defaultOptions = oldOptions; assert(/1 more item/.test(util.inspect(arr))); - assert(/Object/.test(util.inspect(obj))); + assert(!/Object/.test(util.inspect(obj))); assert.strictEqual( JSON.stringify(util.inspect.defaultOptions), JSON.stringify(oldOptions) @@ -1561,11 +1561,19 @@ util.inspect(process); let head = list; // A linked list of length 100k should be inspectable in some way, even though // the real cutoff value is much lower than 100k. - for (let i = 0; i < 100000; i++) + for (let i = 0; i < 100000; i++) { head = head.next = {}; + } + + const res = Array(15) + .fill(0) + .map((_, i) => `{ next:\n${' '.repeat(i + 1)}`) + .join('') + + '{ next: { next: { next: { next: { next: { next:' + + ' [Object] } } } } } } } } } } } } } } } } } } } } }'; assert.strictEqual( util.inspect(list), - '{ next: { next: { next: [Object] } } }' + res ); const longList = util.inspect(list, { depth: Infinity }); const match = longList.match(/next/g); |