From c6d6db3661ec93b9ebb8ca55ff88726f66b3d5e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Wed, 3 Jul 2024 15:55:24 +0900 Subject: [PATCH] test(bindings/ts): Test Wasm binding (#9128) **Description:** Now, the build pipeline is running, so I'll look into testing the Wasm binary. --- .../scripts/build_nodejs_release.sh | 4 -- .../scripts/build_web_release.sh | 4 -- .../__tests__/transform.js | 40 +++++++++++++++++++ .../binding_typescript_wasm/scripts/build.sh | 1 + .../binding_typescript_wasm/scripts/test.sh | 6 +++ bindings/binding_typescript_wasm/src/lib.rs | 2 +- 6 files changed, 48 insertions(+), 9 deletions(-) delete mode 100755 bindings/binding_core_wasm/scripts/build_nodejs_release.sh delete mode 100755 bindings/binding_core_wasm/scripts/build_web_release.sh create mode 100644 bindings/binding_typescript_wasm/__tests__/transform.js create mode 100755 bindings/binding_typescript_wasm/scripts/build.sh create mode 100755 bindings/binding_typescript_wasm/scripts/test.sh diff --git a/bindings/binding_core_wasm/scripts/build_nodejs_release.sh b/bindings/binding_core_wasm/scripts/build_nodejs_release.sh deleted file mode 100755 index 3bb0665c539c..000000000000 --- a/bindings/binding_core_wasm/scripts/build_nodejs_release.sh +++ /dev/null @@ -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 diff --git a/bindings/binding_core_wasm/scripts/build_web_release.sh b/bindings/binding_core_wasm/scripts/build_web_release.sh deleted file mode 100755 index b57746ecb289..000000000000 --- a/bindings/binding_core_wasm/scripts/build_web_release.sh +++ /dev/null @@ -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 diff --git a/bindings/binding_typescript_wasm/__tests__/transform.js b/bindings/binding_typescript_wasm/__tests__/transform.js new file mode 100644 index 000000000000..a20de8582026 --- /dev/null +++ b/bindings/binding_typescript_wasm/__tests__/transform.js @@ -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 + } + " + `); + }); +}); diff --git a/bindings/binding_typescript_wasm/scripts/build.sh b/bindings/binding_typescript_wasm/scripts/build.sh new file mode 100755 index 000000000000..84e9df918c60 --- /dev/null +++ b/bindings/binding_typescript_wasm/scripts/build.sh @@ -0,0 +1 @@ +wasm-pack build --debug --scope swc -t nodejs --features getrandom/js $@ diff --git a/bindings/binding_typescript_wasm/scripts/test.sh b/bindings/binding_typescript_wasm/scripts/test.sh new file mode 100755 index 000000000000..38d3522d0252 --- /dev/null +++ b/bindings/binding_typescript_wasm/scripts/test.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +set -eu + +./scripts/build.sh +npx jest $@ \ No newline at end of file diff --git a/bindings/binding_typescript_wasm/src/lib.rs b/bindings/binding_typescript_wasm/src/lib.rs index 21fb9bcd4115..f580a9e44451 100644 --- a/bindings/binding_typescript_wasm/src/lib.rs +++ b/bindings/binding_typescript_wasm/src/lib.rs @@ -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 { let options: Options = serde_wasm_bindgen::from_value(options)?;