Files
scriptc/tests/diagnostics/test-option-fences.ts
T
Chris Tate 05cb9bd609 Add the concurrency test option
node:test changes, matching Node 24.22:

- { concurrency } on describe, suite, test, it and t.test sets how many
  subtests run at once: a number, true for os.availableParallelism() - 1,
  or false for 1. Subtests inherit the parent's value.
- Above 1, each subtest runs on its own fiber. Subtests start in
  declaration order as slots free up, and t.test and test() calls inside a
  concurrent test start the subtest at once; t.test's promise settles when
  it finishes. The parent finishes after all of them.
- Results, diagnostics and failures are reported in declaration order.
- A concurrent subtest waits after its beforeEach hooks, and a concurrent
  suite before its children, for as many turns as Node's runner does, so
  sibling bodies interleave as they do there.
- A concurrency that is not an integer from 1 to 4294967295 throws Node's
  ERR_OUT_OF_RANGE RangeError when the test or suite is created.
- Nested test() calls and hooks inside a concurrent subtest attach to the
  subtest that runs on the calling fiber.

The concurrency fixture compares the reporter output, the order of the
bodies' side effects, and the range errors with Node, plain and with
SCRIPTC_SAN=1.
2026-10-17 03:28:15 -05:00

21 lines
743 B
TypeScript

// node:test options lower for skip, todo, only and concurrency on tests and
// suites, and plan and timeout on tests. Each other form is refused with a
// named diagnostic: a concurrency that is neither a boolean literal nor a
// number, a suite's timeout and plan, and a plan that is not a
// non-negative integer literal.
import { describe, test } from "node:test";
test("lowers", { plan: 1, timeout: 50, concurrency: 2 }, (t) => {
t.assert.ok(true);
});
const parallel = process.argv.length > 2;
test("computed concurrency", { concurrency: parallel }, () => {});
describe("suite timeout", { timeout: 100 }, () => {});
describe("suite plan", { plan: 1 }, () => {});
const count = 2;
test("computed plan", { plan: count }, () => {});