8000 assert: add compatibility for older Node.js versions · nodejs/node@6983a0c · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit 6983a0c

Browse files
BridgeARtargos
authored andcommitted
assert: add compatibility for older Node.js versions
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>
1 parent 0393045 commit 6983a0c

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

lib/internal/assert/assertion_error.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,9 @@ class AssertionError extends Error {
298298
const {
299299
message,
300300
operator,
301-
stackStartFn
301+
stackStartFn,
302+
// Compatibility with older versions.
303+
stackStartFunction
302304
} = options;
303305
let {
304306
actual,
@@ -418,7 +420,7 @@ class AssertionError extends Error {
418420
this.expected = expected;
419421
this.operator = operator;
420422
// eslint-disable-next-line no-restricted-syntax
421-
Error.captureStackTrace(this, stackStartFn);
423+
Error.captureStackTrace(this, stackStartFn || stackStartFunction);
422424
// Create error message including the error code in the name.
423425
this.stack;
424426
// Reset the name.

test/parallel/test-assert.js

+18
Original file line numberDiff line numberDiff line change
@@ -1203,3 +1203,21 @@ assert.throws(
12031203
() => a.deepStrictEqual(),
12041204
{ code: 'ERR_MISSING_ARGS' }
12051205
);
1206+
1207+
// Verify that `stackStartFunction` works as alternative to `stackStartFn`.
1208+
{
1209+
(function hidden() {
1210+
const err = new assert.AssertionError({
1211+
actual: 'foo',
1212+
operator: 'strictEqual',
1213+
stackStartFunction: hidden
1214+
});
1215+
const err2 = new assert.AssertionError({
1216+
actual: 'foo',
1217+
operator: 'strictEqual',
1218+
stackStartFn: hidden
1219+
});
1220+
assert(!err.stack.includes('hidden'));
1221+
assert(!err2.stack.includes('hidden'));
1222+
})();
1223+
}

0 commit comments

Comments
 (0)
0