diff options
author | Anna Henningsen <anna@addaleax.net> | 2018-04-13 21:40:28 +0200 |
---|---|---|
committer | Ruben Bridgewater <ruben@bridgewater.de> | 2018-05-11 17:46:56 +0200 |
commit | 849aaaeeb045965f3f8085c7cb65c3c830bd724c (patch) | |
tree | 0beefed2ec9fe936e2de381627f66b4dd3860896 /test | |
parent | 85373aeb4c79dd16bf22549559cf09df17d78e5a (diff) | |
download | android-node-v8-849aaaeeb045965f3f8085c7cb65c3c830bd724c.tar.gz android-node-v8-849aaaeeb045965f3f8085c7cb65c3c830bd724c.tar.bz2 android-node-v8-849aaaeeb045965f3f8085c7cb65c3c830bd724c.zip |
Revert "util: change util.inspect depth default"
This reverts commit b994b8eff6018433a56bb10dbc473cefa0dd9370.
This caused regressions in ecosystem code. While the change originally
was semver-major and could be postponed until after Node.js 10,
I think reverting it is a good choice at this point.
Also, I personally do not think defaulting to a shallow inspect
is a bad thing at all – quite the opposite: It makes `util.inspect()`
give an overview of an object, rather than providing a full
display of its contents. Changing the `depth` default to infinity
fundamentally changed the role that `util.inspect()` plays,
and makes output much more verbose and thus at times unusable
for `console.log()`-style debugging.
PR-URL: https://github.com/nodejs/node/pull/20017
Fixes: https://github.com/nodejs/node/issues/19405
Refs: https://github.com/nodejs/node/pull/17907
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/parallel/test-stream-buffer-list.js | 8 | ||||
-rw-r--r-- | test/parallel/test-util-inspect-proxy.js | 16 | ||||
-rw-r--r-- | test/parallel/test-util-inspect.js | 22 |
3 files changed, 17 insertions, 29 deletions
diff --git a/test/parallel/test-stream-buffer-list.js b/test/parallel/test-stream-buffer-list.js index ef9b1fef6d..d7728d1171 100644 --- a/test/parallel/test-stream-buffer-list.js +++ b/test/parallel/test-stream-buffer-list.js @@ -3,7 +3,6 @@ require('../common'); const assert = require('assert'); const BufferList = require('internal/streams/buffer_list'); -const util = require('util'); // Test empty buffer list. const emptyList = new BufferList(); @@ -31,10 +30,3 @@ assert.strictEqual(list.join(','), 'foo'); const shifted = list.shift(); assert.strictEqual(shifted, buf); assert.deepStrictEqual(list, new BufferList()); - -const tmp = util.inspect.defaultOptions.colors; -util.inspect.defaultOptions = { colors: true }; -assert.strictEqual( - util.inspect(list), - 'BufferList { length: \u001b[33m0\u001b[39m }'); -util.inspect.defaultOptions = { colors: tmp }; diff --git a/test/parallel/test-util-inspect-proxy.js b/test/parallel/test-util-inspect-proxy.js index bc53c1fe68..d7fb28ddc7 100644 --- a/test/parallel/test-util-inspect-proxy.js +++ b/test/parallel/test-util-inspect-proxy.js @@ -48,17 +48,13 @@ const expected1 = 'Proxy [ {}, {} ]'; const expected2 = 'Proxy [ Proxy [ {}, {} ], {} ]'; const expected3 = 'Proxy [ Proxy [ Proxy [ {}, {} ], {} ], Proxy [ {}, {} ] ]'; const expected4 = 'Proxy [ Proxy [ {}, {} ], Proxy [ Proxy [ {}, {} ], {} ] ]'; -const expected5 = 'Proxy [ Proxy [ Proxy [ Proxy [ {}, {} ], {} ],' + +const expected5 = 'Proxy [ Proxy [ Proxy [ Proxy [Array], {} ],' + ' Proxy [ {}, {} ] ],\n Proxy [ Proxy [ {}, {} ]' + - ', Proxy [ Proxy [ {}, {} ], {} ] ] ]'; -const expected6 = 'Proxy [ Proxy [ Proxy [ Proxy [ Proxy [ {}, {} ], {} ], ' + - 'Proxy [ {}, {} ] ],\n' + - ' Proxy [ Proxy [ {}, {} ], ' + - 'Proxy [ Proxy [ {}, {} ], {} ] ] ],\n' + - ' Proxy [ Proxy [ Proxy [ Proxy [ {}, {} ], {} ], ' + - 'Proxy [ {}, {} ] ],\n' + - ' Proxy [ Proxy [ {}, {} ], ' + - 'Proxy [ Proxy [ {}, {} ], {} ] ] ] ]'; + ', Proxy [ Proxy [Array], {} ] ] ]'; +const expected6 = 'Proxy [ Proxy [ Proxy [ Proxy [Array], Proxy [Array]' + + ' ],\n Proxy [ Proxy [Array], Proxy [Array] ] ],\n' + + ' Proxy [ Proxy [ Proxy [Array], Proxy [Array] ],\n' + + ' Proxy [ Proxy [Array], Proxy [Array] ] ] ]'; assert.strictEqual( util.inspect(proxy1, { showProxy: true, depth: null }), expected1); diff --git a/test/parallel/test-util-inspect.js b/test/parallel/test-util-inspect.js index b5ef8dca08..5cd051299d 100644 --- a/test/parallel/test-util-inspect.js +++ b/test/parallel/test-util-inspect.js @@ -68,7 +68,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: { d: 2 } } } }'); + '{ a: { b: { c: [Object] } } }'); assert.strictEqual( util.inspect({ 'a': { 'b': { 'c': { 'd': 2 } } } }, false, null), '{ a: { b: { c: { d: 2 } } } }'); @@ -106,7 +106,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( @@ -1011,15 +1011,15 @@ if (typeof Symbol !== 'undefined') { // Empty and circular before depth. { const arr = [[[[]]]]; - assert.strictEqual(util.inspect(arr, { depth: 2 }), '[ [ [ [] ] ] ]'); + assert.strictEqual(util.inspect(arr), '[ [ [ [] ] ] ]'); arr[0][0][0][0] = []; - assert.strictEqual(util.inspect(arr, { depth: 2 }), '[ [ [ [Array] ] ] ]'); + assert.strictEqual(util.inspect(arr), '[ [ [ [Array] ] ] ]'); arr[0][0][0] = {}; - assert.strictEqual(util.inspect(arr, { depth: 2 }), '[ [ [ {} ] ] ]'); + assert.strictEqual(util.inspect(arr), '[ [ [ {} ] ] ]'); arr[0][0][0] = { a: 2 }; - assert.strictEqual(util.inspect(arr, { depth: 2 }), '[ [ [ [Object] ] ] ]'); + assert.strictEqual(util.inspect(arr), '[ [ [ [Object] ] ] ]'); arr[0][0][0] = arr; - assert.strictEqual(util.inspect(arr, { depth: 2 }), '[ [ [ [Circular] ] ] ]'); + assert.strictEqual(util.inspect(arr), '[ [ [ [Circular] ] ] ]'); } // Corner cases. @@ -1116,10 +1116,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 = 2; - assert(/Object/.test(util.inspect(obj))); - util.inspect.defaultOptions.depth = oldOptions.depth; + util.inspect.defaultOptions.depth = null; 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) @@ -1131,7 +1131,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) |