-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MessageChannel is not defined #2448
Comments
Same error, MessageChannel is not defined. Context: I use Jest and run a createWriteStream method from "streamsaver". Does a workaround exist maybe? Thanks |
Unfortunately I did not find a workaround in this library :( That doesn't mean there isn't one, however... |
@TheJoshuaEvans Did you find one elsewhere? |
Been a while since I touched this. When I was working on this I wound up just switching to |
Looks like one could just do this as of Node 10.5.0: window.MessageChannel = require('worker_threads').MessageChannel; Source: https://nodejs.org/api/worker_threads.html#worker_threads_class_messagechannel However, one needs to pass Node the |
If someone adds this, there is one concern that I think needs to be resolved. jsdom sandboxes timers. I.e. I believe that jsdom should do the same for |
I just encountered this issue during my testing, but not sure if we need something else than this:
As I don't need to test sending messages in my tests, it works for me. Do you really need text messaging? |
window.MessageChannel = jest.fn().mockImplementation(() => {
let onmessage;
return {
port1: {
set onmessage(cb) {
onmessage = cb;
},
},
port2: {
postMessage: data => {
onmessage?.({ data });
},
},
};
}); works for me |
Basic info:
I am attempting to use Zombie.js (which uses jsdom) to debug Message Channel generation, but it doesn't seem to be defined. According to the MDN docs, the MessageChannel constructor has support going all the way back to IE10, so it seems strange that it's not supported here
Minimal reproduction case
Running the above node file should print the string "MessageChannel Exists!" and produce no errors. However, when running using jsdom a "MesssageChannel is not defined" error is thrown, and the console logs "MessageChannel Does not Exist :("
How does similar code behave in browsers?
Example of working code in JSFiddle:
https://jsfiddle.net/hvLpg6tm/5/
The HTML provided is exactly the same
The text was updated successfully, but these errors were encountered: