canjs / can-fixture-socket

Simulate socket.io services.
https://canjs.com/doc/can-fixture-socket.html
MIT License
7 stars 2 forks source link

Events do not fall through to the "real" socket connection. #59

Open DesignByOnyx opened 6 years ago

DesignByOnyx commented 6 years ago

With AJAX fixtures, I only have to mock the services I want - everything else falls through to an actual AJAX request to the server. I would expect the same with sockets, but that is not the case.

Creating the mock server (and nothing else - no event listeners) prevents all socket messages from falling through to the "actual" socket connection to my server.

var io = require("socket.io-client");
var fixtureSocket = require("can-fixture-socket");
var mockServer = new fixtureSocket.Server(io);

If I set up event listeners, I am able to successfully mock a service with fixture data:

mockServer.onFeathersService('/users', store);

However, as it stands right now, I would need to do this for all of my services. I only want to do it for a select few services (like I can with AJAX).

justinbmeyer commented 6 years ago

@ilyavf any ideas?

DesignByOnyx commented 6 years ago

Another thing I noticed, which I think should be a part of this issue, is that the mockServer used for socket fixtrues has to be set up before any connections are defined or else it simply doesn't work. This was a bit difficult to track down, and even after knowing this it still came back and bit me because a model/connection was being imported somewhere before the mockServer was created. It would be nice if that could be fixed too so that fixtures can simply be imported, and all subsequent "requests" (socket events) are intercepted.