Skip to content

Commit

Permalink
test: increase inspect coverage
Browse files Browse the repository at this point in the history
1. Truncate output for Primitives with 1 character left
Refs: https://coverage.nodejs.org/coverage-0b6d3070a176d437/lib/internal/util/inspect.js.html#L1359

2. Truncate output for ArrayBuffers using plural or singular bytes
Refs: https://coverage.nodejs.org/coverage-0b6d3070a176d437/lib/internal/util/inspect.js.html#L1465

PR-URL: #36755
Reviewed-By: Zijian Liu <lxxyxzj@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
  • Loading branch information
emilsivervik authored and targos committed May 1, 2021
1 parent 21e7b02 commit db44b92
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions test/parallel/test-util-inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,17 @@ assert(!/Object/.test(
'ArrayBuffer { (detached), byteLength: 0 }');
}

// Truncate output for ArrayBuffers using plural or singular bytes
{
const ab = new ArrayBuffer(3);
assert.strictEqual(util.inspect(ab, { showHidden: true, maxArrayLength: 2 }),
'ArrayBuffer { [Uint8Contents]' +
': <00 00 ... 1 more byte>, byteLength: 3 }');
assert.strictEqual(util.inspect(ab, { showHidden: true, maxArrayLength: 1 }),
'ArrayBuffer { [Uint8Contents]' +
': <00 ... 2 more bytes>, byteLength: 3 }');
}

// Now do the same checks but from a different context.
{
const showHidden = false;
Expand Down Expand Up @@ -2915,6 +2926,12 @@ assert.strictEqual(
assert.strictEqual(inspect(undetectable), '{}');
}

// Truncate output for Primitives with 1 character left
{
assert.strictEqual(util.inspect('bl', { maxStringLength: 1 }),
"'b'... 1 more character");
}

{
const x = 'a'.repeat(1e6);
assert.strictEqual(
Expand Down

0 comments on commit db44b92

Please sign in to comment.