zena:test
import {…} from 'zena:test';
Test framework for structuring and running test suites.
Provides suite and test functions to define hierarchical test suites,
executed through the Zena CLI test runner (zena test).
A test's body is synchronous, or async: an asynchronous body is
awaited before the next test starts, and a failure anywhere in it,
before or after an await, is the test's failure. Tests run one at
a time, in the order they were registered.
Examples ​
import { suite, test, TestContext } from 'zena:test';
import { equal } from 'zena:assert';
import { readFile } from 'zena:fs';
export let tests = suite('Math', () => {
test('addition', (ctx: TestContext) => {
equal(1 + 1, 2);
});
test('a file', async (ctx: TestContext) => {
equal(await readFile('two.txt'), '2');
});
});
Classes
TestContext
class TestContext
Test context passed to each test function
TestResult
class TestResult
Result of a single test execution
SuiteResult
class SuiteResult
Suite
class Suite
A test suite containing tests and nested suites
Functions
test
function test(name: String, fn: (ctx: TestContext) => void): void
Register a test in the current suite
test
function test(name: String, fn: (ctx: TestContext) => Future<void>): void
Register a test whose body is asynchronous. The next test starts once the body's future has settled.
testOnly
function testOnly(name: String, fn: (ctx: TestContext) => void): void
Register a test that will be the only one to run (for debugging)
testOnly
function testOnly(name: String, fn: (ctx: TestContext) => Future<void>): void
testSkip
function testSkip(name: String, fn: (ctx: TestContext) => void): void
Register a test that will be skipped
testSkip
function testSkip(name: String, fn: (ctx: TestContext) => Future<void>): void
suite
function suite(name: String, fn: () => void): Suite
Create a test suite
runAndReport
async function runAndReport(s: Suite, write: (s: String) => void): Future<i32>
Run a suite, print results, and return the number of failures. This is the standard entry point for test runners.
Usage in a test wrapper:
import { tests } from './my_test.zena';
import { runAndReport } from 'zena:test';
export async function main(): Future