aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRuben Bridgewater <ruben@bridgewater.de>2018-04-02 18:42:11 +0200
committerJames M Snell <jasnell@gmail.com>2018-04-14 10:43:48 -0700
commit2b0825e77feb262cf862982cabf7a67bf58f4d5b (patch)
tree0ed1eaac009f81d8b4b71af56cadf44937f7068b /lib
parentbfe54df81240151a3aeaf99dcd91c362bab3a6b0 (diff)
downloadandroid-node-v8-2b0825e77feb262cf862982cabf7a67bf58f4d5b.tar.gz
android-node-v8-2b0825e77feb262cf862982cabf7a67bf58f4d5b.tar.bz2
android-node-v8-2b0825e77feb262cf862982cabf7a67bf58f4d5b.zip
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>
Diffstat (limited to 'lib')
-rw-r--r--lib/assert.js18
-rw-r--r--lib/internal/errors.js24
2 files changed, 17 insertions, 25 deletions
diff --git a/lib/assert.js b/lib/assert.js
index 180744c9c0..2164c22958 100644
--- a/lib/assert.js
+++ b/lib/assert.js
@@ -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;
diff --git a/lib/internal/errors.js b/lib/internal/errors.js
index 22d1006828..eff720f090 100644
--- a/lib/internal/errors.js
+++ b/lib/internal/errors.js
@@ -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}`);
}
}