// Type definitions for tst // ───────────────────────────────────────────────────────────────────────────── // Assertions (from assert.js) // ───────────────────────────────────────────────────────────────────────────── export class Assertion extends Error { operator: string actual?: unknown expected?: unknown } /** Assert value is truthy */ export function ok(value: unknown, msg?: string): true /** Assert deep equality (Object.is for primitives, deep equal for objects) */ export function is(actual: T, expected: T, msg?: string): true /** Assert values differ */ export function not(actual: T, expected: T, msg?: string): true /** Assert value is one of options */ export function any(value: T, options: T[], msg?: string): true /** Assert arrays have same members (order-independent) */ export function same(actual: T[], expected: T[], msg?: string): true /** Assert function throws (optionally matching pattern) */ export function throws( fn: () => unknown, expected?: RegExp | ErrorConstructor | ((err: Error) => boolean), msg?: string ): true /** Assert approximate equality (for floats) */ export function almost(a: number, b: number, eps?: number, msg?: string): true export function almost(a: number[], b: number[], eps?: number, msg?: string): true /** Explicit pass */ export function pass(msg?: string): true /** Explicit fail (always throws) */ export function fail(msg?: string): never /** Hook for capturing assertion passes (internal) */ export function onPass(fn: ((info: { operator: string; message: string }) => void) | null): void // ───────────────────────────────────────────────────────────────────────────── // Test runner (from tst.js) // ───────────────────────────────────────────────────────────────────────────── export interface TestOptions { timeout?: number } export interface RunOptions { timeout?: number grep?: RegExp | string bail?: boolean mute?: boolean format?: string | Format } export interface RunState { passed: number failed: [string, { name: string }][] skipped: number assertCount: number } export interface Format { testStart(name: string, type: string, muted: boolean): void testSkip(name: string, type: string): void assertion(n: number, operator: string, message: string): void testPass(name: string, type: string, assertCount: number, muted: boolean): void testFail(name: string, error: Error, assertCount: number, muted: boolean): void summary(state: RunState, opts?: { grep?: RegExp; only?: number }): void } export interface Formats { pretty: Format tap: Format [key: string]: Format } export const formats: Formats /** Assert module passed to test callbacks */ export interface Assert { ok: typeof ok is: typeof is not: typeof not any: typeof any same: typeof same throws: typeof throws almost: typeof almost pass: typeof pass fail: typeof fail } type TestFn = (t: Assert) => void | Promise interface Test { (name: string, fn: TestFn): void (name: string, opts: TestOptions, fn: TestFn): void (name: string): void // no fn = todo /** Skip this test */ skip(name: string, fn?: TestFn): void /** Mark as todo (planned) */ todo(name: string, fn?: TestFn): void /** Run only this test */ only(name: string, fn: TestFn): void only(name: string, opts: TestOptions, fn: TestFn): void /** Demo mode: run but failures don't affect exit code */ demo(name: string, fn: TestFn): void demo(name: string, opts: TestOptions, fn: TestFn): void /** Mute mode: hide assertion output, show summary */ mute(name: string, fn: TestFn): void mute(name: string, opts: TestOptions, fn: TestFn): void /** Fork mode: run in isolated worker thread (benchmarking, isolation) */ fork(name: string, fn: TestFn): void fork(name: string, opts: TestOptions, fn: TestFn): void /** Manually run tests */ run(opts?: RunOptions): Promise } declare const test: Test export default test /** Run all registered tests */ export function run(opts?: RunOptions): Promise