diff --git a/lib/internal/test_runner/test.js b/lib/internal/test_runner/test.js index da502812f52c3b..effc73c0f2ca7d 100644 --- a/lib/internal/test_runner/test.js +++ b/lib/internal/test_runner/test.js @@ -12,7 +12,6 @@ const { MathMax, Number, ObjectDefineProperty, - ObjectEntries, ObjectSeal, PromisePrototypeThen, PromiseResolve, @@ -107,10 +106,28 @@ function lazyAssertObject() { if (assertObj === undefined) { assertObj = new SafeMap(); const assert = require('assert'); - for (const { 0: key, 1: value } of ObjectEntries(assert)) { - if (typeof value === 'function') { - assertObj.set(value, key); - } + + const methodsToCopy = [ + 'deepEqual', + 'deepStrictEqual', + 'doesNotMatch', + 'doesNotReject', + 'doesNotThrow', + 'equal', + 'fail', + 'ifError', + 'match', + 'notDeepEqual', + 'notDeepStrictEqual', + 'notEqual', + 'notStrictEqual', + 'ok', + 'rejects', + 'strictEqual', + 'throws', + ]; + for (let i = 0; i < methodsToCopy.length; i++) { + assertObj.set(methodsToCopy[i], assert[methodsToCopy[i]]); } } return assertObj; @@ -227,18 +244,18 @@ class TestContext { get assert() { if (this.#assert === undefined) { const { plan } = this.#test; - const assertions = lazyAssertObject(); + const map = lazyAssertObject(); const assert = { __proto__: null }; this.#assert = assert; - for (const { 0: method, 1: name } of assertions.entries()) { + map.forEach((method, name) => { assert[name] = (...args) => { if (plan !== null) { plan.actual++; } return ReflectApply(method, assert, args); }; - } + }); } return this.#assert; } diff --git a/test/parallel/test-runner-assert.js b/test/parallel/test-runner-assert.js new file mode 100644 index 00000000000000..2af05c95414d79 --- /dev/null +++ b/test/parallel/test-runner-assert.js @@ -0,0 +1,26 @@ +'use strict'; +require('../common'); +const { deepStrictEqual } = require('node:assert'); +const test = require('node:test'); + +test('only methods from node:assert are on t.assert', (t) => { + deepStrictEqual(Object.keys(t.assert).sort(), [ + 'deepEqual', + 'deepStrictEqual', + 'doesNotMatch', + 'doesNotReject', + 'doesNotThrow', + 'equal', + 'fail', + 'ifError', + 'match', + 'notDeepEqual', + 'notDeepStrictEqual', + 'notEqual', + 'notStrictEqual', + 'ok', + 'rejects', + 'strictEqual', + 'throws', + ]); +});