diff --git a/extensions/wasm_bindgen/rules_js/test/BUILD.bazel b/extensions/wasm_bindgen/rules_js/test/BUILD.bazel index b587ca0f01..14896a4a05 100644 --- a/extensions/wasm_bindgen/rules_js/test/BUILD.bazel +++ b/extensions/wasm_bindgen/rules_js/test/BUILD.bazel @@ -70,13 +70,13 @@ _WASM_DATA = [ js_test( name = "hello_world_wasm_direct_test", data = _WASM_DATA, - entry_point = "hello_world_wasm_test.js", + entry_point = "hello_world_wasm_test.mjs", ) js_library( name = "hello_world_wasm_lib", srcs = [ - "hello_world_wasm_test.js", + "hello_world_wasm_test.mjs", ], data = _WASM_DATA, deps = [], diff --git a/extensions/wasm_bindgen/rules_js/test/hello_world_wasm_test.js b/extensions/wasm_bindgen/rules_js/test/hello_world_wasm_test.js deleted file mode 100644 index 61fc383955..0000000000 --- a/extensions/wasm_bindgen/rules_js/test/hello_world_wasm_test.js +++ /dev/null @@ -1,30 +0,0 @@ -"use strict"; -const fs = require("fs"); -const path = require("path"); -const assert = require("assert"); - -const main = async function (typ, dir) { - const wasm_file = path.join( - __dirname, - "..", - dir, - "test", - "hello_world_" + typ + "_wasm_bindgen", - "hello_world_" + typ + "_wasm_bindgen_bg.wasm", - ); - const buf = fs.readFileSync(wasm_file); - assert.ok(buf); - - const res = await WebAssembly.instantiate(buf); - assert.ok(res); - assert.strictEqual(res.instance.exports.double(2), 4); -}; - -["bundler", "web", "deno", "nomodules", "nodejs"].forEach((typ) => { - main(typ, process.argv.length > 2 ? process.argv[2] : "").catch(function ( - err, - ) { - console.error(err); - process.exit(1); - }); -}); diff --git a/extensions/wasm_bindgen/rules_js/test/hello_world_wasm_test.mjs b/extensions/wasm_bindgen/rules_js/test/hello_world_wasm_test.mjs new file mode 100644 index 0000000000..1a87967d1d --- /dev/null +++ b/extensions/wasm_bindgen/rules_js/test/hello_world_wasm_test.mjs @@ -0,0 +1,28 @@ +import path from "path"; +import assert from "assert"; +import { fileURLToPath } from "url"; + +const main = async function (typ, dir) { + const filename = fileURLToPath(import.meta.url); + const dirname = path.dirname(filename); + + const wasm_module = path.join( + dirname, + "..", + dir, + "test", + `hello_world_${typ}_wasm_bindgen`, + `hello_world_${typ}_wasm_bindgen.js`, + ); + + const res = await import(wasm_module); + + assert.strictEqual(res.instance.exports.double(2), 4); +}; + +["bundler", "web", "deno", "nomodules", "nodejs"].forEach((typ) => { + main(typ, process.argv.length > 2 ? process.argv[2] : "").catch((err) => { + console.error(err); + process.exit(1); + }); +});