Skip to content

Commit 015e75d

Browse files
test(jco): add test setup & checks
1 parent 9bd393f commit 015e75d

1 file changed

Lines changed: 31 additions & 6 deletions

File tree

  • packages/jco/test/p3/ported/component-model

packages/jco/test/p3/ported/component-model/wast.js

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,50 @@
11
import { join, relative } from "node:path";
22
import { opendir } from "node:fs/promises";
3+
import { spawn } from "node:child_process";
34

4-
import { suite, test, assert } from "vitest";
5+
import { suite, test, assert, beforeAll } from "vitest";
56

6-
import { COMPONENT_MODEL_FIXTURES_WAST_DIR } from "../../../common.js";
7+
import { fileExists, COMPONENT_MODEL_FIXTURES_WAST_DIR } from "../../../common.js";
78

89
// These tests are ported from the component-model repo
910
//
1011
// see: https://github.com/WebAssembly/component-model/tree/main/test
1112
//
1213
suite("component-model", async () => {
1314
const walker = await opendir(COMPONENT_MODEL_FIXTURES_WAST_DIR, { recursive: true });
15+
const metadata = [];
1416
for await (const dirent of walker) {
1517
if (!dirent.isFile) {
1618
continue;
1719
}
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+
});
1942

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
2348
assert.strictEqual(true, true);
2449
});
2550
}

0 commit comments

Comments
 (0)