summaryrefslogtreecommitdiff
path: root/lib/assert.js
diff options
context:
space:
mode:
authorRuben Bridgewater <ruben@bridgewater.de>2017-12-09 19:38:20 -0200
committerRuben Bridgewater <ruben@bridgewater.de>2018-01-24 13:07:34 +0100
commit2d9e87695e16d80ecffc8eab50e9fe1dfa7005f5 (patch)
tree630dff5068317e263866d8d0d2bb07d7c1add615 /lib/assert.js
parentcb88f35a733c3d9efab5f7b18ca84047b93e7ab6 (diff)
downloadandroid-node-v8-2d9e87695e16d80ecffc8eab50e9fe1dfa7005f5.tar.gz
android-node-v8-2d9e87695e16d80ecffc8eab50e9fe1dfa7005f5.tar.bz2
android-node-v8-2d9e87695e16d80ecffc8eab50e9fe1dfa7005f5.zip
assert: improve error messages
From now on all error messages produced by `assert` in strict mode will produce a error diff. PR-URL: https://github.com/nodejs/node/pull/17615 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Diffstat (limited to 'lib/assert.js')
-rw-r--r--lib/assert.js16
1 files changed, 12 insertions, 4 deletions
diff --git a/lib/assert.js b/lib/assert.js
index db8ae35e07..9931ce9c22 100644
--- a/lib/assert.js
+++ b/lib/assert.js
@@ -48,6 +48,10 @@ const meta = [
const escapeFn = (str) => meta[str.charCodeAt(0)];
+const ERR_DIFF_DEACTIVATED = 0;
+const ERR_DIFF_NOT_EQUAL = 1;
+const ERR_DIFF_EQUAL = 2;
+
// The assert module provides functions that throw
// AssertionError's when particular conditions are not met. The
// assert module must conform to the following interface.
@@ -283,7 +287,8 @@ assert.deepStrictEqual = function deepStrictEqual(actual, expected, message) {
expected,
message,
operator: 'deepStrictEqual',
- stackStartFn: deepStrictEqual
+ stackStartFn: deepStrictEqual,
+ errorDiff: this === strict ? ERR_DIFF_EQUAL : ERR_DIFF_DEACTIVATED
});
}
};
@@ -296,7 +301,8 @@ function notDeepStrictEqual(actual, expected, message) {
expected,
message,
operator: 'notDeepStrictEqual',
- stackStartFn: notDeepStrictEqual
+ stackStartFn: notDeepStrictEqual,
+ errorDiff: this === strict ? ERR_DIFF_NOT_EQUAL : ERR_DIFF_DEACTIVATED
});
}
}
@@ -308,7 +314,8 @@ assert.strictEqual = function strictEqual(actual, expected, message) {
expected,
message,
operator: 'strictEqual',
- stackStartFn: strictEqual
+ stackStartFn: strictEqual,
+ errorDiff: this === strict ? ERR_DIFF_EQUAL : ERR_DIFF_DEACTIVATED
});
}
};
@@ -320,7 +327,8 @@ assert.notStrictEqual = function notStrictEqual(actual, expected, message) {
expected,
message,
operator: 'notStrictEqual',
- stackStartFn: notStrictEqual
+ stackStartFn: notStrictEqual,
+ errorDiff: this === strict ? ERR_DIFF_NOT_EQUAL : ERR_DIFF_DEACTIVATED
});
}
};