Skip to content

Commit 6920b07

Browse files
test(jco): add extended test suite for niche regression tests
This commit adds an extended test suites that uses components in `jco/test/components` to ensure Jco functionality is working properly. While most components that are tested with Jco are written in either JS or Rust, all other components (e.g. C++, Python) will be stored in `jco/test/components` and built/used from there by relevant tests.
1 parent 9c7b7a6 commit 6920b07

9 files changed

Lines changed: 60 additions & 14 deletions

File tree

packages/jco/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
"lint:fix": "oxlint --fix",
7272
"test": "vitest run -c test/vitest.ts",
7373
"test:lts": "vitest run -c test/vitest.lts.ts",
74+
"test:extended": "vitest run -c test/vitest.extended.ts",
7475
"prepack": "cargo xtask build release"
7576
},
7677
"dependencies": {

packages/jco/test/common.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ export const P3_COMPONENT_FIXTURES_DIR = join(COMPONENT_FIXTURES_DIR, "p3");
2929
/** Path to built custom rust components (i.e. output of `cargo xtask build-test-components`) */
3030
export const LOCAL_TEST_COMPONENTS_DIR = join(COMPONENT_FIXTURES_DIR, "../../output/rust-test-components");
3131

32+
/** Path to built extended test components (i.e. output of `just build` run in `jco/test/components`) */
33+
export const EXTENDED_TEST_COMPONENTS_DIR = fileURLToPath(new URL("../../../test/components/output", import.meta.url));
34+
3235
/**
3336
* Retrieve a list of all component fixtures
3437
*
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { join } from "node:path";
2+
3+
import { suite, test, assert } from "vitest";
4+
5+
import { exec, jcoPath, fileExists } from "../helpers.js";
6+
import { EXTENDED_TEST_COMPONENTS_DIR } from "../common.js";
7+
8+
suite("jco-issue-1380", () => {
9+
test("composed component runs", async () => {
10+
const combinedComponentPath = join(EXTENDED_TEST_COMPONENTS_DIR, "jco-issue-1380/composed.wasm");
11+
assert(await fileExists(combinedComponentPath), "built composed component must be in place");
12+
13+
const { stdout, stderr } = await exec(jcoPath, "run", combinedComponentPath);
14+
15+
assert.strictEqual(stdout, "");
16+
assert.strictEqual(stderr, "");
17+
});
18+
});

packages/jco/test/helpers.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,3 +662,9 @@ export async function getCurrentWitComponentVersion() {
662662
CURRENT_WIT_COMPONENT_VERSION = version;
663663
return CURRENT_WIT_COMPONENT_VERSION;
664664
}
665+
666+
export async function fileExists(p) {
667+
return stat(p)
668+
.then((f) => f.isFile())
669+
.catch(() => false);
670+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { availableParallelism } from "node:os";
2+
3+
import { defineConfig } from "vitest/config";
4+
5+
const DEFAULT_TIMEOUT_MS = 1000 * 60 * 1; // 60s
6+
const CI_DEFAULT_TIMEOUT_MS = 1000 * 60 * 3; // 1m
7+
8+
const REPORTERS = process.env.GITHUB_ACTIONS ? ["verbose", "github-actions"] : ["verbose"];
9+
const JSPI_EXEC_ARGV = "Suspending" in WebAssembly ? [] : ["--experimental-wasm-jspi"];
10+
11+
export default defineConfig({
12+
test: {
13+
reporters: REPORTERS,
14+
maxConcurrency: Math.max(availableParallelism() / 2, 5),
15+
disableConsoleIntercept: true,
16+
printConsoleTrace: true,
17+
passWithNoTests: false,
18+
setupFiles: ["test/meta-resolve-stub.ts"],
19+
include: ["test/extended/**/*.js"],
20+
testTimeout: process.env.CI ? CI_DEFAULT_TIMEOUT_MS : DEFAULT_TIMEOUT_MS,
21+
hookTimeout: process.env.CI ? CI_DEFAULT_TIMEOUT_MS : DEFAULT_TIMEOUT_MS,
22+
teardownTimeout: process.env.CI ? CI_DEFAULT_TIMEOUT_MS : DEFAULT_TIMEOUT_MS,
23+
pool: "forks",
24+
poolOptions: {
25+
forks: {
26+
execArgv: [...JSPI_EXEC_ARGV, "--stack-trace-limit=100"],
27+
},
28+
},
29+
},
30+
});

packages/jco/test/vitest.lts.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export default defineConfig({
2424
setupFiles: ["test/meta-resolve-stub.ts"],
2525
include: ["test/*.js"],
2626
exclude: [
27+
"test/extended/*",
2728
"test/output/*",
2829
"test/fixtures/*",
2930
"test/common.js",

packages/jco/test/vitest.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export default defineConfig({
1818
setupFiles: ["test/meta-resolve-stub.ts"],
1919
include: ["test/**/*.js"],
2020
exclude: [
21+
"test/extended/*",
2122
"test/output/*",
2223
"test/fixtures/*",
2324
"test/common.js",

test/components/cpp/jco-issue-1380/caller/component.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@
44
#include <iostream>
55

66
std::expected<void, wit::Void> exports::wasi::cli::run::Run() {
7-
std::cout << "[dbg] run: minimal begin" << std::endl;
87
auto h = ::test::jco_bug::iface::OpenTemp();
9-
std::cout << "[dbg] run: before append" << std::endl;
108
h.Append("|x|");
11-
std::cout << "[dbg] run: after append" << std::endl;
129
return {};
1310
}

test/components/python/jco-issue-1380/callee/component.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,21 @@ class Handle(iface.Handle):
1515
def __init__(self, path: str) -> None:
1616
self._path = path
1717
Handle._storage.setdefault(self._path, "")
18-
print(f"[dbg] py: Handle.__init__ path={self._path}")
1918

2019
def append(self, data: str) -> None:
21-
print(f"[dbg] py: Handle.append begin path={self._path} data={data}")
2220
Handle._storage[self._path] = Handle._storage.get(self._path, "") + data
23-
print(
24-
f"[dbg] py: Handle.append end path={self._path} size={len(Handle._storage[self._path])}"
25-
)
2621

2722

2823
class Iface(exports.Iface):
2924
def open_temp(self) -> Handle:
30-
print("[dbg] py: open_temp begin")
3125
Handle._seq += 1
3226
h = Handle(f"mem://h-{Handle._seq}")
33-
print(f"[dbg] py: open_temp end path={h._path}")
3427
return h
3528

3629

3730
class Run(exports.Run):
3831
def run(self) -> None:
39-
print("[dbg] py: run begin")
4032
api = Handle()
41-
print("[dbg] py: run open_temp")
4233
h = api.open_temp()
43-
print("[dbg] py: run append")
4434
h.append("|py-run|")
45-
print("[dbg] py: run end")
4635
return None

0 commit comments

Comments
 (0)