Comments (5)
self
is only defined in browser-like environments, so you need to specify happy-dom
or jsdom
environment
from vitest.
I tried adding
+import "@vitest/web-worker";
self.onmessage = function (e) {
console.log("Message received from main script");
const workerResult = "Result: " + e.data[0] * e.data[1];
but npm test
still fails.
from vitest.
(main)$ npm test
> [email protected] test
> vitest
DEV v1.6.0 /home/hamir/self-is-not-defined
❯ app/worker.ts (0)
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Failed Suites 1 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
FAIL app/worker.ts [ app/worker.ts ]
ReferenceError: self is not defined
❯ app/worker.ts:2:1
1| import "@vitest/web-worker";
2| self.onmessage = function (e) {
| ^
3| console.log("Message received from main script");
4| const workerResult = "Result: " + e.data[0] * e.data[1];
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/1]⎯
Test Files 1 failed (1)
Tests no tests
Start at 15:58:19
Duration 260ms (transform 27ms, setup 0ms, collect 0ms, tests 0ms, environment 0ms, prepare 60ms)
FAIL Tests failed. Watching for file changes...
press h to show help, press q to quit
from vitest.
https://github.com/hamirmahal/self-is-not-defined/actions/runs/9704696379/job/26785406469
from vitest.
#3974 might be related.
from vitest.
Related Issues (20)
- module mock failure on react-router-dom in browser mode HOT 2
- Snapshots modify input by unexpectedly trimming and adjusting indentation
- Unable to npm install @vitest/ui HOT 1
- stack trace incorrect for unhandled errors during test run in browser mode
- expect(...).toMatchSnapshot has typescript error since v2 of vitest HOT 2
- "TypeError: Cannot create proxy with a non-object as target or handler" when importing node module with a Proxy
- stack trace incorrect when react component throws with istanbul coverage HOT 1
- `@vitest/web-worker` didn't transform `.wasm?url` in worker import HOT 11
- Custom equality testers are not properly relayed to typed arrays HOT 2
- correct type for `import { defineConfig } from 'vitest/config';` with `"type": "commonjs"` HOT 1
- Pass down context to `onTestFinished` and `onTestFailed` instead of test result
- Some coverage.exclude glob patterns not matching for vitest 2 workspace HOT 4
- TypeError: Unknown file extension ".css"
- `tsc` with `"vitest"` version 2 requires `"@types/node"` to run without errors HOT 2
- Add 'coverageLinkUrl' option in Vitest UI for custom coverage report links
- Improve Vitest Public API
- Browser docs refer to defineCommand function which doesn't exist
- False negative with typecheck enabled
- `Error: Failed to load url` when dynamic importing js files generated during tests with relative path
- Istanbul: Coverage ignore doesn't work for default in switch
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vitest.