Skip to content

Commit 1c429cf

Browse files
BridgeARoyyd
authored andcommittedSep 25, 2018
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. PR-URL: nodejs#22788 Refs: nodejs#22763 Reviewed-By: John-David Dalton <john.david.dalton@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
1 parent 7f54071 commit 1c429cf

File tree

4 files changed

+31
-16
lines changed

4 files changed

+31
-16
lines changed
 

‎lib/internal/assert.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ function inspectValue(val) {
5252
// comparison.
5353
breakLength: Infinity,
5454
// Assert does not detect proxies currently.
55-
showProxy: false
55+
showProxy: false,
56+
sorted: true
5657
}
5758
);
5859
}

‎test/parallel/test-assert-deep.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ function re(literals, ...values) {
2323
depth: 1000,
2424
customInspect: false,
2525
maxArrayLength: Infinity,
26-
breakLength: Infinity
26+
breakLength: Infinity,
27+
sorted: true
2728
});
2829
// Need to escape special characters.
2930
result += str;

‎test/parallel/test-assert.js

+26-13
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ testAssertionMessage(-Infinity, '-Infinity');
293293
testAssertionMessage([1, 2, 3], '[\n+ 1,\n+ 2,\n+ 3\n+ ]');
294294
testAssertionMessage(function f() {}, '[Function: f]');
295295
testAssertionMessage(function() {}, '[Function]');
296-
testAssertionMessage(circular, '{\n+ y: 1,\n+ x: [Circular]\n+ }');
296+
testAssertionMessage(circular, '{\n+ x: [Circular],\n+ y: 1\n+ }');
297297
testAssertionMessage({ a: undefined, b: null },
298298
'{\n+ a: undefined,\n+ b: null\n+ }');
299299
testAssertionMessage({ a: NaN, b: Infinity, c: -Infinity },
@@ -602,8 +602,8 @@ assert.throws(
602602
'\n' +
603603
'+ {}\n' +
604604
'- {\n' +
605-
"- loop: 'forever',\n" +
606-
'- [Symbol(nodejs.util.inspect.custom)]: [Function]\n' +
605+
'- [Symbol(nodejs.util.inspect.custom)]: [Function],\n' +
606+
"- loop: 'forever'\n" +
607607
'- }'
608608
});
609609

@@ -870,9 +870,12 @@ common.expectsError(
870870
code: 'ERR_ASSERTION',
871871
name: 'AssertionError [ERR_ASSERTION]',
872872
message: `${start}\n${actExp}\n\n` +
873-
" Comparison {\n name: 'TypeError',\n" +
874-
" message: 'Wrong value',\n+ code: 404\n" +
875-
'- code: 404,\n- foo: undefined\n }'
873+
' Comparison {\n' +
874+
' code: 404,\n' +
875+
'- foo: undefined,\n' +
876+
" message: 'Wrong value',\n" +
877+
" name: 'TypeError'\n" +
878+
' }'
876879
}
877880
);
878881

@@ -884,9 +887,13 @@ common.expectsError(
884887
code: 'ERR_ASSERTION',
885888
name: 'AssertionError [ERR_ASSERTION]',
886889
message: `${start}\n${actExp}\n\n` +
887-
" Comparison {\n name: 'TypeError',\n" +
888-
" message: 'Wrong value',\n+ code: 404\n" +
889-
"- code: '404',\n- foo: undefined\n }"
890+
' Comparison {\n' +
891+
'+ code: 404,\n' +
892+
"- code: '404',\n" +
893+
'- foo: undefined,\n' +
894+
" message: 'Wrong value',\n" +
895+
" name: 'TypeError'\n" +
896+
' }'
890897
}
891898
);
892899

@@ -916,8 +923,11 @@ common.expectsError(
916923
name: 'AssertionError [ERR_ASSERTION]',
917924
code: 'ERR_ASSERTION',
918925
message: `${start}\n${actExp}\n\n` +
919-
" Comparison {\n+ name: 'TypeError',\n- name: 'Error'," +
920-
"\n message: 'e'\n }"
926+
' Comparison {\n' +
927+
" message: 'e',\n" +
928+
"+ name: 'TypeError'\n" +
929+
"- name: 'Error'\n" +
930+
' }'
921931
}
922932
);
923933
assert.throws(
@@ -927,8 +937,11 @@ common.expectsError(
927937
code: 'ERR_ASSERTION',
928938
generatedMessage: true,
929939
message: `${start}\n${actExp}\n\n` +
930-
" Comparison {\n name: 'Error',\n+ message: 'foo'" +
931-
"\n- message: ''\n }"
940+
' Comparison {\n' +
941+
"+ message: 'foo',\n" +
942+
"- message: '',\n" +
943+
" name: 'Error'\n" +
944+
' }'
932945
}
933946
);
934947

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

+1-1
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: 'Error for testing purposes: a'\n- message: \/\^Error/
95+
message: /\+ message: 'Error for testing purposes: a',\n- message: \/\^Error/
9696
});
9797

9898
// Test ERR_INVALID_FD_TYPE

0 commit comments

Comments
 (0)
Please sign in to comment.