npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@vitest/web-worker

v4.0.15

Published

Web Worker support for testing in Vitest

Downloads

388,601

Readme

@vitest/web-worker

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

Simulates Web Worker, but in the same thread.

Supported:

  • new Worker(path)
  • new SharedWorker(path)
  • import MyWorker from './worker?worker'
  • import MySharedWorker from './worker?sharedworker'

Installing

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

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

# with yarn
yarn add --dev @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'],
  },
})

You can also import defineWebWorkers from @vitest/web-worker/pure to define workers, whenever you need:

import { defineWebWorkers } from '@vitest/web-worker/pure'

if (process.env.SUPPORT_WORKERS) {
  defineWebWorkers({ clone: 'none' })
}

It accepts options:

  • clone: 'native' | 'ponyfill' | 'none'. Defines how should Worker clone message, when transferring data. Applies only to Worker communication. SharedWorker uses MessageChannel from Node's worker_threads module, and is not configurable.

Note Requires Node 17, if you want to use native structuredClone. Otherwise, it fallbacks to polyfill, if not specified as none. You can also configure this option with VITEST_WEB_WORKER_CLONE environmental variable.

Examples

// worker.ts
self.onmessage = (e) => {
  self.postMessage(`${e.data} world`)
}
// worker.test.ts
import '@vitest/web-worker'
import MyWorker from '../worker?worker'

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'
}

Notes

  • Worker does not support onmessage = () => {}. Please, use self.onmessage = () => {}.
  • Shared worker does not support onconnect = () => {}. Please, use self.onconnect = () => {}.
  • Transferring Buffer will not change its byteLength.
  • You have access to shared global space as your tests.
  • You can debug your worker, using DEBUG=vitest:web-worker environmental variable.