You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Given a crate A with a package.json next to Cargo.toml containing NPM package dependencies, running cargo test --target wasm32-unknown-unknown (or wasm-pack test) will fail as the required dependencies are not present to be loaded.
It feels like wasm-bindgen needs to invoke npm install to install the dependencies in the temporary test directory to install the dependencies prior to running the tests?
Steps to Reproduce
Set up a crate which creates bindings to a NPM module via #[wasm_bindgen(module = ...)]
Add tests using #[wasm_bindgen_test] which make use of the bindings
Run cargo test --target wasm32-unknown-unknown or wasm-pack test
It's been a while since I last looked at this, but the biggest missing piece IIRC was the fact that the dependencies are not actually installed in some way, so they cannot be loaded when running the tests either.
I'm not sure what's the best approach here, as requiring an npm install of the dependencies then adds an implicit dependency of on npm on the runner.
So I delved deeper into this and, as far as I can tell, there's at least two things which need to happen for tests to work:
wasm-bindgen-test-runner probably should npm install the package under test to the temporary directory (so all its dependencies are available and importable during the tests)
The HTTP server currently serving the test JS and HTTP files needs to implement some additional module resolution logic, probably similar to what Webpack does
I am currently hacking away at these two points to get to a point where things work. If you have any feedback on this, I'd be happy to hear it! cc @simlay
Describe the Bug
Given a crate
A
with apackage.json
next toCargo.toml
containing NPM package dependencies, runningcargo test --target wasm32-unknown-unknown
(orwasm-pack test
) will fail as the required dependencies are not present to be loaded.It feels like
wasm-bindgen
needs to invokenpm install
to install the dependencies in the temporary test directory to install the dependencies prior to running the tests?Steps to Reproduce
#[wasm_bindgen(module = ...)]
#[wasm_bindgen_test]
which make use of the bindingscargo test --target wasm32-unknown-unknown
orwasm-pack test
Minimal example using bindings to React: https://github.com/jpgneves/wbg-test
Expected Behavior
Tests run successfully.
Actual Behavior
The following error is given (for the example linked above):
The contents of
target/wasm32-unknown-unknown/wbg-tmp
:Where
package.json
contains the declared dependencies:The text was updated successfully, but these errors were encountered: