mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-28 06:53:42 +08:00
node:test changes, matching Node 24.22:
- t.before, t.after, t.beforeEach and t.afterEach lower. t.before runs
when it is called; a throw fails the test and the subtests that follow,
which skip their body and beforeEach hooks and run their afterEach hooks.
t.beforeEach and t.afterEach wrap every descendant subtest. t.after runs
after the test's afterEach chain, also when the body throws, and a throw
fails the test.
- t.plan(count) counts the test's t.assert calls and subtests. A mismatch
fails the test with Node's "plan expected N assertions but received M"
string, unless an assertion failed first.
- t.fullName joins the names from the outermost suite or test with " > ".
- Tests and suites under a todo suite or test are todo, with a bare TODO
directive, unless they are skipped or carry their own todo message. A
todo suite reports its directive.
- describe.only, suite.only and { only: true } on a suite mark it. At each
level, when a child is marked or contains a marked test or suite, only
those children run.
- The failing-tests section lists failures in completion order, so
subtests come before the test that ran them, and prints thrown strings
quoted, as Node inspects them.
The fixtures ctx-hooks, ctx-plan, todo-suites, suite-variants,
only-nested and thrown-values compare the reporter output and exit code
with Node.
46 lines
1.1 KiB
TypeScript
46 lines
1.1 KiB
TypeScript
// @exit: 1
|
|
// t.plan counts the test's t.assert calls and subtests; a mismatch fails
|
|
// the test with Node's string message, which the failing-tests section
|
|
// prints inspected. A failing assertion reports its own error. t.fullName
|
|
// joins the names from the outermost suite or test with " > ".
|
|
import { describe, it, test } from "node:test";
|
|
|
|
test("plan met", (t) => {
|
|
t.plan(2);
|
|
t.assert.ok(true);
|
|
t.assert.strictEqual(1, 1);
|
|
});
|
|
test("plan short", (t) => {
|
|
t.plan(3);
|
|
t.assert.ok(true);
|
|
});
|
|
test("plan over", (t) => {
|
|
t.plan(1);
|
|
t.assert.ok(true);
|
|
t.assert.ok(true);
|
|
});
|
|
test("plan counts subtests", async (t) => {
|
|
t.plan(2);
|
|
await t.test("a", () => {});
|
|
t.assert.ok(true);
|
|
});
|
|
test("plan with a failing assertion", (t) => {
|
|
t.plan(2);
|
|
t.assert.ok(true);
|
|
t.assert.strictEqual(1, 2);
|
|
});
|
|
|
|
describe("outer", () => {
|
|
describe("mid", () => {
|
|
it("leaf", (t) => {
|
|
t.assert.strictEqual(t.fullName, "outer > mid > leaf");
|
|
});
|
|
});
|
|
});
|
|
test("top", async (t) => {
|
|
t.assert.strictEqual(t.fullName, "top");
|
|
await t.test("child", (c) => {
|
|
c.assert.strictEqual(c.fullName, "top > child");
|
|
});
|
|
});
|