util: inspect() should not exceed breakLength

Using `util.inspect()` with the `compact` option set to a number
could result in output that exceeded the `breakLength` option. This
change makes sure that limit is taken into account.

PR-URL: https://github.com/nodejs/node/pull/26914
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
This commit is contained in:
Ruben Bridgewater committed 2019-04-03 02:20:31 +02:00
1 parent 7aa7971eec
commit e1e9f1e9ee
3 files changed
+98 -3

No files matched your search

+6 -3
View File
@@ -18,8 +18,8 @@ const kReadableOperator = {
equal: 'Expected values to be loosely equal:',
notDeepStrictEqual: 'Expected "actual" not to be strictly deep-equal to:',
notStrictEqual: 'Expected "actual" to be strictly unequal to:',
// eslint-disable-next-line max-len
notStrictEqualObject: 'Expected "actual" not to be reference-equal to "expected":',
notStrictEqualObject:
'Expected "actual" not to be reference-equal to "expected":',
notDeepEqual: 'Expected "actual" not to be loosely deep-equal to:',
notEqual: 'Expected "actual" to be loosely unequal to:',
notIdentical: 'Values identical but not reference-equal:',
@@ -52,7 +52,10 @@ function inspectValue(val) {
// Assert compares only enumerable properties (with a few exceptions).
showHidden: false,
// Having a long line as error is better than wrapping the line for
// comparison.
// comparison for now.
// TODO(BridgeAR): `breakLength` should be limited as soon as soon as we
// have meta information about the inspected properties (i.e., know where
// in what line the property starts and ends).
breakLength: Infinity,
// Assert does not detect proxies currently.
showProxy: false,