Skip to content

Commit

Permalink
assert: add compatibility for older Node.js versions
Browse files Browse the repository at this point in the history
This makes sure the `AssertionError` still accepts the
`stackStartFunction` option as alternative to the `stackStartFn`.

PR-URL: #27672
Fixes: #27671
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
  • Loading branch information
BridgeAR authored and targos committed May 17, 2019
1 parent 0393045 commit 6983a0c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/internal/assert/assertion_error.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,9 @@ class AssertionError extends Error {
const {
message,
operator,
stackStartFn
stackStartFn,
// Compatibility with older versions.
stackStartFunction
} = options;
let {
actual,
Expand Down Expand Up @@ -418,7 +420,7 @@ class AssertionError extends Error {
this.expected = expected;
this.operator = operator;
// eslint-disable-next-line no-restricted-syntax
Error.captureStackTrace(this, stackStartFn);
Error.captureStackTrace(this, stackStartFn || stackStartFunction);
// Create error message including the error code in the name.
this.stack;
// Reset the name.
Expand Down
18 changes: 18 additions & 0 deletions test/parallel/test-assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -1203,3 +1203,21 @@ assert.throws(
() => a.deepStrictEqual(),
{ code: 'ERR_MISSING_ARGS' }
);

// Verify that `stackStartFunction` works as alternative to `stackStartFn`.
{
(function hidden() {
const err = new assert.AssertionError({
actual: 'foo',
operator: 'strictEqual',
stackStartFunction: hidden
});
const err2 = new assert.AssertionError({
actual: 'foo',
operator: 'strictEqual',
stackStartFn: hidden
});
assert(!err.stack.includes('hidden'));
assert(!err2.stack.includes('hidden'));
})();
}

0 comments on commit 6983a0c

Please sign in to comment.