assert: remove errorDiff
property
The property is not necessary as it is possible to check for the operator instead. PR-URL: https://github.com/nodejs/node/pull/19467 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
bfe54df812
commit
2b0825e77f
@ -54,9 +54,6 @@ const meta = [
|
||||
|
||||
const escapeFn = (str) => meta[str.charCodeAt(0)];
|
||||
|
||||
const ERR_DIFF_NOT_EQUAL = 1;
|
||||
const ERR_DIFF_EQUAL = 2;
|
||||
|
||||
let warned = false;
|
||||
|
||||
// The assert module provides functions that throw
|
||||
@ -321,8 +318,7 @@ assert.deepStrictEqual = function deepStrictEqual(actual, expected, message) {
|
||||
expected,
|
||||
message,
|
||||
operator: 'deepStrictEqual',
|
||||
stackStartFn: deepStrictEqual,
|
||||
errorDiff: ERR_DIFF_EQUAL
|
||||
stackStartFn: deepStrictEqual
|
||||
});
|
||||
}
|
||||
};
|
||||
@ -335,8 +331,7 @@ function notDeepStrictEqual(actual, expected, message) {
|
||||
expected,
|
||||
message,
|
||||
operator: 'notDeepStrictEqual',
|
||||
stackStartFn: notDeepStrictEqual,
|
||||
errorDiff: ERR_DIFF_NOT_EQUAL
|
||||
stackStartFn: notDeepStrictEqual
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -348,8 +343,7 @@ assert.strictEqual = function strictEqual(actual, expected, message) {
|
||||
expected,
|
||||
message,
|
||||
operator: 'strictEqual',
|
||||
stackStartFn: strictEqual,
|
||||
errorDiff: ERR_DIFF_EQUAL
|
||||
stackStartFn: strictEqual
|
||||
});
|
||||
}
|
||||
};
|
||||
@ -361,8 +355,7 @@ assert.notStrictEqual = function notStrictEqual(actual, expected, message) {
|
||||
expected,
|
||||
message,
|
||||
operator: 'notStrictEqual',
|
||||
stackStartFn: notStrictEqual,
|
||||
errorDiff: ERR_DIFF_NOT_EQUAL
|
||||
stackStartFn: notStrictEqual
|
||||
});
|
||||
}
|
||||
};
|
||||
@ -389,8 +382,7 @@ function compareExceptionKey(actual, expected, key, message, keys) {
|
||||
actual: a,
|
||||
expected: b,
|
||||
operator: 'deepStrictEqual',
|
||||
stackStartFn: assert.throws,
|
||||
errorDiff: ERR_DIFF_EQUAL
|
||||
stackStartFn: assert.throws
|
||||
});
|
||||
Error.stackTraceLimit = tmpLimit;
|
||||
message = err.message;
|
||||
|
@ -395,8 +395,7 @@ class AssertionError extends Error {
|
||||
expected,
|
||||
message,
|
||||
operator,
|
||||
stackStartFn,
|
||||
errorDiff = 0
|
||||
stackStartFn
|
||||
} = options;
|
||||
|
||||
if (message != null) {
|
||||
@ -427,15 +426,10 @@ class AssertionError extends Error {
|
||||
expected = copyError(expected);
|
||||
}
|
||||
|
||||
if (errorDiff === 0) {
|
||||
let res = util.inspect(actual);
|
||||
let other = util.inspect(expected);
|
||||
if (res.length > 128)
|
||||
res = `${res.slice(0, 125)}...`;
|
||||
if (other.length > 128)
|
||||
other = `${other.slice(0, 125)}...`;
|
||||
super(`${res} ${operator} ${other}`);
|
||||
} else if (errorDiff === 1) {
|
||||
if (operator === 'deepStrictEqual' || operator === 'strictEqual') {
|
||||
super(createErrDiff(actual, expected, operator));
|
||||
} else if (operator === 'notDeepStrictEqual' ||
|
||||
operator === 'notStrictEqual') {
|
||||
// In case the objects are equal but the operator requires unequal, show
|
||||
// the first object and say A equals B
|
||||
const res = inspectValue(actual);
|
||||
@ -457,7 +451,13 @@ class AssertionError extends Error {
|
||||
super(`${base}\n\n ${res.join('\n ')}\n`);
|
||||
}
|
||||
} else {
|
||||
super(createErrDiff(actual, expected, operator));
|
||||
let res = util.inspect(actual);
|
||||
let other = util.inspect(expected);
|
||||
if (res.length > 128)
|
||||
res = `${res.slice(0, 125)}...`;
|
||||
if (other.length > 128)
|
||||
other = `${other.slice(0, 125)}...`;
|
||||
super(`${res} ${operator} ${other}`);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user