There's code we want to be able to test with JSDom that uses websockets. There are a lot of different implementations. Which would you suggest for use in contexts server side in JSDom + client side in the browser? I'm leaning towards ws.
Well, if you are wondering about integration into jsdom, my vote would go to one that:
In particular, ws
definitely does not implement the spec API, e.g. using on
instead of addEventListener
and so on.
I'm a little unclear what the purpose of this question is. Are you preparing to create a PR to add web socket support to jsdom?
I'd create a PR to add websocket support if you'd want it. For code that I'm testing using JSDom, I also want to be able to test websockets (while being able to browserify the whole lot).
That would be lovely!
Would it be appropriate to use ws
under the hood, but make the API match the API specification for websockets?
Definitely.
What the purpose of JSDom in XI century if it doesn't support WebSockets?..
:-)
@rgbkrk +1
@domenic have you integrated the PR?
@avesus It turns out a lot of people find purpose in it so far despite it not being a complete browser.
have you integrated the PR?
What PR?
I never made a PR, ended up getting away from jsdom for a bit as well as the project I wanted websockets for. Back to using it again though!
Please use the voting buttons and don't add "me too" comments. Deleting the one that just appeared.
Voting buttons? I'm looking around for this, found a change petition but it appears that github has not implemented any voting system..
@davidworkman9
@inikulin thanks. I was not aware that in github land that reaction.meaning == vote.meaning (or that you could use reactions as a voting mechanism). Sorry about my lack of proper github social skills.
Hey it's ok, the feature has only been around a few weeks IIRC.
what is the current state of websocket in jsdom?
It's not implemented.
@Sebmaster
It is very hard to separate out code from websockets. We would like to test views but views require models, models require websockets. Moking models is possible but very close test range.
Do you plan to implement websokets in near future?
I don't think anyone of us is currently implementing it, or prioritizing it in the near future. So unless there's a PR or a change of priorities, probably not.
Is anyone interested in collaborating on this?
I'm willing to do the work but would be great to have others participate at least in reviews.
@palmerj3 I'd be interested, but I'm sure the rest of @jsdom would be too. Just make sure to look at the requirements @Joris-van-der-Wel listed out when choosing a WS library: https://github.com/tmpvar/jsdom/issues/1195#issuecomment-131390814. If you hit any bumps, we'll be on #jsdom at Freenode to help :)
Is anyone working on this? Will take a crack at it otherwise
No one is working on this. ws
does support addEventListener
now so you should be able to use that module directly.
In general we're not able to use any modules directly as they don't support the full Web IDL semantics; wrapping will still be necessary. See https://github.com/tmpvar/jsdom/blob/master/Contributing.md#architecture for more information.
Would using this not work? https://www.npmjs.com/package/universal-websocket-client
This is actually what I'm using in my application that jsdom is having issues with
That definitely wouldn't be a good idea; it's just a wrapper around ws
, so we'd then need a wrapper around a wrapper around ws. Let's just do one layer of wrapping, please.
AFAIK this wrapper does implement this spec API
Yes, but as I tried to explain (and Contributing.md goes into in more detail), it doesn't implement it in a way that's compatible with jsdom's systems. For example, jsdom already contains an EventTarget, so we can't use the one that ws (or universal-websocket-client) comes with; then we'd have duplicates.
Ah that makes sense. Will dig into the contributing docs. Thanks
Thanks @domenic and @thdxr.
FYI there is now an active PR implementing the entirety of the WebSocket APIs, in https://github.com/tmpvar/jsdom/pull/2088. Please, check it out!
The WebSocket API PR just got merged! Support will be available in the next jsdom release.
Most helpful comment
Voting buttons? I'm looking around for this, found a change petition but it appears that github has not implemented any voting system..