Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(bindings/ts): Test Wasm binding #9128

Merged
merged 3 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions bindings/binding_core_wasm/scripts/build_nodejs_release.sh

This file was deleted.

4 changes: 0 additions & 4 deletions bindings/binding_core_wasm/scripts/build_web_release.sh

This file was deleted.

40 changes: 40 additions & 0 deletions bindings/binding_typescript_wasm/__tests__/transform.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const swc = require("../pkg");

it("properly reports error", function () {
expect(() => {
swc.transformSync("Foo {}", {});
}).toThrow();
});

describe("trannsform", () => {
it("should strip types", async () => {
const { code } = await swc.transform(
`
export const foo: number = 1;
type Foo = number;
`,
{}
);
expect(code).toMatchInlineSnapshot(`
"export const foo = 1;
"
`);
});

it("should preserve enum", async () => {
const { code } = await swc.transform(
`
enum Foo {
Bar
}
`,
{}
);
await expect(code).toMatchInlineSnapshot(`
"enum Foo {
Bar
}
"
`);
});
});
1 change: 1 addition & 0 deletions bindings/binding_typescript_wasm/scripts/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
wasm-pack build --debug --scope swc -t nodejs --features getrandom/js $@
6 changes: 6 additions & 0 deletions bindings/binding_typescript_wasm/scripts/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

set -eu

./scripts/build.sh
npx jest $@
2 changes: 1 addition & 1 deletion bindings/binding_typescript_wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub fn transform(input: JsString, options: JsValue) -> Promise {
future_to_promise(async move { transform_sync(input, options) })
}

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

Expand Down
Loading