Getting Started
Install
Add as-test to an AssemblyScript project:
npm install --save-dev as-testas-test is self-contained — value serialization for assertions, snapshots, and log() is built in, so there are no required peer dependencies.
The WASI target additionally needs @assemblyscript/wasi-shim:
npm install --save-dev @assemblyscript/wasi-shimScaffold a project
The fastest path is the initializer:
npx ast initast init can create:
as-test.config.json- runner scripts under
.as-test/runners/ - a sample spec in
assembly/__tests__/ - an optional sample fuzzer in
assembly/__fuzz__/ assembly/tsconfig.json
Useful flags:
| Flag | Effect |
|---|---|
--target <wasi|bindings|web> | Set the build target (default wasi). |
--example <minimal|full|none> | Choose the sample spec, or skip it. |
--fuzz-example / --no-fuzz-example | Include or omit the sample fuzzer. |
--enable <list> | Turn on features at scaffold time (e.g. coverage, try-as). |
--dir <path> | Scaffold into a specific directory. |
--install | Install dependencies after scaffolding. |
--yes, -y | Accept defaults; no prompts. |
--force | Overwrite managed files. |
npx ast init --target bindings --example full --fuzz-example --yesYour first spec
A spec is any file matched by input (default assembly/__tests__/*.spec.ts). Register suites, assert with expect, and end with run():
import { describe, expect, test } from "as-test";
describe("example", () => {
test("adds numbers", () => {
expect(1 + 2).toBe(3);
});
});
run()is called for you when a spec defines suites but never calls it. Add an explicitrun()only when you need to passRunOptions.
Run the suite
npx ast test # build + run every spec
npx ast test --parallel # spread files across a worker pool
npx ast fuzz # run fuzz targets only
npx ast test --fuzz # run specs, then fuzzers
npx ast test --watch # re-run on changeast test compiles each spec with the AssemblyScript compiler (running the as-test transform), then executes the resulting wasm through the configured runtime. See the CLI reference for the full flag set.
Minimal config
ast init writes this for you, but the whole thing fits in a few lines:
{
"input": ["assembly/__tests__/*.spec.ts"],
"output": ".as-test/",
"buildOptions": {
"target": "wasi"
},
"runOptions": {
"runtime": {
"cmd": "node ./.as-test/runners/default.wasi.js"
}
}
}Next
- Writing Tests — the full authoring surface.
- Assertions — every matcher.
- Runtimes & Modes — run the same specs on more than one runtime.
- Configuration — every config field.
