mirror of
https://github.com/swc-project/swc.git
synced 2024-11-22 06:46:41 +03:00
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:
parent
214535b848
commit
c6d6db3661
@ -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
|
@ -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
|
40
bindings/binding_typescript_wasm/__tests__/transform.js
Normal file
40
bindings/binding_typescript_wasm/__tests__/transform.js
Normal 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
|
||||
}
|
||||
"
|
||||
`);
|
||||
});
|
||||
});
|
1
bindings/binding_typescript_wasm/scripts/build.sh
Executable file
1
bindings/binding_typescript_wasm/scripts/build.sh
Executable file
@ -0,0 +1 @@
|
||||
wasm-pack build --debug --scope swc -t nodejs --features getrandom/js $@
|
6
bindings/binding_typescript_wasm/scripts/test.sh
Executable file
6
bindings/binding_typescript_wasm/scripts/test.sh
Executable file
@ -0,0 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -eu
|
||||
|
||||
./scripts/build.sh
|
||||
npx jest $@
|
@ -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)?;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user