Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 25 additions & 8 deletions lib/internal/test_runner/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const {
MathMax,
Number,
ObjectDefineProperty,
ObjectEntries,
ObjectSeal,
PromisePrototypeThen,
PromiseResolve,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
26 changes: 26 additions & 0 deletions test/parallel/test-runner-assert.js
Original file line number Diff line number Diff line change
@@ -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',
]);
});