-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvitest.setup.ts
More file actions
29 lines (24 loc) · 1.05 KB
/
Copy pathvitest.setup.ts
File metadata and controls
29 lines (24 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/**
* WASM Test Setup: Loads Zig WASM modules for tests.
* Runs in Node.js context (vitest setupFiles).
*/
import { readFileSync, existsSync } from 'node:fs';
import { join } from 'node:path';
export default function setup() {
const wasmPath = join(process.cwd(), 'packages', 'core', 'dist', 'zig', 'dominator_core.wasm');
if (!existsSync(wasmPath)) {
console.warn('[dominator] WASM binary not found at', wasmPath, '— tests will fail without WASM backend');
return;
}
try {
const wasmBytes = readFileSync(wasmPath);
const module = new WebAssembly.Module(wasmBytes);
const memory = new WebAssembly.Memory({ initial: 1024, maximum: 8192 });
const instance = new WebAssembly.Instance(module, { env: { memory } });
// Place on globalThis so wasm-glue.ts getCore() finds it
(globalThis as any).__DOMINATOR_WASM_INSTANCE__ = instance;
(globalThis as any).__DOMINATOR_WASM_MEMORY__ = memory;
} catch (err) {
console.error('[dominator] Failed to load WASM:', err);
}
}