1

I am trying to write tests for multiple socket connections, which I need to have multiple sessions (simultaneously) for since they are identified by session ID on the server side...

In the example below client1 will connect and the handshake will be passed the cookie with session id so i can use express-socket.io-session to get the session data for that user....

The problem i'm running into is when i want to connect a second socket, the handshake data passed through is obviously going to be the same as the first socket.

I can't just send a logout request and change user because i'm trying to test multiplayer functionality.

var agent = chai.request.agent(app)

describe("authentication", function () {
    it('login as user', function (done) {
        agent
            .post('/login')
            .send({
                username: username,
                password: password
            })
            .then(function (res) {
                expect(res).to.have.status(200);
                expect(res).to.have.cookie('connect.sid');
                done()
            })
            .catch(function (err) {
                done(err)
            })
    });

})


describe("socket tests", function () {
    var client1, client2;

    it('can connect to socket', function (done) {
        client1 = io.connect("http://localhost:3000/", options);
        client1.on('connect', () => {
            done();
        })
    });

    it('can connect second user to socket', function (done) {
        client2 = io.connect("http://localhost:3000/", options);
        client2.on('connect', () => {
            done();
        })
    });
})
Koborl
  • 235
  • 1
  • 11

0 Answers0