fix(ext/node): add assert property to test context object (#28904)

This commit is contained in:
Yoshiya Hinosawa 2025-04-17 14:32:48 +09:00 committed by GitHub
parent e12d9b4946
commit 016b02d374
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 64 additions and 2 deletions

View file

@ -4,10 +4,44 @@ import { primordials } from "ext:core/mod.js";
const {
PromisePrototypeThen,
ArrayPrototypePush,
ArrayPrototypeForEach,
SafePromiseAll,
SafePromisePrototypeFinally,
} = primordials;
import { notImplemented, warnNotImplemented } from "ext:deno_node/_utils.ts";
import assert from "node:assert";
const methodsToCopy = [
"deepEqual",
"deepStrictEqual",
"doesNotMatch",
"doesNotReject",
"doesNotThrow",
"equal",
"fail",
"ifError",
"match",
"notDeepEqual",
"notDeepStrictEqual",
"notEqual",
"notStrictEqual",
"partialDeepStrictEqual",
"rejects",
"strictEqual",
"throws",
];
/** `assert` object available via t.assert */
let assertObject = undefined;
function getAssertObject() {
if (assertObject === undefined) {
assertObject = { __proto__: null };
ArrayPrototypeForEach(methodsToCopy, (method) => {
assertObject[method] = assert[method];
});
}
return assertObject;
}
export function run() {
notImplemented("test.run");
@ -22,6 +56,10 @@ class NodeTestContext {
this.#denoContext = t;
}
get assert() {
return getAssertObject();
}
get signal() {
notImplemented("test.TestContext.signal");
return null;