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: https://github.com/nodejs/node/pull/22788 Refs: https://github.com/nodejs/node/issues/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>
This commit is contained in:
parent
b95b0d87c3
commit
28902f33aa
@ -52,7 +52,8 @@ function inspectValue(val) {
|
|||||||
// comparison.
|
// comparison.
|
||||||
breakLength: Infinity,
|
breakLength: Infinity,
|
||||||
// Assert does not detect proxies currently.
|
// Assert does not detect proxies currently.
|
||||||
showProxy: false
|
showProxy: false,
|
||||||
|
sorted: true
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,8 @@ function re(literals, ...values) {
|
|||||||
depth: 1000,
|
depth: 1000,
|
||||||
customInspect: false,
|
customInspect: false,
|
||||||
maxArrayLength: Infinity,
|
maxArrayLength: Infinity,
|
||||||
breakLength: Infinity
|
breakLength: Infinity,
|
||||||
|
sorted: true
|
||||||
});
|
});
|
||||||
// Need to escape special characters.
|
// Need to escape special characters.
|
||||||
result += str;
|
result += str;
|
||||||
|
@ -293,7 +293,7 @@ testAssertionMessage(-Infinity, '-Infinity');
|
|||||||
testAssertionMessage([1, 2, 3], '[\n+ 1,\n+ 2,\n+ 3\n+ ]');
|
testAssertionMessage([1, 2, 3], '[\n+ 1,\n+ 2,\n+ 3\n+ ]');
|
||||||
testAssertionMessage(function f() {}, '[Function: f]');
|
testAssertionMessage(function f() {}, '[Function: f]');
|
||||||
testAssertionMessage(function() {}, '[Function]');
|
testAssertionMessage(function() {}, '[Function]');
|
||||||
testAssertionMessage(circular, '{\n+ y: 1,\n+ x: [Circular]\n+ }');
|
testAssertionMessage(circular, '{\n+ x: [Circular],\n+ y: 1\n+ }');
|
||||||
testAssertionMessage({ a: undefined, b: null },
|
testAssertionMessage({ a: undefined, b: null },
|
||||||
'{\n+ a: undefined,\n+ b: null\n+ }');
|
'{\n+ a: undefined,\n+ b: null\n+ }');
|
||||||
testAssertionMessage({ a: NaN, b: Infinity, c: -Infinity },
|
testAssertionMessage({ a: NaN, b: Infinity, c: -Infinity },
|
||||||
@ -602,8 +602,8 @@ assert.throws(
|
|||||||
'\n' +
|
'\n' +
|
||||||
'+ {}\n' +
|
'+ {}\n' +
|
||||||
'- {\n' +
|
'- {\n' +
|
||||||
"- loop: 'forever',\n" +
|
'- [Symbol(nodejs.util.inspect.custom)]: [Function],\n' +
|
||||||
'- [Symbol(nodejs.util.inspect.custom)]: [Function]\n' +
|
"- loop: 'forever'\n" +
|
||||||
'- }'
|
'- }'
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -885,9 +885,12 @@ common.expectsError(
|
|||||||
code: 'ERR_ASSERTION',
|
code: 'ERR_ASSERTION',
|
||||||
name: 'AssertionError [ERR_ASSERTION]',
|
name: 'AssertionError [ERR_ASSERTION]',
|
||||||
message: `${start}\n${actExp}\n\n` +
|
message: `${start}\n${actExp}\n\n` +
|
||||||
" Comparison {\n name: 'TypeError',\n" +
|
' Comparison {\n' +
|
||||||
" message: 'Wrong value',\n+ code: 404\n" +
|
' code: 404,\n' +
|
||||||
'- code: 404,\n- foo: undefined\n }'
|
'- foo: undefined,\n' +
|
||||||
|
" message: 'Wrong value',\n" +
|
||||||
|
" name: 'TypeError'\n" +
|
||||||
|
' }'
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -899,9 +902,13 @@ common.expectsError(
|
|||||||
code: 'ERR_ASSERTION',
|
code: 'ERR_ASSERTION',
|
||||||
name: 'AssertionError [ERR_ASSERTION]',
|
name: 'AssertionError [ERR_ASSERTION]',
|
||||||
message: `${start}\n${actExp}\n\n` +
|
message: `${start}\n${actExp}\n\n` +
|
||||||
" Comparison {\n name: 'TypeError',\n" +
|
' Comparison {\n' +
|
||||||
" message: 'Wrong value',\n+ code: 404\n" +
|
'+ code: 404,\n' +
|
||||||
"- code: '404',\n- foo: undefined\n }"
|
"- code: '404',\n" +
|
||||||
|
'- foo: undefined,\n' +
|
||||||
|
" message: 'Wrong value',\n" +
|
||||||
|
" name: 'TypeError'\n" +
|
||||||
|
' }'
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -931,8 +938,11 @@ common.expectsError(
|
|||||||
name: 'AssertionError [ERR_ASSERTION]',
|
name: 'AssertionError [ERR_ASSERTION]',
|
||||||
code: 'ERR_ASSERTION',
|
code: 'ERR_ASSERTION',
|
||||||
message: `${start}\n${actExp}\n\n` +
|
message: `${start}\n${actExp}\n\n` +
|
||||||
" Comparison {\n+ name: 'TypeError',\n- name: 'Error'," +
|
' Comparison {\n' +
|
||||||
"\n message: 'e'\n }"
|
" message: 'e',\n" +
|
||||||
|
"+ name: 'TypeError'\n" +
|
||||||
|
"- name: 'Error'\n" +
|
||||||
|
' }'
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
assert.throws(
|
assert.throws(
|
||||||
@ -942,8 +952,11 @@ common.expectsError(
|
|||||||
code: 'ERR_ASSERTION',
|
code: 'ERR_ASSERTION',
|
||||||
generatedMessage: true,
|
generatedMessage: true,
|
||||||
message: `${start}\n${actExp}\n\n` +
|
message: `${start}\n${actExp}\n\n` +
|
||||||
" Comparison {\n name: 'Error',\n+ message: 'foo'" +
|
' Comparison {\n' +
|
||||||
"\n- message: ''\n }"
|
"+ message: 'foo',\n" +
|
||||||
|
"- message: '',\n" +
|
||||||
|
" name: 'Error'\n" +
|
||||||
|
' }'
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -92,7 +92,7 @@ common.expectsError(() => {
|
|||||||
}, {
|
}, {
|
||||||
code: 'ERR_ASSERTION',
|
code: 'ERR_ASSERTION',
|
||||||
type: assert.AssertionError,
|
type: assert.AssertionError,
|
||||||
message: /\+ message: 'Error for testing purposes: a'\n- message: \/\^Error/
|
message: /\+ message: 'Error for testing purposes: a',\n- message: \/\^Error/
|
||||||
});
|
});
|
||||||
|
|
||||||
// Test ERR_INVALID_FD_TYPE
|
// Test ERR_INVALID_FD_TYPE
|
||||||
|
Loading…
x
Reference in New Issue
Block a user