Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions tests/browsertype-connect.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ test('should be able to connect two browsers at the same time', async ({browserT

test('should timeout in socket while connecting', async ({browserType, startRemoteServer, server}) => {
const e = await browserType.connect({
wsEndpoint: `ws://localhost:${server.PORT}/ws`,
timeout: 1,
wsEndpoint: `ws://localhost:${server.PORT}/ws-slow`,
timeout: 1000,
Comment thread
dgozman marked this conversation as resolved.
}).catch(e => e);
expect(e.message).toContain('browserType.connect: Opening handshake has timed out');
});
Expand Down
27 changes: 17 additions & 10 deletions utils/testserver/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,24 @@ class TestServer {
else
this._server = http.createServer(this._onRequest.bind(this));
this._server.on('connection', socket => this._onSocket(socket));
this._wsServer = new WebSocketServer({server: this._server });
this._wsServer.shouldHandle = (request) => {
this._wsServer = new WebSocketServer({ noServer: true });
this._server.on('upgrade', async (request, socket, head) => {
const pathname = url.parse(request.url).pathname;
return ['/ws', '/ws-emit-and-close'].includes(pathname);
};
this._wsServer.on('connection', (ws, request) => {
const pathname = url.parse(request.url).pathname;
if (this._onWebSocketConnectionData !== undefined)
ws.send(this._onWebSocketConnectionData);
if (pathname === '/ws-emit-and-close')
ws.close(1003, 'closed by Playwright test-server');
if (pathname === '/ws-slow')
await new Promise(f => setTimeout(f, 2000));
if (!['/ws', '/ws-slow', '/ws-emit-and-close'].includes(pathname)) {
socket.write('HTTP/1.1 400 Bad Request\r\n\r\n');
socket.destroy();
return;
}
this._wsServer.handleUpgrade(request, socket, head, ws => {
// Next emit is only for our internal 'connection' listeners.
this._wsServer.emit('connection', ws, request);
if (this._onWebSocketConnectionData !== undefined)
ws.send(this._onWebSocketConnectionData);
if (pathname === '/ws-emit-and-close')
ws.close(1003, 'closed by Playwright test-server');
});
});
this._server.listen(port);
this._dirPath = dirPath;
Expand Down