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 escapeFn = (str) => meta[str.charCodeAt(0)];
|
||||||
|
|
||||||
const ERR_DIFF_NOT_EQUAL = 1;
|
|
||||||
const ERR_DIFF_EQUAL = 2;
|
|
||||||
|
|
||||||
let warned = false;
|
let warned = false;
|
||||||
|
|
||||||
// The assert module provides functions that throw
|
// The assert module provides functions that throw
|
||||||
@ -321,8 +318,7 @@ assert.deepStrictEqual = function deepStrictEqual(actual, expected, message) {
|
|||||||
expected,
|
expected,
|
||||||
message,
|
message,
|
||||||
operator: 'deepStrictEqual',
|
operator: 'deepStrictEqual',
|
||||||
stackStartFn: deepStrictEqual,
|
stackStartFn: deepStrictEqual
|
||||||
errorDiff: ERR_DIFF_EQUAL
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -335,8 +331,7 @@ function notDeepStrictEqual(actual, expected, message) {
|
|||||||
expected,
|
expected,
|
||||||
message,
|
message,
|
||||||
operator: 'notDeepStrictEqual',
|
operator: 'notDeepStrictEqual',
|
||||||
stackStartFn: notDeepStrictEqual,
|
stackStartFn: notDeepStrictEqual
|
||||||
errorDiff: ERR_DIFF_NOT_EQUAL
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -348,8 +343,7 @@ assert.strictEqual = function strictEqual(actual, expected, message) {
|
|||||||
expected,
|
expected,
|
||||||
message,
|
message,
|
||||||
operator: 'strictEqual',
|
operator: 'strictEqual',
|
||||||
stackStartFn: strictEqual,
|
stackStartFn: strictEqual
|
||||||
errorDiff: ERR_DIFF_EQUAL
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -361,8 +355,7 @@ assert.notStrictEqual = function notStrictEqual(actual, expected, message) {
|
|||||||
expected,
|
expected,
|
||||||
message,
|
message,
|
||||||
operator: 'notStrictEqual',
|
operator: 'notStrictEqual',
|
||||||
stackStartFn: notStrictEqual,
|
stackStartFn: notStrictEqual
|
||||||
errorDiff: ERR_DIFF_NOT_EQUAL
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -389,8 +382,7 @@ function compareExceptionKey(actual, expected, key, message, keys) {
|
|||||||
actual: a,
|
actual: a,
|
||||||
expected: b,
|
expected: b,
|
||||||
operator: 'deepStrictEqual',
|
operator: 'deepStrictEqual',
|
||||||
stackStartFn: assert.throws,
|
stackStartFn: assert.throws
|
||||||
errorDiff: ERR_DIFF_EQUAL
|
|
||||||
});
|
});
|
||||||
Error.stackTraceLimit = tmpLimit;
|
Error.stackTraceLimit = tmpLimit;
|
||||||
message = err.message;
|
message = err.message;
|
||||||
|
@ -395,8 +395,7 @@ class AssertionError extends Error {
|
|||||||
expected,
|
expected,
|
||||||
message,
|
message,
|
||||||
operator,
|
operator,
|
||||||
stackStartFn,
|
stackStartFn
|
||||||
errorDiff = 0
|
|
||||||
} = options;
|
} = options;
|
||||||
|
|
||||||
if (message != null) {
|
if (message != null) {
|
||||||
@ -427,15 +426,10 @@ class AssertionError extends Error {
|
|||||||
expected = copyError(expected);
|
expected = copyError(expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (errorDiff === 0) {
|
if (operator === 'deepStrictEqual' || operator === 'strictEqual') {
|
||||||
let res = util.inspect(actual);
|
super(createErrDiff(actual, expected, operator));
|
||||||
let other = util.inspect(expected);
|
} else if (operator === 'notDeepStrictEqual' ||
|
||||||
if (res.length > 128)
|
operator === 'notStrictEqual') {
|
||||||
res = `${res.slice(0, 125)}...`;
|
|
||||||
if (other.length > 128)
|
|
||||||
other = `${other.slice(0, 125)}...`;
|
|
||||||
super(`${res} ${operator} ${other}`);
|
|
||||||
} else if (errorDiff === 1) {
|
|
||||||
// In case the objects are equal but the operator requires unequal, show
|
// In case the objects are equal but the operator requires unequal, show
|
||||||
// the first object and say A equals B
|
// the first object and say A equals B
|
||||||
const res = inspectValue(actual);
|
const res = inspectValue(actual);
|
||||||
@ -457,7 +451,13 @@ class AssertionError extends Error {
|
|||||||
super(`${base}\n\n ${res.join('\n ')}\n`);
|
super(`${base}\n\n ${res.join('\n ')}\n`);
|
||||||
}
|
}
|
||||||
} else {
|
} 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