vael:test
Sequential registration-based test runner and reporting API.
Available in both vjs (vaeljs) and vjs-lite (vaeljs-lite) runtimes.
Note that TestOptions.timeout is only supported in vjs (vaeljs);
specifying timeout in vjs-lite throws VAEL_TEST_NO_TIMER.
import ... from "vael:test"
vaeljs-core; vael-test (default) in vaeljs-lite-core{ timeout } test option is supported in vjs (V8) only; vjs-lite rejects it with VAEL_TEST_NO_TIMER.Example
Section titled “Example”import assert from "vael:assert";import test, { run } from "vael:test";
test("addition works", () => { assert.strictEquals(2 + 2, 4);});
const report = await run({ throwOnFailure: false });console.log(report.passed, report.total);Functions
Section titled “Functions”export function test(name: string): void;
export function test(name: string, fn: () => unknown, options?: TestOptions): void;
Register a pending test case (fails the run because no callback was supplied).
Register a test case to execute on the next run().
Generator functions are rejected with VAEL_TEST_UNSUPPORTED.
| Name | Type | Description |
|---|---|---|
name | string | Non-blank test name. |
fn optional | () => unknown | Synchronous or async test body. |
options optional | TestOptions | Optional registration options ({ timeout }). |
voidTypeError— on invalidname; on invalid arguments or unknown options.Error— withcode"VAEL_TEST_DURING_RUN"or"VAEL_TEST_LIMIT"; withcode"VAEL_TEST_DURING_RUN","VAEL_TEST_LIMIT","VAEL_TEST_UNSUPPORTED", or"VAEL_TEST_NO_TIMER".
import assert from "vael:assert";import { test } from "vael:test";
test("async work resolves", async () => { const value = await Promise.resolve(123); assert.strictEquals(value, 123);});export function run(options?: RunOptions): Promise<TestReport>;
Execute queued tests in registration order and return the cumulative
TestReport.
| Name | Type | Description |
|---|---|---|
options optional | RunOptions | Optional { throwOnFailure, settle } flags. |
Promise<TestReport> — Promise resolving to the cumulative TestReport.TypeError— on invalid options.Error— withcode = "VAEL_TEST_ALREADY_RUNNING"if re-entered.TestFailureError— (code = "VAEL_TEST_FAILURES") whenthrowOnFailureistrueand any failure, pending test, unhandled rejection, or unsettled work was recorded.
import { run } from "vael:test";
const report = await run({ throwOnFailure: false });console.log(report.passed, report.failed);Classes
Section titled “Classes”TestFailureError
Section titled “TestFailureError”export class TestFailureError extends Error {
override name: "TestFailureError";
code: "VAEL_TEST_FAILURES";
failures: string[];
constructor(message: string, failures: string[]);
}
Error thrown by run() when throwOnFailure is true and any test
failed, was pending, or left unhandled/unsettled work.
constructor(message: string, failures: string[]);
Construct a TestFailureError.
| Name | Type | Description |
|---|---|---|
message | string | Summary failure message. |
failures | string[] | Individual formatted failure strings. |
| Property | Type | Description | Since |
|---|---|---|---|
name | "TestFailureError" | Error name ("TestFailureError"). | v0.0.0-alpha.0 |
code | "VAEL_TEST_FAILURES" | Machine-readable error code ("VAEL_TEST_FAILURES"). | v0.0.0-alpha.0 |
failures | string[] | Formatted failure messages. | v0.0.0-alpha.0 |
Interfaces
Section titled “Interfaces”TestOptions
Section titled “TestOptions”export interface TestOptions {
timeout?: number;
}
Options accepted by test(name, fn, options).
| Property | Type | Description | Since |
|---|---|---|---|
timeout optional | number | Per-test timeout in milliseconds (1..=2_147_483_647, default 30_000 in vjs V8). Not supported in vjs-lite (throws VAEL_TEST_NO_TIMER because QuickJS has no host timers). | v0.0.0-alpha.0 |
RunOptions
Section titled “RunOptions”export interface RunOptions {
throwOnFailure?: boolean;
settle?: boolean;
}
Options accepted by run(options).
| Property | Type | Description | Since |
|---|---|---|---|
throwOnFailure optional | boolean | Throw TestFailureError (code = "VAEL_TEST_FAILURES") if the cumulative report contains any failure, pending test, unhandled rejection, or unsettled event-loop work (default: true). | v0.0.0-alpha.0 |
settle optional | boolean | Run a bounded event-loop settle drain after tests finish (default: false). Intended for the runtime's final pass after entry module evaluation. | v0.0.0-alpha.0 |
TestReport
Section titled “TestReport”export interface TestReport {
total: number;
passed: number;
failed: number;
pending: number;
unhandled: number;
unsettled: number;
failures: string[];
}
Cumulative summary returned by run(options).
| Property | Type | Description | Since |
|---|---|---|---|
total | number | Total number of registered tests executed. | v0.0.0-alpha.0 |
passed | number | Count of passing tests. | v0.0.0-alpha.0 |
failed | number | Count of failing tests. | v0.0.0-alpha.0 |
pending | number | Count of pending tests (registered without a callback). | v0.0.0-alpha.0 |
unhandled | number | Count of unhandled Promise rejections observed during the run. | v0.0.0-alpha.0 |
unsettled | number | Count of unsettled async test promises. | v0.0.0-alpha.0 |
failures | string[] | Formatted failure messages for all failing/pending/unhandled items. | v0.0.0-alpha.0 |
Type Aliases
Section titled “Type Aliases”TestErrorCode
Section titled “TestErrorCode”export type TestErrorCode =
| "VAEL_TEST_FAILURES"
| "VAEL_TEST_DURING_RUN"
| "VAEL_TEST_ALREADY_RUNNING"
| "VAEL_TEST_LIMIT"
| "VAEL_TEST_UNSUPPORTED"
| "VAEL_TEST_NO_TIMER"
| "VAEL_TEST_PENDING"
| "VAEL_TEST_CYCLE"
| "VAEL_TEST_CHAIN"
| "VAEL_TEST_OBSERVE";
Error codes thrown by vael:test operations on Error.code.
Constants
Section titled “Constants”MAX_TESTS
Section titled “MAX_TESTS”export const MAX_TESTS: 10000;
Maximum number of tests that can be registered in one runtime (10_000).
Default Export
Section titled “Default Export”default export
Section titled “default export”export default test;
Default export: the test registration function.
