Skip to content

Commit 78db1d5

Browse files
test(jco): support WastDirective::AssertTrap
1 parent d9313d4 commit 78db1d5

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

crates/xtask/src/build/wast_fixtures.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ fn convert_wast_file(
3131
if (!args) {{ throw new Error('missing args'); }}
3232
if (!args.instance) {{ throw new Error('missing loaded wasm instance'); }}
3333
if (!args.assert) {{ throw new Error('missing assert obj'); }}
34-
const {{ instance, assert }} = args;
34+
if (!args.expect) {{ throw new Error('missing expect obj'); }}
35+
const {{ instance, assert, expect }} = args;
3536
let res;
3637
"#
3738
)?;
@@ -69,7 +70,16 @@ fn convert_wast_file(
6970
bail!("unsupported directive Register")
7071
}
7172
wast::WastDirective::Invoke(_) => bail!("unsupported directive Invoke"),
72-
wast::WastDirective::AssertTrap { .. } => bail!("unsupported directive AssertTrap"),
73+
wast::WastDirective::AssertTrap { exec, message, .. } => {
74+
let (export_name, args) = extract_export_fn(&exec)?;
75+
writeln!(
76+
output_js,
77+
r#"
78+
await expect(instance['{export_name}']({})).rejects.toThrow(/trap/, "expected trap with content like [{message}]");
79+
"#,
80+
args_to_js_params(args)?,
81+
)?;
82+
}
7383
wast::WastDirective::AssertReturn { exec, results, .. } => {
7484
ensure!(
7585
results.len() == 1,

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { join, relative, basename } from "node:path";
22
import { opendir } from "node:fs/promises";
33
import { spawn } from "node:child_process";
44

5-
import { suite, test, assert, beforeAll } from "vitest";
5+
import { suite, test, assert, expect, beforeAll } from "vitest";
66

77
import { COMPONENT_MODEL_FIXTURES_WAST_DIR } from "../../../common.js";
88
import { fileExists, setupAsyncTest } from "../../../helpers.js";
@@ -82,6 +82,7 @@ suite("component-model", async () => {
8282
await mod.runWastTest({
8383
instance,
8484
assert,
85+
expect,
8586
});
8687
} finally {
8788
await cleanup?.();

0 commit comments

Comments
 (0)