New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@vitest/web-worker

Package Overview
Dependencies
Maintainers
2
Versions
204
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@vitest/web-worker

Web Worker support for testing in Vitest

  • 0.7.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
49K
increased by27.58%
Maintainers
2
Weekly downloads
 
Created
Source

@vitest/web-worker

Web Worker support for Vitest testing. Doesn't require JSDom.

Simulates Web Worker, but in the same thread. Supports both new Worker(url) and import from './worker?worker.

Installing

# with npm
npm install -D @vitest/web-worker

# with pnpm
pnpm install -D @vitest/web-worker

# with yarn
yarn install -D @vitest/web-worker

Usage

Just import @vitest/web-worker in your test file to test only in current suite.

Or add @vitest/web-worker in your setupFiles, if you want to have a global support.

import { defineConfig } from 'vitest/node'

export default defineConfig({
  test: {
    setupFiles: ['@vitest/web-worker'],
  },
})

Examples

// worker.ts
import '@vitest/web-worker'
import MyWorker from '../worker?worker'

self.onmessage = (e) => {
  self.postMessage(`${e.data} world`)
}

// worker.test.ts
let worker = new MyWorker()
// new Worker is also supported
worker = new Worker(new URL('../src/worker.ts', import.meta.url))

worker.postMessage('hello')
worker.onmessage = (e) => {
  // e.data equals to 'hello world'
}

Notice

  • Does not support onmessage = () => {}. Please, use self.onmessage = () => {}.

FAQs

Package last updated on 17 Mar 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc