IF Commons GitHub

Test

Quality: 16 tests: 13 passed, 0 failed, 3 skipped, 4 of 7 requirements proved, 0 open issues, 0 open tickets. The tests and issues of the library

Tests that run unchanged under bun test and node --test (commons 0001-test FR-001): registration on node:test, assertions on node:assert/strict, with short plain names (assert, assertEquals, assertStringIncludes, ...). proves names the requirements a test proves, as erga's kernel test.ts does, and keeps them for a report. Kept out of ./mod.ts, so that importing the runtime never loads a test runner.

Every test registered here is recorded by this module's own code, not by a runner's reporter (commons 0008-test-evidence FR-001 to FR-004): its id (the SHA-256 of its file and name), file, name, requirements, risk (the option risk, not-high by default), start and end, outcome (pass, fail, skip, todo or cancelled), a skip's or todo's reason, a failure's message, expected and actual values (redacted and cut to 4096 characters) and attempt (IFC_TEST_ATTEMPT, 1 by default), as a test span and a log record whose parent is the run's span from TRACEPARENT, on a resource that is the installation record. Where IFC_TEST_RECORD names a file, each test's records are appended to it as OTLP JSON lines as it starts and as it ends, and a test that has not ended when the process exits is appended as cancelled; otherwise they are kept in memory (recorded) and given to each listener (onTestRecord). The file of a test is the file that called test or proves, from the call's stack, relative to the working folder, or the option file. A test's outcome is never changed by its recording: a failure is still thrown to the runner.

A test's body is given a context t whose t.step(name, fn) runs a step as a subtest of node:test (TestContext.test), awaited, and records it in the test's evidence (commons 0001-test FR-002): a test step span, a child of the test's span (or of the step it is in), as it ends, and the test's steps, which its test span names in ifc.test.steps. A step that fails fails its test with the step's error, on every runner, so that the test's record says why.

only runs a test alone among the tests of its file (FR-060). Each runner is given node:test's only, and this module also skips the other tests of the file itself, so that "the one marked only runs alone" holds on each runner, and each of the others is recorded as skip with the reason ONLY_REASON:

  • node --test --test-only runs only the tests marked only, of itself;
  • node --test without --test-only (Node 26 then says "'only' and 'runOnly' require the --test-only command-line option") and bun test (Bun's node:test ignores only) run every test: the others then skip themselves, and a runner shows them as passed (Bun) or skipped (Node);
  • bun test --only runs no test of node:test at all, only or not, as its node:test never marks one: give bun test no --only. The others of the file are those registered before the first test marked only that have not started, and every one registered after it; bun test loads every file in one process, so the mark is kept for each file, never for the process.

Entry points

Modules

Examples

import { assertEquals, proves } from "./test.ts";
proves(["0001-test FR-001"], "one and one", () => assertEquals(1 + 1, 2));
proves(["0008-test-evidence FR-001"], "a high-risk test", () => assertEquals(2 * 2, 4), { risk: "high" });

Titles, headings, exports, tables, columns and requirements. Esc closes.