Skip to content

Commit 93c08b0

Browse files
BridgeARjasnell
authored andcommitted
test: improve util inspect tests
Remove unnecessary code parts and outdated code PR-URL: #14881 Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]>
1 parent 5b47f84 commit 93c08b0

File tree

1 file changed

+19
-76
lines changed

1 file changed

+19
-76
lines changed

test/parallel/test-util-inspect.js

Lines changed: 19 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -235,43 +235,21 @@ for (const showHidden of [true, false]) {
235235
);
236236
});
237237

238-
// Due to the hash seed randomization it's not deterministic the order that
239-
// the following ways this hash is displayed.
240-
// See http://codereview.chromium.org/9124004/
241-
242-
{
243-
const out =
244-
util.inspect(
245-
Object.create(
246-
{},
247-
{ visible: { value: 1, enumerable: true }, hidden: { value: 2 } }
248-
),
249-
true
250-
);
251-
if (out !== '{ [hidden]: 2, visible: 1 }' &&
252-
out !== '{ visible: 1, [hidden]: 2 }') {
253-
assert.fail(`unexpected value for out ${out}`);
254-
}
255-
}
256-
238+
assert.strictEqual(
239+
util.inspect(Object.create({}, {
240+
visible: { value: 1, enumerable: true },
241+
hidden: { value: 2 }
242+
}), { showHidden: true }),
243+
'{ visible: 1, [hidden]: 2 }'
244+
);
257245
// Objects without prototype
258-
{
259-
const out =
260-
util.inspect(Object.create(null,
261-
{
262-
name: {
263-
value: 'Tim',
264-
enumerable: true
265-
},
266-
hidden: {
267-
value: 'secret'
268-
}
269-
}), true);
270-
if (out !== "{ [hidden]: 'secret', name: 'Tim' }" &&
271-
out !== "{ name: 'Tim', [hidden]: 'secret' }") {
272-
assert.fail(`unexpected value for out ${out}`);
273-
}
274-
}
246+
assert.strictEqual(
247+
util.inspect(Object.create(null, {
248+
name: { value: 'Tim', enumerable: true },
249+
hidden: { value: 'secret' }
250+
}), { showHidden: true }),
251+
"{ name: 'Tim', [hidden]: 'secret' }"
252+
);
275253

276254
assert.strictEqual(
277255
util.inspect(Object.create(null,
@@ -280,7 +258,6 @@ assert.strictEqual(
280258
'{ name: \'Tim\' }'
281259
);
282260

283-
284261
// Dynamic properties
285262
{
286263
assert.strictEqual(util.inspect({ get readonly() {} }),
@@ -1061,19 +1038,11 @@ if (typeof Symbol !== 'undefined') {
10611038
{
10621039
const x = new Array(101).fill();
10631040
assert(util.inspect(x).endsWith('1 more item ]'));
1064-
}
1065-
1066-
{
1067-
const x = new Array(101).fill();
10681041
assert(!util.inspect(x, { maxArrayLength: 101 }).endsWith('1 more item ]'));
10691042
assert.strictEqual(
10701043
util.inspect(x, { maxArrayLength: -1 }),
10711044
'[ ... 101 more items ]'
10721045
);
1073-
}
1074-
1075-
{
1076-
const x = new Array(101).fill();
10771046
assert.strictEqual(util.inspect(x, { maxArrayLength: 0 }),
10781047
'[ ... 101 more items ]');
10791048
}
@@ -1082,46 +1051,20 @@ if (typeof Symbol !== 'undefined') {
10821051
const x = Array(101);
10831052
assert.strictEqual(util.inspect(x, { maxArrayLength: 0 }),
10841053
'[ ... 101 more items ]');
1085-
}
1086-
1087-
{
1088-
const x = new Uint8Array(101);
1089-
assert(util.inspect(x).endsWith('1 more item ]'));
1090-
}
1091-
1092-
{
1093-
const x = new Uint8Array(101);
1094-
assert(!util.inspect(x, { maxArrayLength: 101 }).endsWith('1 more item ]'));
1095-
}
1096-
1097-
{
1098-
const x = new Uint8Array(101);
1099-
assert.strictEqual(util.inspect(x, { maxArrayLength: 0 }),
1100-
'Uint8Array [ ... 101 more items ]');
1101-
}
1102-
1103-
{
1104-
const x = Array(101);
11051054
assert(!util.inspect(x, { maxArrayLength: null }).endsWith('1 more item ]'));
1106-
}
1107-
1108-
{
1109-
const x = Array(101);
11101055
assert(!util.inspect(
11111056
x, { maxArrayLength: Infinity }
11121057
).endsWith('1 more item ]'));
11131058
}
11141059

11151060
{
11161061
const x = new Uint8Array(101);
1062+
assert(util.inspect(x).endsWith('1 more item ]'));
1063+
assert(!util.inspect(x, { maxArrayLength: 101 }).endsWith('1 more item ]'));
1064+
assert.strictEqual(util.inspect(x, { maxArrayLength: 0 }),
1065+
'Uint8Array [ ... 101 more items ]');
11171066
assert(!util.inspect(x, { maxArrayLength: null }).endsWith('1 more item ]'));
1118-
}
1119-
1120-
{
1121-
const x = new Uint8Array(101);
1122-
assert(!util.inspect(
1123-
x, { maxArrayLength: Infinity }
1124-
).endsWith('1 more item ]'));
1067+
assert(util.inspect(x, { maxArrayLength: Infinity }).endsWith(' 0 ]'));
11251068
}
11261069

11271070
{

0 commit comments

Comments
 (0)