mswjs / jest-fixed-jsdom

A superset of the JSDOM environment for Jest that respects Node.js globals.
https://npm.im/jest-fixed-jsdom
52 stars 5 forks source link

Fix "BroadcastChannel" #18

Closed jcrang closed 3 weeks ago

jcrang commented 4 weeks ago

As of MSW 2.6.0, BroadcastChannel is required to be defined.

Have polyfilled this myself with:

const { BroadcastChannel } = require('node:worker_threads');

Object.defineProperties(globalThis, {
    BroadcastChannel: { value: BroadcastChannel }
});
kettanaito commented 3 weeks ago

Hi, @jcrang. Thanks for proposing this.

Is BroadcastChannel truly undefined in JSDOM?

kettanaito commented 3 weeks ago

We can also take it from the global scope, it's defined there.

jcrang commented 3 weeks ago

Thanks for the quick resolution @kettanaito.

To answer your question (hopefully?) we were getting the same errors as for other properties that are fixed in jest-fixed-jsdom. The full error from our tests runs is:

● Test suite failed to run

  ReferenceError: BroadcastChannel is not defined

    // location in our code

    at Object.<anonymous> (node_modules/msw/src/core/ws.ts:20:26)
    at Object.<anonymous> (node_modules/msw/src/core/index.ts:13:40)
    at Object.require (Views/Shared/utils/msw/index.ts:3:1) // Our code
    at Object.require (Views/Shared/utils/msw/jest.ts:2:1) // Our code
    at Object.<anonymous> // Our code
kettanaito commented 3 weeks ago

Released: v0.0.7 🎉

This has been released in v0.0.7!

Make sure to always update to the latest version (npm i jest-fixed-jsdom@latest) to get the newest features and bug fixes.


Predictable release automation by @ossjs/release.