-
-
Notifications
You must be signed in to change notification settings - Fork 192
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
Pollyfill MessageEvent since Node doesn't initialize properties per the spec. #682
Comments
Thanks for reporting @kalvenschraut! 🙂
You are very welcome to implement it. All contributions are welcome. The event classes are here (you should find many example of how they are implemented by looking at other events): |
Can I extend the global MessageEvent and add the missing functionality? Node doesn't do anything with the second parameter like it is suppose to per the spec. Can see what I am doing currently locally from the vitest issue. |
@kalvenschraut the events in the browsers are expected to inherit from the Event, and it is not possible to extend two classes. Also, I believe they would have different purposes as the MessageEvent is meant for very browser specific functionality. Do you have any documentation for the Node.js MessageEvent? Because I can't find it. |
As far as I understood it, node is attempting to make MessageEvent available to behave like browser contexts, but it is missing the functionality that vitest is trying to use in their web worker package. https://nodejs.org/api/globals.html#messageevent is the only documentation I can find. Vlad at vitest talked that they could look at adding this themselves here |
I think it is safest to implement this in Happy DOM without extending the NodeJS class to ensure that it will be compatible with the rest of the DOM functionality. Example: import Event from '../Event';
import IMessageEventInit from './IMessageEventInit';
export default class MessageEvent extends Event {
public readonly data: string | null = null;
...
/**
* Constructor.
*
* @param type Event type.
* @param [eventInit] Event init.
*/
constructor(type: string, eventInit?: IMessageEventInit) {
super(type, eventInit);
this.data = eventInit?.data || null;
...
}
} |
By implementing this: |
It's probably because it has not been implemented in Happy DOM yet. |
I guess I don't understand, if it hasn't been implemented in happy-dom then does it not fall back to Node's implementation? The only difference between those two tests is the environment, one only has Node and other has happy-dom + Node. Found Node's implementation here |
@kalvenschraut I have made a fix which adds support for I have also added the logo for RTVision 🥳 You can read more about the release here: |
See my issue over on vitest
I could do a PR if all that would be done is what I did in its description.
The text was updated successfully, but these errors were encountered: