Files
scriptc/tests/fixtures/node-test/cases/only-nested.ts
T
Chris Tate 681f5ceee7 Add TestContext hooks, plan and fullName, and Node's todo and only rules
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.
2026-10-15 23:16:04 -05:00

29 lines
846 B
TypeScript

// The only twins of describe, suite and it inside a suite: the marked
// tests and suites run, and their unmarked siblings, and the unmarked
// top-level suites, do not.
import { describe, it, suite } from "node:test";
describe("not marked", () => {
it("dropped with its suite", () => {
throw new Error("an unmarked top-level suite does not run");
});
});
describe("only among siblings", () => {
it.only("it.only runs", () => {});
it("dropped", () => {
throw new Error("an unmarked sibling of it.only does not run");
});
describe.only("describe.only", () => {
it("inside", () => {});
});
suite.only("suite.only", () => {
it("inside", () => {});
});
describe("unmarked suite", () => {
it("dropped", () => {
throw new Error("an unmarked suite next to describe.only does not run");
});
});
});