Skip to content

Commit 70633f9

Browse files
Trottaddaleax
authored andcommitted
test: refactor test-util-inspect
* Handle a rejected Promise as that is expected to cause the process to exit in a future version of Node.js. (Currently, it emits a warning.) * Remove unneeded escaping in regexps * Replace template strings with strings where there is no variable substitution. * A few minor readability changes (whitespace). PR-URL: #9804 Reviewed-By: Prince John Wesley <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent 4c2ad8c commit 70633f9

File tree

1 file changed

+22
-17
lines changed

1 file changed

+22
-17
lines changed

test/parallel/test-util-inspect.js

+22-17
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,12 @@ for (const showHidden of [true, false]) {
143143
assert.strictEqual(
144144
util.inspect(array, true),
145145
`${constructor.name} [\n` +
146-
` 65,\n` +
147-
` 97,\n` +
146+
' 65,\n' +
147+
' 97,\n' +
148148
` [BYTES_PER_ELEMENT]: ${constructor.BYTES_PER_ELEMENT},\n` +
149149
` [length]: ${length},\n` +
150150
` [byteLength]: ${byteLength},\n` +
151-
` [byteOffset]: 0,\n` +
151+
' [byteOffset]: 0,\n' +
152152
` [buffer]: ArrayBuffer { byteLength: ${byteLength} } ]`);
153153
assert.strictEqual(
154154
util.inspect(array, false),
@@ -168,23 +168,21 @@ for (const showHidden of [true, false]) {
168168
Uint8ClampedArray ].forEach((constructor) => {
169169
const length = 2;
170170
const byteLength = length * constructor.BYTES_PER_ELEMENT;
171-
const array = vm.runInNewContext('new constructor(new ArrayBuffer(' +
172-
'byteLength), 0, length)',
173-
{ constructor: constructor,
174-
byteLength: byteLength,
175-
length: length
176-
});
171+
const array = vm.runInNewContext(
172+
'new constructor(new ArrayBuffer(byteLength), 0, length)',
173+
{ constructor, byteLength, length }
174+
);
177175
array[0] = 65;
178176
array[1] = 97;
179177
assert.strictEqual(
180178
util.inspect(array, true),
181179
`${constructor.name} [\n` +
182-
` 65,\n` +
183-
` 97,\n` +
180+
' 65,\n' +
181+
' 97,\n' +
184182
` [BYTES_PER_ELEMENT]: ${constructor.BYTES_PER_ELEMENT},\n` +
185183
` [length]: ${length},\n` +
186184
` [byteLength]: ${byteLength},\n` +
187-
` [byteOffset]: 0,\n` +
185+
' [byteOffset]: 0,\n' +
188186
` [buffer]: ArrayBuffer { byteLength: ${byteLength} } ]`);
189187
assert.strictEqual(
190188
util.inspect(array, false),
@@ -208,8 +206,8 @@ for (const showHidden of [true, false]) {
208206
// Objects without prototype
209207
{
210208
const out = util.inspect(Object.create(null,
211-
{ name: {value: 'Tim', enumerable: true},
212-
hidden: {value: 'secret'}}), true);
209+
{ name: {value: 'Tim', enumerable: true},
210+
hidden: {value: 'secret'}}), true);
213211
if (out !== "{ [hidden]: 'secret', name: 'Tim' }" &&
214212
out !== "{ name: 'Tim', [hidden]: 'secret' }") {
215213
common.fail(`unexpected value for out ${out}`);
@@ -696,7 +694,14 @@ assert.strictEqual(
696694

697695
// test Promise
698696
assert.strictEqual(util.inspect(Promise.resolve(3)), 'Promise { 3 }');
699-
assert.strictEqual(util.inspect(Promise.reject(3)), 'Promise { <rejected> 3 }');
697+
698+
{
699+
const rejected = Promise.reject(3);
700+
assert.strictEqual(util.inspect(rejected), 'Promise { <rejected> 3 }');
701+
// squelch UnhandledPromiseRejection
702+
rejected.catch(() => {});
703+
}
704+
700705
assert.strictEqual(
701706
util.inspect(new Promise(function() {})),
702707
'Promise { <pending> }'
@@ -831,7 +836,7 @@ checkAlignment(new Map(big_array.map(function(y) { return [y, null]; })));
831836

832837
{
833838
const x = Array(101);
834-
assert(/^\[ ... 101 more items \]$/.test(
839+
assert(/^\[ ... 101 more items ]$/.test(
835840
util.inspect(x, {maxArrayLength: 0})));
836841
}
837842

@@ -847,7 +852,7 @@ checkAlignment(new Map(big_array.map(function(y) { return [y, null]; })));
847852

848853
{
849854
const x = new Uint8Array(101);
850-
assert(/\[ ... 101 more items \]$/.test(
855+
assert(/\[ ... 101 more items ]$/.test(
851856
util.inspect(x, {maxArrayLength: 0})));
852857
}
853858

0 commit comments

Comments
 (0)