xref: /aosp_15_r20/external/bazelbuild-rules_rust/examples/wasm_bindgen/hello_world_wasm_test.js (revision d4726bddaa87cc4778e7472feed243fa4b6c267f)
1"use strict";
2const fs = require("fs");
3const path = require("path");
4const assert = require("assert");
5
6const main = async function (typ, dir) {
7    const wasm_file = path.join(
8        __dirname,
9        dir,
10        "hello_world_" + typ + "_wasm_bindgen_bg.wasm",
11    );
12    const buf = fs.readFileSync(wasm_file);
13    assert.ok(buf);
14
15    const res = await WebAssembly.instantiate(buf);
16    assert.ok(res);
17    assert.strictEqual(res.instance.exports.double(2), 4);
18};
19
20["bundler", "web", "deno", "nomodules", "nodejs"].forEach((typ) => {
21    main(typ, process.argv.length > 2 ? process.argv[2] : "").catch(function (
22        err,
23    ) {
24        console.error(err);
25        process.exit(1);
26    });
27});
28