Skip to content

Commit efdb326

Browse files
BridgeARtargos
authored andcommitted
assert: improve diff output
The output is now a tiny bit improved by sorting object properties when inspecting the values that are compared with each other. That reduces the overall diff for identical objects with a different property insertion order. Backport-PR-URL: #23226 PR-URL: #22788 Refs: #22763 Reviewed-By: John-David Dalton <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]>
1 parent cf17759 commit efdb326

File tree

3 files changed

+29
-15
lines changed

3 files changed

+29
-15
lines changed

‎lib/internal/assert.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ function inspectValue(val){
4343
// comparison.
4444
breakLength: Infinity,
4545
// Assert does not detect proxies currently.
46-
showProxy: false
46+
showProxy: false,
47+
sorted: true
4748
}
4849
).split('\n');
4950
}

‎test/parallel/test-assert.js‎

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ testAssertionMessage(/abc/gim, '/abc/gim');
285285
testAssertionMessage(functionf(){},'[Function: f]');
286286
testAssertionMessage(function(){},'[Function]');
287287
testAssertionMessage({},'{}');
288-
testAssertionMessage(circular,'{\n- y: 1,\n- x: [Circular]\n- }');
288+
testAssertionMessage(circular,'{\n- x: [Circular],\n- y: 1\n- }');
289289
testAssertionMessage({a: undefined,b: null},
290290
'{\n- a: undefined,\n- b: null\n- }');
291291
testAssertionMessage({a: NaN,b: Infinity,c: -Infinity},
@@ -593,8 +593,8 @@ assert.throws(
593593
'\n'+
594594
'-{}\n'+
595595
'+{\n'+
596-
"+ loop: 'forever',\n"+
597-
'+ [Symbol(nodejs.util.inspect.custom)]: [Function]\n'+
596+
'+ [Symbol(nodejs.util.inspect.custom)]: [Function],\n'+
597+
"+ loop: 'forever'\n"+
598598
'+ }'
599599
});
600600

@@ -858,9 +858,12 @@ common.expectsError(
858858
code: 'ERR_ASSERTION',
859859
name: 'AssertionError [ERR_ASSERTION]',
860860
message: `${start}\n${actExp}\n\n`+
861-
" Comparison{\n name: 'TypeError',\n"+
862-
" message: 'Wrong value',\n- code: 404\n"+
863-
'+ code: 404,\n+ foo: undefined\n }'
861+
' Comparison{\n'+
862+
' code: 404,\n'+
863+
'+ foo: undefined,\n'+
864+
" message: 'Wrong value',\n"+
865+
" name: 'TypeError'\n"+
866+
'}'
864867
}
865868
);
866869

@@ -872,9 +875,13 @@ common.expectsError(
872875
code: 'ERR_ASSERTION',
873876
name: 'AssertionError [ERR_ASSERTION]',
874877
message: `${start}\n${actExp}\n\n`+
875-
" Comparison{\n name: 'TypeError',\n"+
876-
" message: 'Wrong value',\n- code: 404\n"+
877-
"+ code: '404',\n+ foo: undefined\n }"
878+
' Comparison{\n'+
879+
'- code: 404,\n'+
880+
"+ code: '404',\n"+
881+
'+ foo: undefined,\n'+
882+
" message: 'Wrong value',\n"+
883+
" name: 'TypeError'\n"+
884+
'}'
878885
}
879886
);
880887

@@ -904,8 +911,11 @@ common.expectsError(
904911
name: 'AssertionError [ERR_ASSERTION]',
905912
code: 'ERR_ASSERTION',
906913
message: `${start}\n${actExp}\n\n`+
907-
" Comparison{\n- name: 'TypeError',\n+ name: 'Error',"+
908-
"\n message: 'e'\n }"
914+
' Comparison{\n'+
915+
" message: 'e',\n"+
916+
"- name: 'TypeError'\n"+
917+
"+ name: 'Error'\n"+
918+
'}'
909919
}
910920
);
911921
assert.throws(
@@ -915,8 +925,11 @@ common.expectsError(
915925
code: 'ERR_ASSERTION',
916926
generatedMessage: true,
917927
message: `${start}\n${actExp}\n\n`+
918-
" Comparison{\n name: 'Error',\n- message: 'foo'"+
919-
"\n+ message: ''\n }"
928+
' Comparison{\n'+
929+
"- message: 'foo',\n"+
930+
"+ message: '',\n"+
931+
" name: 'Error'\n"+
932+
'}'
920933
}
921934
);
922935

‎test/parallel/test-internal-errors.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ common.expectsError(() =>{
9292
},{
9393
code: 'ERR_ASSERTION',
9494
type: assert.AssertionError,
95-
message: /-message:'Errorfortestingpurposes:a'\n\+message:\/\^Error/
95+
message: /-message:'Errorfortestingpurposes:a',\n\+message:\/\^Error/
9696
});
9797

9898
// Test ERR_INVALID_FD_TYPE

0 commit comments

Comments
(0)