-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to allow testing in both browser and Node.js? #2571
Comments
I think maybe you can do this with feature flags which was recently added to |
Adding to simlay comment: Maybe as a somewhat of a workaround (from wasm-pack v0.10.0) could be done:
In Cargo.toml:
And then
|
Sure, something like that is possible, but I don't want to add feature and recompile tests just to switch testing. wasm-pack already has switch for Node.js vs browser ( |
There's no way to allow both environments to run right now as far as I know, but I don't think that there's a reason that this can't be done. Right now the test runner looks at a custom section in the wasm binary to decide whether to run it using Node or the browser
wasm-bindgen/crates/test/src/lib.rs Lines 18 to 36 in 44d577f
I think you could change things so that there is one custom section per target environment (node, browser, etc) then have the test runner look for each. Then run all of the environments that are in the custom sections. I haven't spent any time thinking about how to make that all into a good user experience and whatnot in terms of how errors are reported and whether or not tests run in parallel, etc.. But at a high level multiple target environments should be possible as far as I can tell. |
Summary
I have code that is only using standard JS APIs, and I want to ensure it works in both browser and Node.js environments.
If I use
then running e.g.
wasm-pack test --headless --chrome
succeeds, butwasm-pack test --node
fails with:If I comment out that
wasm_bindgen_test_configure!(...)
call, then insteadwasm-pack test --node
succeeds, but browser test command fails with:Is there a way to allow either environment?
Additional Details
Looks like this behavior & flags were introduced in #1465 + rustwasm/wasm-pack#630, but I don't see a way to allow either environment.
The text was updated successfully, but these errors were encountered: