|
1 | 1 | import { join, relative } from "node:path"; |
2 | 2 | import { opendir } from "node:fs/promises"; |
| 3 | +import { spawn } from "node:child_process"; |
3 | 4 |
|
4 | | -import { suite, test, assert } from "vitest"; |
| 5 | +import { suite, test, assert, beforeAll } from "vitest"; |
5 | 6 |
|
6 | | -import { COMPONENT_MODEL_FIXTURES_WAST_DIR } from "../../../common.js"; |
| 7 | +import { fileExists, COMPONENT_MODEL_FIXTURES_WAST_DIR } from "../../../common.js"; |
7 | 8 |
|
8 | 9 | // These tests are ported from the component-model repo |
9 | 10 | // |
10 | 11 | // see: https://github.com/WebAssembly/component-model/tree/main/test |
11 | 12 | // |
12 | 13 | suite("component-model", async () => { |
13 | 14 | const walker = await opendir(COMPONENT_MODEL_FIXTURES_WAST_DIR, { recursive: true }); |
| 15 | + const metadata = []; |
14 | 16 | for await (const dirent of walker) { |
15 | 17 | if (!dirent.isFile) { |
16 | 18 | continue; |
17 | 19 | } |
18 | | - const relPath = relative(COMPONENT_MODEL_FIXTURES_WAST_DIR, join(dirent.parentPath, dirent.name)); |
| 20 | + const wastPath = join(dirent.parentPath, dirent.name); |
| 21 | + const wastRelPath = relative(COMPONENT_MODEL_FIXTURES_WAST_DIR, wastPath); |
| 22 | + const wasmPath = join(COMPONENT_MODEL_FIXTURES_WAST_DIR, `${dirent.name}.wasm`); |
| 23 | + const scriptPath = join(COMPONENT_MODEL_FIXTURES_WAST_DIR, `${dirent.name}.js`); |
| 24 | + metadata.push({ |
| 25 | + wastRelPath, |
| 26 | + wastPath, |
| 27 | + wasmPath, |
| 28 | + scriptPath, |
| 29 | + }); |
| 30 | + } |
| 31 | + |
| 32 | + beforeAll(async () => { |
| 33 | + for (const { wastPath } of metadata) { |
| 34 | + const fixtureBuild = spawn("cargo", ["xtask", "build-wast-fixture", wastPath], { |
| 35 | + detached: false, |
| 36 | + stdio: "pipe", |
| 37 | + shell: true, |
| 38 | + }); |
| 39 | + await new Promise(resolve => fixtureBuild.on("exit", resolve)); |
| 40 | + } |
| 41 | + }); |
19 | 42 |
|
20 | | - test.concurrent(relPath, async () => { |
21 | | - // TODO: convert WAST test to WAT + executable JS |
22 | | - console.log(`path [${relPath}]`); |
| 43 | + for (const { wastRelPath, wasmPath, scriptPath } of metadata) { |
| 44 | + test.concurrent(wastRelPath, async () => { |
| 45 | + assert(await fileExists(scriptPath), `missing generated script @ [${scriptPath}]`); |
| 46 | + assert(await fileExists(wasmPath), `missing generated wasm component @ [${wasmPath}]`); |
| 47 | + // TODO: convert WAST test to WAST + executable JS |
23 | 48 | assert.strictEqual(true, true); |
24 | 49 | }); |
25 | 50 | } |
|
0 commit comments