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

**Description:**

Now, the build pipeline is running, so I'll look into testing the Wasm binary.
This commit is contained in:
Donny/강동윤 2024-07-03 15:55:24 +09:00 committed by GitHub
parent 214535b848
commit c6d6db3661
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 48 additions and 9 deletions

View File

@ -1,4 +0,0 @@
#!/bin/bash
# run this script from the wasm folder ./scripts/build_nodejs_release.sh
npx wasm-pack build --scope swc -t nodejs --features plugin

View File

@ -1,4 +0,0 @@
#!/bin/bash
# run this script from the wasm folder ./scripts/build_web_release.sh
npx wasm-pack build --scope swc --features plugin

View File

@ -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
}
"
`);
});
});

View File

@ -0,0 +1 @@
wasm-pack build --debug --scope swc -t nodejs --features getrandom/js $@

View File

@ -0,0 +1,6 @@
#!/usr/bin/env bash
set -eu
./scripts/build.sh
npx jest $@

View File

@ -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)?;