Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/internal/assert/assertion_error.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ function addEllipsis(string) {
lines.length = 10;
return `${ArrayPrototypeJoin(lines, '\n')}\n...`;
} else if (string.length > kMaxLongStringLength) {
return `${StringPrototypeSlice(string, kMaxLongStringLength)}...`;
return `${StringPrototypeSlice(string, 0, kMaxLongStringLength)}...`;
}
return string;
}
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-assert-class.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ const truncatedBs = 'B\\n'.repeat(10) + '...';
const longStringOfAs = 'A'.repeat(10_000);
const longStringOfBs = 'B'.repeat(10_000);

const longLinesOfAsWithEllipsis = longStringOfAs.substring(0, 9_488) + '...';
const longLinesOFBsWithEllipsis = longStringOfBs.substring(0, 9_488) + '...';
const longLinesOfAsWithEllipsis = longStringOfAs.substring(0, 512) + '...';
const longLinesOFBsWithEllipsis = longStringOfBs.substring(0, 512) + '...';
test('Assert class non strict with full diff', () => {
const assertInstance = new Assert({ diff: 'full', strict: false });

Expand Down
18 changes: 17 additions & 1 deletion test/parallel/test-assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,23 @@ test('Long values should be truncated for display', () => {
`${strictEqualMessageStart}+ actual - expected\n\n` +
`+ '${'A'.repeat(1000)}'\n- ''\n`);
assert.strictEqual(err.actual.length, 1000);
assert.ok(inspect(err).includes(`actual: '${'A'.repeat(488)}...'`));
assert.ok(inspect(err).includes(`actual: '${'A'.repeat(512)}...'`));
return true;
});
});

test('Truncated long values should keep the beginning of the string', () => {
// Use a heterogeneous string so the retained portion is distinguishable
// from the discarded portion (a homogeneous string cannot tell the head
// from the tail). The first `kMaxLongStringLength` (512) characters should
// be kept, followed by an ellipsis.
const actual = 'a'.repeat(300) + 'b'.repeat(300);
assert.throws(() => {
assert.strictEqual(actual, '');
}, (err) => {
const kept = `${'a'.repeat(300)}${'b'.repeat(212)}`;
assert.ok(inspect(err).includes(`actual: '${kept}...'`),
`expected the beginning of the string to be kept, got ${inspect(err)}`);
return true;
});
});
Expand Down
Loading