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
I have been struggling to test components that use my Rust wasm-pack generated code.
I narrowed down the problem to the invokation of wasm-pack's await init().
It looks like vitest freezes there and can't proceed so I can't finish my tests.
I have tried replacing it with initSync() and running the init fn from the setupTests.ts file so it initializes before the test suite runs but no luck.
Running the async init function imported from my-wasm-lib/pkg throws a ReferenceError: self is not defined.
I tried mocking the self namespace with
globalThis.self = globalThis;
in my setupTests file and then I'd get a TypeError: Invalid URL
I wonder if it's possible at all to run the WASM thread in Vitest or am I doing something wrong.
Using the regular vite server with the wasm lib works just fine in the browser enviroment.
I have been struggling to test components that use my Rust wasm-pack generated code.
I narrowed down the problem to the invokation of wasm-pack's
await init()
.It looks like vitest freezes there and can't proceed so I can't finish my tests.
I have tried replacing it with
initSync()
and running theinit
fn from thesetupTests.ts
file so it initializes before the test suite runs but no luck.Running the async init function imported from
my-wasm-lib/pkg
throws aReferenceError: self is not defined
.I tried mocking the self namespace with
in my setupTests file and then I'd get a
TypeError: Invalid URL
I wonder if it's possible at all to run the WASM thread in Vitest or am I doing something wrong.
Using the regular vite server with the wasm lib works just fine in the browser enviroment.
My vite config:
Deps:
I build my wasm package using
wasm-pack build ./my-wasm-lib --target web
Tests are also declared with
@vitest-environment jsdom
Any ideas?
The text was updated successfully, but these errors were encountered: