I have a rust + wasm project like this:
wasm-pack-example/
pkg/
.gitignore
package.json
wasm_pack_example.d.ts
wasm_pack_example.js
wasm_pack_example_bg.d.ts
wasm_pack_example_bg.js
wasm_pack_example_bg.wasm
src/
lib.rs
Cargo.toml
The contents of pkg get built when I run wasm-pack build.
The emitted js files aren't simple pass-throughs of the public rust functions - wasm-pack adds some logic to them. It looks mostly like memory management wrappers over the public rust functions.
What I really want to do at this point in my project is to write automated tests against the js interface to the emitted wasm. This is what my app does, and this is what I need to test. I'm happy using any testing framework (I've been doing a lot of this experimentation with jest).
I've tried numerous guides and tools to do this, including https://github.com/DrSensor/rs-jest, which was promising, but lacks the ability to test the specific js interface produced by wasm-pack. Also, it seems to lack what's needed by my particular lib, perhaps in the particular way I'm using wasm_bindgen. When instantiating the WebAssembly according to rs-jest's, I'd see TypeError: WebAssembly.instantiate(): Imports argument must be present and must be an object, and if I passed an empty object to the instantiation, I'd see TypeError: WebAssembly.instantiate(): Import #0 module="__wbindgen_placeholder__" error: module is not an object or function.
I also tried for a while to simulate the particular way wasm might be fetched and instantiated by the browser using JsDom. I produced an index.html file that loaded the wasm-pack js files via a script tag, then I created a JsDom instance using that index.html file. It properly tried to fetch the wasm from an import in the js (which required me to add my own fetch implementation to the JsDom instance's window, serving back the wasm file from the filesystem), but then choked halfway down the js file because module.require is not a function. I was unable to make any progress past that.
Anyway, this is just to show that I haven't been able to find any solution for this. Has anybody out there been able to write automated tests against the js interfaces produced by wasm-pack?