👢
Bootstrap Tests Manually
Pull yourself up by the bootstraps.
To use the@as-pect/core package, install the latest version from github along with @as-pect/assembly.
1
$ npm install --save-dev @as-pect/core @as-pect/assembly
Copied!
To create a TestContext simply import it and instantiate it.
1
import { TestContext, EmptyReporter } from "@as-pect/core";
2
import { instantiateBuffer } from "assemblyscript/lib/loader";
3
4
class Reporter extends EmptyReporter {
5
constructor() { super(); }
6
// implement the reporter functions here
7
}
8
const binary = await fetch("./path/to/test/binary.wasm");
9
const buffer = await binary.arrayBuffer();
10
const wasmBinary = new Uint8Array(buffer);
11
12
const ctx = new TestContext({
13
fileName: "test.spec.ts", // the name of your module
14
// groupRegex: /./, // filter the groups
15
// testRegex: /./, // filter the tests
16
// performanceConfiguration: {}, // deprecated
17
// nortrace: true, // disable rtrace monitoring
18
// stdout: null, // something that can write(input: string): void
19
// stderr: null, // something that can write(input: string): void
20
binary: wasmBinary, // the binary for test name collection
21
});
22
23
const imports = ctx.createImports({
24
// put any function imports here
25
});
26
27
// instantiate the module
28
const wasm = instantiateBuffer(wasmBinary, imports);
29
30
// run the tests
31
ctx.run(wasm);
32
33
// inspect the testGroups for errors and exit 1 if necessary
34
const groups = ctx.testGroups;
35
36
// check if the tests passed
37
const pass = ctx.pass;
Copied!
Copy link