summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorRuben Bridgewater <ruben@bridgewater.de>2017-12-28 23:40:30 +0100
committerRuben Bridgewater <ruben@bridgewater.de>2018-01-16 15:34:03 +0100
commitb994b8eff6018433a56bb10dbc473cefa0dd9370 (patch)
tree018ee50d8c636219348747431053d7cd2a1405ca /test
parent9d3958102ec28f2bb468b2c532b7b34cabd61f1b (diff)
downloadandroid-node-v8-b994b8eff6018433a56bb10dbc473cefa0dd9370.tar.gz
android-node-v8-b994b8eff6018433a56bb10dbc473cefa0dd9370.tar.bz2
android-node-v8-b994b8eff6018433a56bb10dbc473cefa0dd9370.zip
util: change util.inspect depth default
The current default is not ideal in most use cases. Therefore it is changed to showing unlimited depth in case util.inspect is called directly. The default is kept as before for console.log and similar. Using console.dir will now show a depth of up to five and console.assert / console.trace will show a unlimited depth. PR-URL: https://github.com/nodejs/node/pull/17907 Refs: https://github.com/nodejs/node/issues/12693 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Michaƫl Zasso <targos@protonmail.com>
Diffstat (limited to 'test')
-rw-r--r--test/parallel/test-stream-buffer-list.js8
-rw-r--r--test/parallel/test-util-inspect-proxy.js16
-rw-r--r--test/parallel/test-util-inspect.js26
3 files changed, 31 insertions, 19 deletions
diff --git a/test/parallel/test-stream-buffer-list.js b/test/parallel/test-stream-buffer-list.js
index ddbff452de..87c9d2a2bb 100644
--- a/test/parallel/test-stream-buffer-list.js
+++ b/test/parallel/test-stream-buffer-list.js
@@ -3,6 +3,7 @@
require('../common');
const assert = require('assert');
const BufferList = require('internal/streams/BufferList');
+const util = require('util');
// Test empty buffer list.
const emptyList = new BufferList();
@@ -25,3 +26,10 @@ assert.strictEqual(list.join(','), 'foo');
const shifted = list.shift();
assert.strictEqual(shifted, 'foo');
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 63527986b1..8c76285499 100644
--- a/test/parallel/test-util-inspect-proxy.js
+++ b/test/parallel/test-util-inspect-proxy.js
@@ -48,13 +48,17 @@ 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 [Array], {} ],' +
+const expected5 = 'Proxy [ Proxy [ Proxy [ Proxy [ {}, {} ], {} ],' +
' Proxy [ {}, {} ] ],\n 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] ] ] ]';
+ ', 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 [ {}, {} ], {} ] ] ] ]';
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 335ba09bd7..35e85f6fdd 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: [Object] } } }');
+ '{ a: { b: { c: { d: 2 } } } }');
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(
@@ -1012,15 +1012,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.
@@ -1117,22 +1117,22 @@ 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)
);
// Set multiple options through object assignment
- util.inspect.defaultOptions = { maxArrayLength: null, depth: null };
+ util.inspect.defaultOptions = { maxArrayLength: null, depth: 2 };
assert(!/1 more item/.test(util.inspect(arr)));
- assert(!/Object/.test(util.inspect(obj)));
+ 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)