I am currently testing my socket.io endpoint and using the socket.io-client library to create client connections to the different namespaces. On the first connections, since its internal cache is empty it will create a new connection and then share that connection with future namespace connections. This is exactly what I want since I have two events that are in different namespaces that depend on each other. However, The problem is that after closing the connections and trying to reconnect again the cache still persists and it creates a new connection for both namespace endpoints instead of sharing one.
I read how to delete the reference to the cached socket.io-client module here but as it clearly points out, only the reference to that module is destroyed and not the actual module object, so whenever I require it again I get the previous version socket.io-client version with its state from the previous tests intact, rather than a new, clean version.
So my question is, is there any way to completely delete that object and obtain a new one? I even tried to create new instances with the new
keyword but that also fails. What I want is to have the module object itself garbage collected and acquire a new copy.
Here is some code
describe('connections',function(){
beforeEach(function(){
var key = require.resolve('socket.io-client');
if(key)
{
delete require.cache[key];
}
ioclient = require('socket.io-client');
myclient = new ioclient(commentURL, ioopts);
});
//run all my tests
})
Aucun commentaire:
Enregistrer un commentaire