Skip to content

Commit c6d6db3

Browse files
authored
test(bindings/ts): Test Wasm binding (#9128)
**Description:** Now, the build pipeline is running, so I'll look into testing the Wasm binary.
1 parent 214535b commit c6d6db3

File tree

6 files changed

+48
-9
lines changed

6 files changed

+48
-9
lines changed

bindings/binding_core_wasm/scripts/build_nodejs_release.sh

Lines changed: 0 additions & 4 deletions
This file was deleted.

bindings/binding_core_wasm/scripts/build_web_release.sh

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
const swc = require("../pkg");
2+
3+
it("properly reports error", function () {
4+
expect(() => {
5+
swc.transformSync("Foo {}", {});
6+
}).toThrow();
7+
});
8+
9+
describe("trannsform", () => {
10+
it("should strip types", async () => {
11+
const { code } = await swc.transform(
12+
`
13+
export const foo: number = 1;
14+
type Foo = number;
15+
`,
16+
{}
17+
);
18+
expect(code).toMatchInlineSnapshot(`
19+
"export const foo = 1;
20+
"
21+
`);
22+
});
23+
24+
it("should preserve enum", async () => {
25+
const { code } = await swc.transform(
26+
`
27+
enum Foo {
28+
Bar
29+
}
30+
`,
31+
{}
32+
);
33+
await expect(code).toMatchInlineSnapshot(`
34+
"enum Foo {
35+
Bar
36+
}
37+
"
38+
`);
39+
});
40+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
wasm-pack build --debug --scope swc -t nodejs --features getrandom/js $@
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env bash
2+
3+
set -eu
4+
5+
./scripts/build.sh
6+
npx jest $@

bindings/binding_typescript_wasm/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ pub fn transform(input: JsString, options: JsValue) -> Promise {
7272
future_to_promise(async move { transform_sync(input, options) })
7373
}
7474

75-
#[wasm_bindgen]
75+
#[wasm_bindgen(js_name = "transformSync")]
7676
pub fn transform_sync(input: JsString, options: JsValue) -> Result<JsValue, JsValue> {
7777
let options: Options = serde_wasm_bindgen::from_value(options)?;
7878

0 commit comments

Comments
 (0)