assert: print more lines in the error diff · nodejs/node@8157a50 · GitHub
Skip to content

Commit 8157a50

Browse files
committed
assert: print more lines in the error diff
So far consequitive identical lines were collapsed if there were at least three. Now they are only collapsed from five identical lines on. This also simplifies the implementation a tiny bit by abstracting some logic. PR-URL: #28058 Reviewed-By: Rich Trott <rtrott@gmail.com>
1 parent 8217441 commit 8157a50

4 files changed

Lines changed: 77 additions & 57 deletions

File tree

lib/internal/assert/assertion_error.js

Lines changed: 46 additions & 38 deletions

test/parallel/test-assert-deep.js

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ assert.throws(
5353
code: 'ERR_ASSERTION',
5454
message: `${defaultMsgStartFull} ... Lines skipped\n\n` +
5555
'+ Uint8Array [\n' +
56-
'- Buffer [Uint8Array] [\n 120,\n...\n 10\n ]'
56+
'- Buffer [Uint8Array] [\n 120,\n...\n 122,\n 10\n ]'
5757
}
5858
);
5959
assert.deepEqual(arr, buf);
@@ -66,9 +66,11 @@ assert.deepEqual(arr, buf);
6666
() => assert.deepStrictEqual(buf2, buf),
6767
{
6868
code: 'ERR_ASSERTION',
69-
message: `${defaultMsgStartFull} ... Lines skipped\n\n` +
69+
message: `${defaultMsgStartFull}\n\n` +
7070
' Buffer [Uint8Array] [\n' +
71-
'...\n' +
71+
' 120,\n' +
72+
' 121,\n' +
73+
' 122,\n' +
7274
' 10,\n' +
7375
'+ prop: 1\n' +
7476
' ]'
@@ -84,9 +86,11 @@ assert.deepEqual(arr, buf);
8486
() => assert.deepStrictEqual(arr, arr2),
8587
{
8688
code: 'ERR_ASSERTION',
87-
message: `${defaultMsgStartFull} ... Lines skipped\n\n` +
89+
message: `${defaultMsgStartFull}\n\n` +
8890
' Uint8Array [\n' +
89-
'...\n' +
91+
' 120,\n' +
92+
' 121,\n' +
93+
' 122,\n' +
9094
' 10,\n' +
9195
'- prop: 5\n' +
9296
' ]'
@@ -932,17 +936,19 @@ assert.deepStrictEqual(obj1, obj2);
932936
),
933937
{
934938
message: 'Expected values to be strictly deep-equal:\n' +
935-
'+ actual - expected ... Lines skipped\n' +
936-
'\n' +
937-
' Comparison {\n' +
938-
'...\n' +
939-
" \"+ foo: 'bar'\\n\" +\n" +
940-
"+ \"- foo: 'baz.'\\n\" +\n" +
941-
"- \"- foo: 'baz'\\n\" +\n" +
942-
" ' }',\n" +
943-
"+ operator: 'deepStrictEqual'\n" +
944-
"- operator: 'throws'\n" +
945-
' }'
939+
'+ actual - expected ... Lines skipped\n' +
940+
'\n' +
941+
' Comparison {\n' +
942+
" message: 'Expected values to be strictly deep-equal:\\n' +\n" +
943+
'...\n' +
944+
" ' [TypeError: foo] {\\n' +\n" +
945+
" \"+ foo: 'bar'\\n\" +\n" +
946+
"+ \"- foo: 'baz.'\\n\" +\n" +
947+
"- \"- foo: 'baz'\\n\" +\n" +
948+
" ' }',\n" +
949+
"+ operator: 'deepStrictEqual'\n" +
950+
"- operator: 'throws'\n" +
951+
' }'
946952
}
947953
);
948954
}

test/parallel/test-assert.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -481,12 +481,14 @@ assert.throws(
481481
'',
482482
' [',
483483
' [',
484-
'...',
484+
' [',
485+
' 1,',
485486
' 2,',
486487
'+ 3',
487488
"- '3'",
488489
' ]',
489490
'...',
491+
' 4,',
490492
' 5',
491493
' ]'].join('\n');
492494
assert.throws(
@@ -500,10 +502,12 @@ assert.throws(
500502
' [',
501503
' 1,',
502504
'...',
505+
' 1,',
503506
' 0,',
504507
'- 1,',
505508
' 1,',
506509
'...',
510+
' 1,',
507511
' 1',
508512
' ]'
509513
].join('\n');
@@ -520,10 +524,11 @@ assert.throws(
520524
' [',
521525
' 1,',
522526
'...',
527+
' 1,',
523528
' 0,',
524529
'+ 1,',
525530
' 1,',
526-
'...',
531+
' 1,',
527532
' 1',
528533
' ]'
529534
].join('\n');

test/pseudo-tty/test-assert-colors.js

Lines changed: 2 additions & 1 deletion

0 commit comments

Comments
 (0)