vitest-pool-assemblyscript 0.2.1 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +114 -314
- package/binding.gyp +4 -4
- package/dist/{compile-runner-8h0dBwG2.mjs → compile-runner-xGvQwgNf.mjs} +2 -2
- package/dist/{compile-runner-8h0dBwG2.mjs.map → compile-runner-xGvQwgNf.mjs.map} +1 -1
- package/dist/config/index.mjs +1 -1
- package/dist/coverage-provider/index.mjs +2 -1
- package/dist/coverage-provider/index.mjs.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/{load-user-imports-J9eaAW0_.mjs → load-user-imports-Bbmpaciu.mjs} +5 -4
- package/dist/{load-user-imports-J9eaAW0_.mjs.map → load-user-imports-Bbmpaciu.mjs.map} +1 -1
- package/dist/{pool-runner-init-d5qScS41.mjs → pool-runner-init-Kuzz61rB.mjs} +2 -2
- package/dist/pool-runner-init-Kuzz61rB.mjs.map +1 -0
- package/dist/pool-thread/compile-worker-thread.mjs +2 -2
- package/dist/pool-thread/test-worker-thread.mjs +2 -2
- package/dist/pool-thread/v3-tinypool-thread.mjs +3 -3
- package/dist/{test-runner-B2BpyPNK.mjs → test-runner-BR4XyhMA.mjs} +2 -2
- package/dist/{test-runner-B2BpyPNK.mjs.map → test-runner-BR4XyhMA.mjs.map} +1 -1
- package/package.json +18 -2
- package/prebuilds/linux-x64/vitest-pool-assemblyscript.glibc.node +0 -0
- package/prebuilds/{linux-arm64/vitest-pool-assemblyscript.glibc.node → linux-x64/vitest-pool-assemblyscript.musl.node} +0 -0
- package/scripts/setup-binaryen.js +253 -79
- package/src/native-instrumentation/addon.cpp +2 -2
- package/dist/pool-runner-init-d5qScS41.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -2,305 +2,160 @@
|
|
|
2
2
|
|
|
3
3
|
AssemblyScript unit testing for your Vitest workflow: Simple, fast, familiar, AS-native.
|
|
4
4
|
|
|
5
|
-
This is a [Vitest](https://vitest.dev) [
|
|
5
|
+
This is a [Vitest](https://vitest.dev) [custom pool](https://vitest.dev/guide/advanced/pool.html) which can compile AssemblyScript to WASM, harness WASM to run tests, and report those results to vitest. It co-exists with existing JavaScript/TypeScript tests, and is designed for incremental adoption.
|
|
6
6
|
|
|
7
|
-
- [
|
|
7
|
+
- [Quick Start](#quick-start)
|
|
8
|
+
- [Compatibility](#compatibility)
|
|
8
9
|
- [Features](#features)
|
|
9
|
-
- [Configuration](
|
|
10
|
-
- [
|
|
10
|
+
- [Configuration Guide](docs/configuration-guide.md)
|
|
11
|
+
- [Providing WASM Imports](docs/providing-wasm-imports.md)
|
|
12
|
+
- [Writing Tests Guide](#writing-tests-guide)
|
|
11
13
|
- [Matcher API](#matcher-api)
|
|
12
14
|
- [Project Status & Expectations](#project-status--expectations)
|
|
13
|
-
- [
|
|
15
|
+
- [License](#license)
|
|
14
16
|
|
|
15
|
-
**Note: 🚧 This project is
|
|
16
|
-
-
|
|
17
|
+
**Note: 🚧 This project is still early-stage and currently *Under Active Development* 🚧**
|
|
18
|
+
- All features listed in the [Features](#features) section are stable and assumed to be bug-free
|
|
19
|
+
- Native instrumentation prebuilds are available cross-platform
|
|
20
|
+
- Expect matchers are stable (except where noted below), with more coming soon
|
|
21
|
+
- See [Project Status & Expectations](#project-status--expectations) to see what's still planned!
|
|
17
22
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
## Quickstart
|
|
21
|
-
|
|
22
|
-
Coming Soon!
|
|
23
|
+
Please [report a bug / request a feature](https://github.com/themattspiral/vitest-pool-assemblyscript/issues/new) if you encounter something you'd like to share!
|
|
23
24
|
|
|
24
25
|
---
|
|
25
26
|
|
|
26
|
-
##
|
|
27
|
-
|
|
28
|
-
### Vitest Integration
|
|
29
|
-
- Use familiar `vitest` commands, CLI spec and test filtering, watch mode
|
|
30
|
-
- Works with Vitest UI, reporters, and coverage tools
|
|
31
|
-
- Project (workspace) config allows coexisting AssemblyScript pools and JavaScript pools
|
|
32
|
-
- Hybrid Coverage Provider unifies test reports from multiple pools (delegating to v8 for JS/TS coverage)
|
|
33
|
-
- Coverage reporting using any vitest reporter (`html`, `lcov`, `json`, etc)
|
|
34
|
-
- Dual vitest 3.x / 4.x support
|
|
35
|
-
|
|
36
|
-
### Per-Test WASM Isolation
|
|
37
|
-
- Each AssemblyScript test file is compiled to a WASM binary once
|
|
38
|
-
- Each test case runs in a fresh WASM instance (reusing the compiled binary)
|
|
39
|
-
- One crashing test doesn't kill the rest within the same suite
|
|
40
|
-
- `toThrowError()` matcher can be used to catch and expect specific errors (which trap and abort)
|
|
41
|
-
|
|
42
|
-
### Familiar Developer Experience
|
|
43
|
-
- Suite and test definition using `describe()` and `test()` in AssemblyScript
|
|
44
|
-
- Inline test option configuration for common vitest options: `timeout`, `retry`, `skip`, `only`, `fails`
|
|
45
|
-
- Assertion matching API based on vitest/jest `expect()` API. See [Matcher API](#matcher-api) for the set of supported matchers and differences from JavaScript
|
|
46
|
-
- Highlighted diffs for assertion and runtime failures, which point to source code
|
|
47
|
-
- Source-mapped WASM error stack traces (accurate source `function file:line:column`)
|
|
48
|
-
- AssemblyScript console output captured and provided to vitest for display
|
|
49
|
-
- No boilerplate patterns for: `run()`, `endTest()`, `fs.readFile`, `WebAssembly.Instance`, etc
|
|
50
|
-
|
|
51
|
-
### Performance & Customization
|
|
52
|
-
- Parallel execution thread pool
|
|
53
|
-
- Lightweight coverage instrumentation using separate memory
|
|
54
|
-
- In-memory binaries and source maps for minimal file I/O
|
|
55
|
-
- Coverage for inlined (`@inline`) code
|
|
56
|
-
- Enforced hard timeouts for long-running WASM via thread termination, with intelligent resume
|
|
57
|
-
- Configurable AssemblyScript compiler options
|
|
58
|
-
- Configurable test memory size
|
|
59
|
-
- Configurable WASM imports with access to memory
|
|
60
|
-
|
|
61
|
-
### Why This Over [Alternative]?
|
|
27
|
+
## Quick Start
|
|
62
28
|
|
|
63
|
-
|
|
64
|
-
- [assemblyscript-unittest-framework](https://github.com/wasm-ecosystem/assemblyscript-unittest-framework): A full-featured AS test framework
|
|
65
|
-
- Many thanks owed to this project for inspiring parts of our discovery and instrumentation approach
|
|
66
|
-
- [as-test](https://github.com/JairusSW/as-test): A minimal and fast AssemblyScript test framework and runner
|
|
67
|
-
- [Built with AssemblyScript - Testing & Benchmarking](https://www.assemblyscript.org/built-with-assemblyscript.html#testing-benchmarking) may track more
|
|
29
|
+
### 1. Install
|
|
68
30
|
|
|
69
|
-
|
|
31
|
+
```bash
|
|
32
|
+
npm install -D vitest vitest-pool-assemblyscript assemblyscript
|
|
33
|
+
```
|
|
70
34
|
|
|
71
|
-
|
|
35
|
+
### 2. Configure Vitest
|
|
72
36
|
|
|
73
|
-
|
|
74
|
-
- The `test` project configuration helpers needed depend on which version of vitest you're using.
|
|
75
|
-
- The `coverage` configuration is the same across versions (shown in the first example below).
|
|
37
|
+
Create or update `vitest.config.ts`. See the [Configuration Guide](docs/configuration-guide.md) for all supported vitest options, pool options, coverage configuration, and multi-project setups.
|
|
76
38
|
|
|
77
|
-
|
|
39
|
+
**vitest 4.x:**
|
|
78
40
|
```typescript
|
|
79
|
-
import { defineConfig
|
|
41
|
+
import { defineConfig } from 'vitest/config';
|
|
80
42
|
import { createAssemblyScriptPool } from 'vitest-pool-assemblyscript/config';
|
|
81
43
|
|
|
82
44
|
export default defineConfig({
|
|
83
45
|
test: {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
defineProject({
|
|
87
|
-
test: {
|
|
88
|
-
name: {
|
|
89
|
-
label: 'assemblyscript-tests',
|
|
90
|
-
color: 'yellow'
|
|
91
|
-
},
|
|
92
|
-
include: ['test/assembly/**/*.as.{test,spec}.ts'],
|
|
93
|
-
|
|
94
|
-
// supported vitest options
|
|
95
|
-
bail: 2, // stop test run after this many failures
|
|
96
|
-
retry: 0, // number of retries to attempt after initial failure
|
|
97
|
-
testTimeout: 500, // ms to wait before terminating test
|
|
98
|
-
// allowOnly: true, // whether or not to respect test.only and describe.only
|
|
99
|
-
// maxWorkers: 8, // concurrent file execution threads (default: available parallelism)
|
|
100
|
-
|
|
101
|
-
// configure vitest to use this custom pool for test files in `include`
|
|
102
|
-
pool: createAssemblyScriptPool({
|
|
103
|
-
stripInline: true, // true to remove @inline decorators for coverage (default: true)
|
|
104
|
-
testMemoryPagesInitial: 2, // initial WASM memory size in pages (default: 1)
|
|
105
|
-
testMemoryPagesMax: 4, // maximum WASM memory size in pages (default: undefined)
|
|
106
|
-
extraCompilerFlags: ['--runtime', 'incremental'], // additional asc flags to customize AS compilation
|
|
107
|
-
wasmImportsFactory: 'test-helpers/create-imports.js', // factory function to create your own WASM imports
|
|
108
|
-
}),
|
|
109
|
-
}
|
|
110
|
-
}),
|
|
111
|
-
|
|
112
|
-
// JavaScript/TypeScript project
|
|
113
|
-
defineProject({
|
|
114
|
-
test: {
|
|
115
|
-
name: {
|
|
116
|
-
label: 'javascript-typescript-tests',
|
|
117
|
-
color: 'blue'
|
|
118
|
-
},
|
|
119
|
-
include: ['test/js/*.{test,spec}.{ts,js}'],
|
|
120
|
-
}
|
|
121
|
-
}),
|
|
122
|
-
]
|
|
46
|
+
include: ['test/assembly/**/*.as.test.ts'],
|
|
47
|
+
pool: createAssemblyScriptPool(),
|
|
123
48
|
},
|
|
124
|
-
|
|
125
|
-
// Coverage config must be at root level (applies to all projects).
|
|
126
|
-
// The "hybrid" provider delegates JS to v8, and merges AS coverage into the final report
|
|
127
49
|
coverage: {
|
|
128
50
|
provider: 'custom',
|
|
129
51
|
customProviderModule: 'vitest-pool-assemblyscript/coverage',
|
|
130
|
-
assemblyScriptInclude: ['assembly/**/*.ts'],
|
|
131
|
-
assemblyScriptExclude: ['assembly/helpers/*.ts'], // example, exclude AS sources from reporting
|
|
132
|
-
|
|
133
|
-
// all other v8 coverage options will be passed through to delegated v8 provider
|
|
52
|
+
assemblyScriptInclude: ['assembly/**/*.ts'],
|
|
134
53
|
enabled: true,
|
|
135
|
-
cleanOnRerun: true,
|
|
136
|
-
reportsDirectory: './coverage',
|
|
137
|
-
reporter: ['text', 'lcov', 'html'],
|
|
138
|
-
include: ['src/**/*.ts'], // example, include JS/TS sources to report on
|
|
139
54
|
},
|
|
140
55
|
});
|
|
141
56
|
```
|
|
142
57
|
|
|
143
|
-
|
|
58
|
+
**vitest 3.x:**
|
|
144
59
|
```typescript
|
|
145
|
-
import {
|
|
146
|
-
import { createAssemblyScriptPool } from 'vitest-pool-assemblyscript/config';
|
|
60
|
+
import { defineAssemblyScriptConfig } from 'vitest-pool-assemblyscript/v3/config';
|
|
147
61
|
|
|
148
|
-
export default
|
|
62
|
+
export default defineAssemblyScriptConfig({
|
|
149
63
|
test: {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
}),
|
|
64
|
+
include: ['test/assembly/**/*.as.test.ts'],
|
|
65
|
+
pool: 'vitest-pool-assemblyscript/v3',
|
|
153
66
|
},
|
|
154
|
-
coverage
|
|
155
|
-
// no change to available options
|
|
156
|
-
}
|
|
67
|
+
// coverage configuration mirrors v4
|
|
157
68
|
});
|
|
158
69
|
```
|
|
159
70
|
|
|
160
|
-
###
|
|
71
|
+
### 3. Write a Test
|
|
72
|
+
|
|
73
|
+
Create a test file (e.g. `test/assembly/example-file.as.test.ts`):
|
|
74
|
+
|
|
161
75
|
```typescript
|
|
162
|
-
import {
|
|
163
|
-
import { defineAssemblyScriptProject } from 'vitest-pool-assemblyscript/v3/config';
|
|
76
|
+
import { test, describe, expect } from "vitest-pool-assemblyscript/assembly";
|
|
164
77
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
test: {
|
|
175
|
-
// AS project config... (standard name/label, include, etc)
|
|
176
|
-
|
|
177
|
-
pool: 'vitest-pool-assemblyscript/v3', // in v3, point to the module
|
|
178
|
-
poolOptions: {
|
|
179
|
-
assemblyScript: {
|
|
180
|
-
// same available options as v4 createAssemblyScriptPool are passed here
|
|
181
|
-
|
|
182
|
-
// Additonal - v3 Only
|
|
183
|
-
// maxThreadsV3: 8 // concurrent test file threads to execute (default: availableParallelism - 1)
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
})
|
|
188
|
-
]
|
|
189
|
-
},
|
|
190
|
-
|
|
78
|
+
test("basic math", () => {
|
|
79
|
+
expect(2 + 2).toBe(4);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
describe("an example suite", () => {
|
|
83
|
+
test("string equality", () => {
|
|
84
|
+
expect("hello").toBe("hello");
|
|
85
|
+
expect("hello").not.toBe("world");
|
|
86
|
+
});
|
|
191
87
|
});
|
|
192
88
|
```
|
|
193
89
|
|
|
194
|
-
###
|
|
195
|
-
```typescript
|
|
196
|
-
import { defineAssemblyScriptConfig } from 'vitest-pool-assemblyscript/v3/config';
|
|
90
|
+
### 4. Run
|
|
197
91
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
pool: 'vitest-pool-assemblyscript/v3',
|
|
201
|
-
poolOptions: {
|
|
202
|
-
assemblyScript: {
|
|
203
|
-
// same available options as v4 createAssemblyScriptPool and v3 multi-project
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
},
|
|
207
|
-
});
|
|
92
|
+
```bash
|
|
93
|
+
npx vitest run
|
|
208
94
|
```
|
|
209
95
|
|
|
210
|
-
|
|
96
|
+
---
|
|
211
97
|
|
|
212
|
-
|
|
213
|
-
The pool provides the full implementation of the [AssemblyScript `console` interface](https://www.assemblyscript.org/stdlib/console.html). This means you can transparently use `console.log("some string")` in your tests, and the output will be fed to vitest and displayed with the test results.
|
|
98
|
+
## Compatibility
|
|
214
99
|
|
|
215
|
-
|
|
100
|
+
| Dependency | Supported Versions |
|
|
101
|
+
|---|---|
|
|
102
|
+
| Node.js | 20, 22, 24+ |
|
|
103
|
+
| Vitest | 3.2.x, 4.x |
|
|
104
|
+
| AssemblyScript | 0.28+ |
|
|
216
105
|
|
|
217
|
-
|
|
218
|
-
The pool also provides an implementation for `trace`, which passes through to Node `console.trace()` immediately for debugging.
|
|
106
|
+
**Platforms with prebuilt native binaries:**
|
|
219
107
|
|
|
220
|
-
|
|
221
|
-
|
|
108
|
+
| | x64 | arm64 |
|
|
109
|
+
|---|---|---|
|
|
110
|
+
| Linux (glibc) | ✓ | ✓ |
|
|
111
|
+
| Linux (musl/Alpine) | ✓ | |
|
|
112
|
+
| macOS | ✓ | ✓ |
|
|
113
|
+
| Windows | ✓ | ✓ |
|
|
222
114
|
|
|
115
|
+
---
|
|
223
116
|
|
|
224
|
-
|
|
225
|
-
To provide your own WebAssembly imports, configure `wasmImportsFactory` to point to an ES module which exports a factory function to create your imports:
|
|
226
|
-
```typescript
|
|
227
|
-
// v4
|
|
228
|
-
// ...
|
|
229
|
-
pool: createAssemblyScriptPool({
|
|
230
|
-
wasmImportsFactory: 'test-helpers/create-imports.js',
|
|
231
|
-
})
|
|
232
|
-
// ...
|
|
233
|
-
|
|
234
|
-
// v3
|
|
235
|
-
// ...
|
|
236
|
-
poolOptions: {
|
|
237
|
-
assemblyScript: {
|
|
238
|
-
wasmImportsFactory: 'test-helpers/create-imports.js',
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
// ...
|
|
242
|
-
```
|
|
117
|
+
## Features
|
|
243
118
|
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
119
|
+
### Vitest Integration
|
|
120
|
+
- Use familiar `vitest` commands, CLI spec and test filtering, watch mode
|
|
121
|
+
- Works with Vitest UI, reporters, and coverage tools
|
|
122
|
+
- Project (workspace) config allows coexisting AssemblyScript pools and JavaScript pools
|
|
123
|
+
- Hybrid Coverage Provider unifies test reports from multiple pools (delegating to v8 for JS/TS coverage)
|
|
124
|
+
- Coverage reporting using any vitest reporter (`html`, `lcov`, `json`, etc)
|
|
125
|
+
- Dual vitest 3.x / 4.x support
|
|
248
126
|
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
utils: {
|
|
255
|
-
// convenience function for extracting returned strings from WASM memory
|
|
256
|
-
liftString: (stringPtr: number) => string | undefined;
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
```
|
|
127
|
+
### Per-Test WASM Isolation
|
|
128
|
+
- Each AssemblyScript test file is compiled to a WASM binary once
|
|
129
|
+
- Each test case runs in a fresh WASM instance (reusing the compiled binary)
|
|
130
|
+
- One crashing test doesn't kill the rest within the same suite
|
|
131
|
+
- `toThrowError()` matcher can be used to catch and expect specific errors (which trap and abort)
|
|
260
132
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
}
|
|
270
|
-
};
|
|
271
|
-
}
|
|
272
|
-
```
|
|
133
|
+
### Familiar Developer Experience
|
|
134
|
+
- Suite and test definition using `describe()` and `test()` in AssemblyScript
|
|
135
|
+
- Inline test option configuration for common vitest options: `timeout`, `retry`, `skip`, `only`, `fails`
|
|
136
|
+
- Assertion matching API based on vitest/jest `expect()` API. See [Matcher API](#matcher-api) for the set of supported matchers and differences from JavaScript
|
|
137
|
+
- Highlighted diffs for assertion and runtime failures, which point to source code
|
|
138
|
+
- Source-mapped WASM error stack traces (accurate source `function file:line:column`)
|
|
139
|
+
- AssemblyScript console output captured and provided to vitest for display
|
|
140
|
+
- No boilerplate patterns for: `run()`, `endTest()`, `fs.readFile`, `WebAssembly.Instance`, etc
|
|
273
141
|
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
142
|
+
### Performance & Customization
|
|
143
|
+
- Parallel execution thread pool
|
|
144
|
+
- Lightweight coverage instrumentation using separate memory
|
|
145
|
+
- In-memory binaries and source maps for minimal file I/O
|
|
146
|
+
- Coverage for inlined (`@inline`) code
|
|
147
|
+
- Enforced hard timeouts for long-running WASM via thread termination, with intelligent resume
|
|
148
|
+
- Configurable AssemblyScript compiler options
|
|
149
|
+
- Configurable test memory size
|
|
150
|
+
- Configurable WASM imports with access to memory
|
|
278
151
|
|
|
279
|
-
|
|
280
|
-
return parseIntStringFunction(input);
|
|
281
|
-
}
|
|
282
|
-
```
|
|
152
|
+
---
|
|
283
153
|
|
|
284
|
-
|
|
285
|
-
If you omit the module name in `@external` (e.g. `@external("parseIntStringFunction")`) or omit `@external` entirely, AssemblyScript uses the source file's own name (without the last file extension) as the module name, making it impractical to provide matching imports to every source file independently if you use imported functions across multiple places in your source. It is recommended to always specify a shared module name (such as "env") for this reason.
|
|
286
|
-
|
|
287
|
-
Conversely, if you need to provide imports targeted to a specific source file, this behavior provides a way to do that as well. For example, if you have a source AS file called `my-file.as.ts` with `declare function myFunc(input: string): i32;` in it and omit the `@external` decorator, then you can import the function *only to this file* with:
|
|
288
|
-
```js
|
|
289
|
-
export default function createWasmImports({ utils }) {
|
|
290
|
-
return {
|
|
291
|
-
// default source file module name (omits the .ts extension)
|
|
292
|
-
'my-file.as': {
|
|
293
|
-
myFunc: (inputStrPtr) => {
|
|
294
|
-
return parseInt(utils.liftString(inputStrPtr));
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
};
|
|
298
|
-
}
|
|
299
|
-
```
|
|
154
|
+
See also: **[Configuration Guide](docs/configuration-guide.md)** | **[Providing WASM Imports](docs/providing-wasm-imports.md)**
|
|
300
155
|
|
|
301
156
|
---
|
|
302
157
|
|
|
303
|
-
## Writing Tests
|
|
158
|
+
## Writing Tests Guide
|
|
304
159
|
|
|
305
160
|
Import `test`, `describe`, `expect` (and `TestOptions` if needed) from `vitest-pool-assemblyscript/assembly`.
|
|
306
161
|
|
|
@@ -372,6 +227,10 @@ test.fails("expected failure with retry", TestOptions.retry(3), () => {
|
|
|
372
227
|
});
|
|
373
228
|
```
|
|
374
229
|
|
|
230
|
+
### Lifecycle Hooks (Setup & Teardown)
|
|
231
|
+
|
|
232
|
+
Coming Soon!
|
|
233
|
+
|
|
375
234
|
---
|
|
376
235
|
|
|
377
236
|
## Matcher API
|
|
@@ -503,13 +362,12 @@ expect(() => { throw new Error("boom"); }).toThrowError("boom");
|
|
|
503
362
|
|
|
504
363
|
## Project Status & Expectations
|
|
505
364
|
|
|
506
|
-
**This is
|
|
507
|
-
|
|
508
|
-
|
|
365
|
+
**This is an early-stage project** being developed in the open by an interested individual with a career of experience shipping production code.
|
|
366
|
+
- All features listed in the [Features](#features) section are stable and assumed to be bug-free
|
|
367
|
+
- Native instrumentation prebuilds are available cross-platform
|
|
368
|
+
- Expect matchers are stable (except where noted above), with more coming soon
|
|
509
369
|
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
All features listed in the [Features](#features) section are working and assumed to be bug-free. Please [report a bug](https://github.com/themattspiral/vitest-pool-assemblyscript/issues/new) if you encounter one.
|
|
370
|
+
Please [report a bug / request a feature](https://github.com/themattspiral/vitest-pool-assemblyscript/issues/new) if you encounter something you'd like to share!
|
|
513
371
|
|
|
514
372
|
**⚠️ Known Limitations - Coming Soon:**
|
|
515
373
|
- **Function-level coverage only**: No statement, branch, or line coverage yet
|
|
@@ -540,82 +398,24 @@ All features listed in the [Features](#features) section are working and assumed
|
|
|
540
398
|
- TBD
|
|
541
399
|
|
|
542
400
|
**✖️ Out of Scope (Currently):**
|
|
543
|
-
- Compiler integration with other compile-to-WASM languages (Rust, C++)
|
|
544
|
-
- I would LOVE to expand this project to a more generic wasm pool, supporting pluggable compilers and ast parsing for different WASM ecosystems and toolchains
|
|
545
|
-
- Not in scope now because of time and effort. If you want to pay me to work on this [get in touch](https://github.com/themattspiral)!
|
|
546
401
|
- Generic JS-harness testing of any precompiled WASM binary
|
|
402
|
+
- Compiler & matcher integration with other compile-to-WASM languages (e.g. Rust and C++ with Emscripten)
|
|
403
|
+
- I would LOVE to expand this project to cover additional cases, supporting pluggable compilers, ast parsing, and matchers for different WASM ecosystems and toolchains
|
|
404
|
+
- Not in scope now because of time and effort
|
|
405
|
+
- If you want to pay me to work on this, please [get in touch](https://github.com/themattspiral)!
|
|
547
406
|
|
|
548
407
|
---
|
|
549
408
|
|
|
550
|
-
##
|
|
551
|
-
|
|
552
|
-
**⚠️ Important:** This project is under active development. Features and APIs may change without notice. No guarantees are made about stability or functionality.
|
|
409
|
+
## Prior Work
|
|
553
410
|
|
|
554
|
-
|
|
411
|
+
There are other (standalone) testing frameworks for AssemblyScript testing which have inspired this project. In particular, many thanks are owed to [assemblyscript-unittest-framework](https://github.com/wasm-ecosystem/assemblyscript-unittest-framework) for inspiring parts of our test discovery and instrumentation walking approaches.
|
|
555
412
|
|
|
556
|
-
|
|
557
|
-
- Node.js 20.0.0+ (required due to our multi-memory coverage approach)
|
|
558
|
-
- Vitest 3.2.0+ or 4.0.0+
|
|
559
|
-
- AssemblyScript 0.28+
|
|
560
|
-
- C++ build tools (dev only - distributed package will include prebuilds):
|
|
561
|
-
- GCC 7+ or Clang 5+ (C++17 support required)
|
|
562
|
-
- Python 3.x (required by node-gyp)
|
|
563
|
-
|
|
564
|
-
### Setup
|
|
565
|
-
|
|
566
|
-
1. **Clone the repository:**
|
|
567
|
-
```bash
|
|
568
|
-
git clone https://github.com/themattspiral/vitest-pool-assemblyscript.git
|
|
569
|
-
cd vitest-pool-assemblyscript
|
|
570
|
-
```
|
|
571
|
-
|
|
572
|
-
2. **Install Binaryen C++ dependencies, then npm deps**
|
|
573
|
-
```bash
|
|
574
|
-
npm run setup-binaryen
|
|
575
|
-
npm install
|
|
576
|
-
```
|
|
577
|
-
The `setup-binaryen` script downloads prebuilt Binaryen libraries and C++ headers to `third_party/binaryen/`. These are used to build the native addon that extracts debug info from WASM binaries.
|
|
578
|
-
|
|
579
|
-
3. **Build Native Addon**
|
|
580
|
-
```bash
|
|
581
|
-
npm run build:native
|
|
582
|
-
```
|
|
583
|
-
|
|
584
|
-
4. **Build Pool**
|
|
585
|
-
```bash
|
|
586
|
-
npm run build
|
|
587
|
-
```
|
|
588
|
-
|
|
589
|
-
5. **Link the pool to your project:**
|
|
590
|
-
```bash
|
|
591
|
-
# In vitest-pool-assemblyscript:
|
|
592
|
-
npm link
|
|
593
|
-
|
|
594
|
-
# In your project directory:
|
|
595
|
-
npm link vitest-pool-assemblyscript
|
|
596
|
-
```
|
|
597
|
-
|
|
598
|
-
6. **Configure Vitest**
|
|
599
|
-
|
|
600
|
-
See the [Configuration](#configuration) section.
|
|
601
|
-
|
|
602
|
-
7. **Write your tests**
|
|
603
|
-
See the [Writing Tests](#writing-tests) section.
|
|
604
|
-
|
|
605
|
-
8. **Run your tests:**
|
|
606
|
-
```bash
|
|
607
|
-
# Run all tests once
|
|
608
|
-
npx vitest run
|
|
609
|
-
|
|
610
|
-
# Run specific test file
|
|
611
|
-
npx vitest run example.as.test.ts
|
|
612
|
-
|
|
613
|
-
# Run specific test in specific file
|
|
614
|
-
npx vitest run example.as.test.ts -t "my test name"
|
|
615
|
-
```
|
|
413
|
+
See [Built with AssemblyScript - Testing & Benchmarking](https://www.assemblyscript.org/built-with-assemblyscript.html#testing-benchmarking) for other related work.
|
|
616
414
|
|
|
617
415
|
---
|
|
618
416
|
|
|
619
417
|
## License
|
|
620
418
|
|
|
621
419
|
[MIT](LICENSE)
|
|
420
|
+
- Portions of this software have been derived from third-party works which are licenced under different terms. Individual code contributions have been noted where applicable and are accompanied by their respective licenses.
|
|
421
|
+
- See the license file and source code for details
|
package/binding.gyp
CHANGED
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"-lpthread"
|
|
28
28
|
],
|
|
29
29
|
# Enable C++ exceptions (node-gyp disables them by default)
|
|
30
|
-
"cflags_cc": ["-std=c++
|
|
30
|
+
"cflags_cc": ["-std=c++20", "-fexceptions", "-O3"],
|
|
31
31
|
"cflags!": ["-fno-exceptions"],
|
|
32
32
|
"cflags_cc!": ["-fno-exceptions"]
|
|
33
33
|
}],
|
|
@@ -38,9 +38,9 @@
|
|
|
38
38
|
"xcode_settings": {
|
|
39
39
|
"GCC_ENABLE_CPP_EXCEPTIONS": "YES",
|
|
40
40
|
"CLANG_CXX_LIBRARY": "libc++",
|
|
41
|
-
# Minimum macOS deployment target for C++
|
|
41
|
+
# Minimum macOS deployment target for C++20 support
|
|
42
42
|
"MACOSX_DEPLOYMENT_TARGET": "10.15",
|
|
43
|
-
"OTHER_CPLUSPLUSFLAGS": ["-std=c++
|
|
43
|
+
"OTHER_CPLUSPLUSFLAGS": ["-std=c++20", "-fexceptions", "-O3"]
|
|
44
44
|
}
|
|
45
45
|
}],
|
|
46
46
|
["OS=='win'", {
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"VCCLCompilerTool": {
|
|
53
53
|
# Enable C++ exception handling (/EHsc)
|
|
54
54
|
"ExceptionHandling": 1,
|
|
55
|
-
"AdditionalOptions": ["/std:c++
|
|
55
|
+
"AdditionalOptions": ["/std:c++20"]
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
}]
|
|
@@ -2,7 +2,7 @@ import { POOL_ERROR_NAMES, POOL_INTERNAL_PATHS } from "./constants-CA50WBdr.mjs"
|
|
|
2
2
|
import { createPoolErrorFromAnyError, debug, getTestErrorFromPoolError } from "./debug-IeEHsxy0.mjs";
|
|
3
3
|
import { failFile, getFullTaskHierarchy, prepareFileTaskForCollection } from "./vitest-file-tasks-BUwzh375.mjs";
|
|
4
4
|
import { getTaskLogLabel, getTaskLogPrefix } from "./vitest-tasks-BKS7689f.mjs";
|
|
5
|
-
import { executeWASMDiscovery, flushRpcUpdates, reportFileCollected, reportFileError, reportFileQueued, reportUserConsoleLogs } from "./load-user-imports-
|
|
5
|
+
import { executeWASMDiscovery, flushRpcUpdates, reportFileCollected, reportFileError, reportFileQueued, reportUserConsoleLogs } from "./load-user-imports-Bbmpaciu.mjs";
|
|
6
6
|
import { compileAssemblyScript } from "./compiler-CN6BRK_N.mjs";
|
|
7
7
|
import { basename, relative } from "node:path";
|
|
8
8
|
|
|
@@ -77,4 +77,4 @@ async function runCompileAndDiscover(file, logModule, rpc, poolOptions, projectR
|
|
|
77
77
|
|
|
78
78
|
//#endregion
|
|
79
79
|
export { runCompileAndDiscover };
|
|
80
|
-
//# sourceMappingURL=compile-runner-
|
|
80
|
+
//# sourceMappingURL=compile-runner-xGvQwgNf.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compile-runner-
|
|
1
|
+
{"version":3,"file":"compile-runner-xGvQwgNf.mjs","names":[],"sources":["../src/pool-thread/runner/compile-runner.ts"],"sourcesContent":["/**\n * Worker thread test runner logic for AssemblyScript Pool\n */\n\nimport { basename, relative } from 'node:path';\nimport type { File } from '@vitest/runner/types';\nimport type { SerializedDiffOptions } from '@vitest/utils/diff';\n\nimport type {\n AssemblyScriptCompilerOptions,\n AssemblyScriptConsoleLog,\n AssemblyScriptConsoleLogHandler,\n InstrumentationOptions,\n ResolvedAssemblyScriptPoolOptions,\n ThreadImports,\n WASMCompilation,\n WorkerRPC,\n} from '../../types/types.js';\nimport {\n ASSEMBLYSCRIPT_LIB_PREFIX,\n POOL_ERROR_NAMES,\n POOL_INTERNAL_PATHS,\n} from '../../types/constants.js';\nimport { executeWASMDiscovery } from '../../wasm-executor/index.js';\nimport { debug } from '../../util/debug.js';\nimport {\n reportFileQueued,\n reportFileCollected,\n reportUserConsoleLogs,\n flushRpcUpdates,\n reportFileError,\n} from '../rpc-reporter.js';\nimport { createPoolErrorFromAnyError, getTestErrorFromPoolError } from '../../util/pool-errors.js';\nimport { compileAssemblyScript } from '../../compiler/index.js';\nimport {\n getTaskLogLabel,\n getTaskLogPrefix,\n} from '../../util/vitest-tasks.js';\nimport {\n failFile,\n getFullTaskHierarchy,\n prepareFileTaskForCollection,\n} from '../../util/vitest-file-tasks.js';\n\nlet threadCompilationCount: number = 0;\n\nexport async function runCompileAndDiscover(\n file: File,\n logModule: string,\n rpc: WorkerRPC,\n poolOptions: ResolvedAssemblyScriptPoolOptions,\n projectRoot: string,\n collectCoverage: boolean,\n relativeUserCoverageExclusions: string[],\n threadImports: ThreadImports,\n diffOptions?: SerializedDiffOptions,\n testNamePattern?: RegExp,\n allowOnly?: boolean,\n): Promise<WASMCompilation | undefined> {\n const base = basename(file.filepath);\n const fileLogPrefix = getTaskLogPrefix(logModule, base, file);\n const fileLogLabel = getTaskLogLabel(base, file);\n\n debug(`${fileLogPrefix} - Beginning runCompileAndDiscover for \"${file.filepath}\" at ${Date.now()}`);\n\n const runStart = performance.now();\n let compilation: WASMCompilation | undefined;\n\n try {\n await reportFileQueued(rpc, file, logModule, fileLogLabel);\n\n // TODO - move to options helpers\n const relativeTestFilePath = relative(projectRoot, file.filepath);\n const instrumentationOptions: InstrumentationOptions = {\n relativeExcludedFiles: [\n relativeTestFilePath,\n ...POOL_INTERNAL_PATHS,\n ...relativeUserCoverageExclusions,\n ],\n excludedLibraryFilePrefix: ASSEMBLYSCRIPT_LIB_PREFIX,\n coverageMemoryPagesMin: poolOptions.coverageMemoryPagesInitial,\n coverageMemoryPagesMax: poolOptions.coverageMemoryPagesMax,\n };\n const compilerOptions: AssemblyScriptCompilerOptions = {\n stripInline: poolOptions.stripInline,\n projectRoot: projectRoot,\n shouldInstrument: collectCoverage,\n instrumentationOptions,\n extraFlags: poolOptions.extraCompilerFlags\n };\n\n const { binary, sourceMap, debugInfo, compileTiming } = await compileAssemblyScript(\n file.filepath,\n compilerOptions,\n logModule,\n fileLogLabel\n );\n file.setupDuration = compileTiming;\n threadCompilationCount++;\n\n debug(`${fileLogPrefix} - TIMING compileAssemblyScript total `\n + `(thread comp # ${threadCompilationCount}): ${compileTiming.toFixed(2)} ms`\n );\n \n const logMessages: AssemblyScriptConsoleLog[] = [];\n const handleLog: AssemblyScriptConsoleLogHandler = (msg: string, isError: boolean = false): void => {\n logMessages.push({ msg, time: Date.now(), isError });\n };\n \n const discoverStart = performance.now();\n\n await executeWASMDiscovery(\n binary,\n sourceMap,\n base,\n poolOptions,\n collectCoverage,\n handleLog,\n file,\n logModule,\n threadImports,\n diffOptions\n );\n\n // set skips when using only and/or user test name pattern, skip file task if all tests skipped\n prepareFileTaskForCollection(file, testNamePattern, allowOnly);\n\n file.collectDuration = performance.now() - discoverStart;\n debug(`${fileLogPrefix} - TIMING Discovery Phase: ${file.collectDuration.toFixed(2)} ms`);\n\n // vitest collect - report discovery results\n await Promise.all([\n // Report user console logs\n reportUserConsoleLogs(rpc, logMessages, logModule, base, file),\n\n // Report onCollected with collected and filtered tasks\n reportFileCollected(rpc, file, logModule, fileLogLabel),\n ]);\n\n debug(() => `${fileLogPrefix} - Collected Test Suite Hierarchy:\\n${getFullTaskHierarchy(file)}`);\n\n const totalTime = performance.now() - runStart;\n debug(`${fileLogPrefix} - TIMING Compilation and Discovery: ${totalTime.toFixed(2)} ms`);\n\n compilation = {\n filePath: file.filepath,\n binary,\n sourceMap,\n debugInfo,\n };\n } catch (error) {\n const poolError = createPoolErrorFromAnyError(\n `${fileLogLabel} - runCompileAndDiscover failure in worker`,\n POOL_ERROR_NAMES.WASMExecutionHarnessError,\n error\n );\n const testError = getTestErrorFromPoolError(poolError);\n\n failFile(file, testError, runStart);\n\n await reportFileQueued(rpc, file, logModule, fileLogLabel);\n await reportFileError(rpc, file, logModule, fileLogLabel);\n\n debug(`${fileLogPrefix} - Reported file error`);\n } finally {\n await flushRpcUpdates(rpc);\n debug(`${fileLogPrefix} - runCompileAndDiscover Completed`);\n }\n\n return compilation;\n}\n"],"mappings":";;;;;;;;;;;;AA4CA,IAAI,yBAAiC;AAErC,eAAsB,sBACpB,MACA,WACA,KACA,aACA,aACA,iBACA,gCACA,eACA,aACA,iBACA,WACsC;CACtC,MAAM,OAAO,SAAS,KAAK,SAAS;CACpC,MAAM,gBAAgB,iBAAiB,WAAW,MAAM,KAAK;CAC7D,MAAM,eAAe,gBAAgB,MAAM,KAAK;AAEhD,OAAM,GAAG,cAAc,0CAA0C,KAAK,SAAS,OAAO,KAAK,KAAK,GAAG;CAEnG,MAAM,WAAW,YAAY,KAAK;CAClC,IAAI;AAEJ,KAAI;AACF,QAAM,iBAAiB,KAAK,MAAM,WAAW,aAAa;EAI1D,MAAM,yBAAiD;GACrD,uBAAuB;IAFI,SAAS,aAAa,KAAK,SAAS;IAI7D,GAAG;IACH,GAAG;IACJ;GACD;GACA,wBAAwB,YAAY;GACpC,wBAAwB,YAAY;GACrC;EACD,MAAM,kBAAiD;GACrD,aAAa,YAAY;GACZ;GACb,kBAAkB;GAClB;GACA,YAAY,YAAY;GACzB;EAED,MAAM,EAAE,QAAQ,WAAW,WAAW,kBAAkB,MAAM,sBAC5D,KAAK,UACL,iBACA,WACA,aACD;AACD,OAAK,gBAAgB;AACrB;AAEA,QAAM,GAAG,cAAc,uDACD,uBAAuB,KAAK,cAAc,QAAQ,EAAE,CAAC,KAC1E;EAED,MAAM,cAA0C,EAAE;EAClD,MAAM,aAA8C,KAAa,UAAmB,UAAgB;AAClG,eAAY,KAAK;IAAE;IAAK,MAAM,KAAK,KAAK;IAAE;IAAS,CAAC;;EAGtD,MAAM,gBAAgB,YAAY,KAAK;AAEvC,QAAM,qBACJ,QACA,WACA,MACA,aACA,iBACA,WACA,MACA,WACA,eACA,YACD;AAGD,+BAA6B,MAAM,iBAAiB,UAAU;AAE9D,OAAK,kBAAkB,YAAY,KAAK,GAAG;AAC3C,QAAM,GAAG,cAAc,6BAA6B,KAAK,gBAAgB,QAAQ,EAAE,CAAC,KAAK;AAGzF,QAAM,QAAQ,IAAI,CAEhB,sBAAsB,KAAK,aAAa,WAAW,MAAM,KAAK,EAG9D,oBAAoB,KAAK,MAAM,WAAW,aAAa,CACxD,CAAC;AAEF,cAAY,GAAG,cAAc,sCAAsC,qBAAqB,KAAK,GAAG;AAGhG,QAAM,GAAG,cAAc,wCADL,YAAY,KAAK,GAAG,UACkC,QAAQ,EAAE,CAAC,KAAK;AAExF,gBAAc;GACZ,UAAU,KAAK;GACf;GACA;GACA;GACD;UACM,OAAO;AAQd,WAAS,MAFS,0BALA,4BAChB,GAAG,aAAa,6CAChB,iBAAiB,2BACjB,MACD,CACqD,EAE5B,SAAS;AAEnC,QAAM,iBAAiB,KAAK,MAAM,WAAW,aAAa;AAC1D,QAAM,gBAAgB,KAAK,MAAM,WAAW,aAAa;AAEzD,QAAM,GAAG,cAAc,wBAAwB;WACvC;AACR,QAAM,gBAAgB,IAAI;AAC1B,QAAM,GAAG,cAAc,oCAAoC;;AAG7D,QAAO"}
|
package/dist/config/index.mjs
CHANGED
|
@@ -3,6 +3,6 @@ import "../debug-IeEHsxy0.mjs";
|
|
|
3
3
|
import "../vitest-file-tasks-BUwzh375.mjs";
|
|
4
4
|
import "../vitest-tasks-BKS7689f.mjs";
|
|
5
5
|
import "../worker-rpc-channel-lbhK7Qz8.mjs";
|
|
6
|
-
import { createAssemblyScriptPool } from "../pool-runner-init-
|
|
6
|
+
import { createAssemblyScriptPool } from "../pool-runner-init-Kuzz61rB.mjs";
|
|
7
7
|
|
|
8
8
|
export { createAssemblyScriptPool };
|
|
@@ -6,7 +6,7 @@ import { ASTVisitor } from "../ast-visitor-DC3SuTzs.mjs";
|
|
|
6
6
|
import { basename, parse, relative } from "node:path";
|
|
7
7
|
import { readFile } from "node:fs/promises";
|
|
8
8
|
import v8CoverageModule from "@vitest/coverage-v8";
|
|
9
|
-
import
|
|
9
|
+
import istanbulCoverage from "istanbul-lib-coverage";
|
|
10
10
|
import { Parser } from "assemblyscript";
|
|
11
11
|
import { resolve as resolve$1 } from "path";
|
|
12
12
|
import TestExclude from "test-exclude";
|
|
@@ -355,6 +355,7 @@ function globFiles(include, exclude, projectRoot) {
|
|
|
355
355
|
* - Delegates JS coverage to Vitest's v8 provider
|
|
356
356
|
* - Merges both into a unified coverage report
|
|
357
357
|
*/
|
|
358
|
+
const { createCoverageMap } = istanbulCoverage;
|
|
358
359
|
var HybridCoverageProvider = class {
|
|
359
360
|
name = "hybrid-assemblyscript-v8";
|
|
360
361
|
v8Provider;
|