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 that vitest is run without an environment like jsdom (i.e. the test.environment config attribute is unset), when importing a worker using the syntax import MyWorker from '../src/worker?worker' and creating an instance of this worker using new MyWorker(), then tests fail with the following stack trace:
FAIL test/init.test.ts > simple worker
ReferenceError: self is not defined
❯ getFileIdFromUrl ../../packages/web-worker/dist/pure.js:347:24
❯ new Worker ../../packages/web-worker/dist/pure.js:408:18
❯ new WorkerWrapper src/worker.ts:2:18
1| self.onmessage = (e) => {
2| self.postMessage(`${e.data} world`)
| ^
3| }
4|
❯ test/init.test.ts:37:20
Note that @vitest/web-workers explicitly states in their README that jsdom is not required:
Describe the bug
Given that
vitest
is run without an environment likejsdom
(i.e. thetest.environment
config attribute is unset), when importing a worker using the syntaximport MyWorker from '../src/worker?worker'
and creating an instance of this worker usingnew MyWorker()
, then tests fail with the following stack trace:Note that
@vitest/web-workers
explicitly states in their README thatjsdom
is not required:vitest/packages/web-worker/README.md
Line 3 in 41e828f
Reproduction
https://github.com/marvinruder/vitest
pnpm install --frozen-lockfile
pnpm build
cd test/web-worker
pnpm test
and observe that many tests fail, e.g.test/init.test.ts > simple worker
System Info
Used Package Manager
pnpm
Validations
The text was updated successfully, but these errors were encountered: