All Projects → developit → Jsdom Worker

developit / Jsdom Worker

👷‍♀️ Use Web Workers in Jest / JSDOM 🌈

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Jsdom Worker

100 Days Of Code Frontend
Curriculum for learning front-end development during #100DaysOfCode.
Stars: ✭ 2,419 (+1009.63%)
Mutual labels:  jest
Root Cause
🔍 Root Cause is a tool for troubleshooting Puppeteer and Playwright tests. 🔎
Stars: ✭ 205 (-5.96%)
Mutual labels:  jest
Wasm Worker
Move a WebAssembly module into its own thread
Stars: ✭ 215 (-1.38%)
Mutual labels:  web-worker
Weekly Digest
Weekly summary of activity on your GitHub repository 📆
Stars: ✭ 199 (-8.72%)
Mutual labels:  jest
Learning React
The code samples for Learning React by Alex Banks and Eve Porcello, published by O'Reilly Media
Stars: ✭ 2,705 (+1140.83%)
Mutual labels:  jest
Front End Guide
📚 Study guide and introduction to the modern front end stack.
Stars: ✭ 14,073 (+6355.5%)
Mutual labels:  jest
Jest Canvas Mock
🌗 A module used to mock canvas in Jest.
Stars: ✭ 189 (-13.3%)
Mutual labels:  jest
Svelte Boilerplate
Svelte application boilerplate with Webpack, Babel, PostCSS, Sass, Fetch, Jest, .Env, EsLint.
Stars: ✭ 216 (-0.92%)
Mutual labels:  jest
Preact Worker Demo
Demo of preact rendering an entire app in a Web Worker.
Stars: ✭ 204 (-6.42%)
Mutual labels:  web-worker
Aspnetcore Vue Typescript Template
Template AspNetCore with Vue, Vue router, Vuex, TypeScript, Bulma, Sass and Jest
Stars: ✭ 215 (-1.38%)
Mutual labels:  jest
Lerna Yarn Workspaces Monorepo
🐉 A Monorepo with multiple packages and a shared build, test, and release process.
Stars: ✭ 201 (-7.8%)
Mutual labels:  jest
Vuesion
Vuesion is a boilerplate that helps product teams build faster than ever with fewer headaches and modern best practices across engineering & design.
Stars: ✭ 2,510 (+1051.38%)
Mutual labels:  jest
Testdeck
Object oriented testing
Stars: ✭ 206 (-5.5%)
Mutual labels:  jest
Jest Native
🦅 Custom jest matchers to test the state of React Native
Stars: ✭ 196 (-10.09%)
Mutual labels:  jest
Awesome Learning
Awesome Learning - Learn JavaScript and Front-End Fundamentals at your own pace
Stars: ✭ 216 (-0.92%)
Mutual labels:  jest
Nxplorerjs Microservice Starter
Node JS , Typescript , Express based reactive microservice starter project for REST and GraphQL APIs
Stars: ✭ 193 (-11.47%)
Mutual labels:  jest
Jest Dom
🦉 Custom jest matchers to test the state of the DOM
Stars: ✭ 2,908 (+1233.94%)
Mutual labels:  jest
Web Worker Proxy
A better way of working with web workers
Stars: ✭ 218 (+0%)
Mutual labels:  web-worker
Modern Node
All-in-one development toolkit for creating node modules with Jest, Prettier, ESLint, and Standard
Stars: ✭ 216 (-0.92%)
Mutual labels:  jest
Buefy Shop
A sample shop built with Nuxt, Stripe, Firebase and Serverless Functions
Stars: ✭ 207 (-5.05%)
Mutual labels:  jest

jsdom-worker

Lets you use Web Workers in Jest!

This is an experimental implementation of the Web Worker API (specifically Dedicated Worker) for JSDOM.

It does not currently do any real threading, rather it implements the Worker interface but all work is done in the current thread. jsdom-worker runs wherever JSDOM runs, and does not require Node.

It supports both "inline" (created via Blob) and standard (loaded via URL) workers.

Hot Take: this module likely works in the browser, where it could act as a simple inline worker "poorlyfill".

npm travis

Why?

Jest uses a JSDOM environment by default, which means it doesn't support Workers. This means it is impossible to test code that requires both NodeJS functionality and Web Workers. jsdom-worker implements enough of the Worker spec that it is now possible to do so.

Installation

npm i jsdom-worker

Example

import 'jsdom-global/register'
import 'jsdom-worker'

let code = `onmessage = e => postMessage(e.data*2)`
let worker = new Worker(URL.createObjectURL(new Blob([code])))
worker.onmessage = console.log
worker.postMessage(5)  // 10

Usage with Jest

For single tests, simply add import 'jsdom-worker' to your module.

Otherwise, add it via the setupFiles Jest config option:

{
  "setupFiles": [
    "jsdom-worker"
  ]
}

License

MIT License

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].