Skip to content

Commit

Permalink
test: remove stale describe
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelfeldman committed Oct 30, 2020
1 parent c9fa8c0 commit 5a9ba55
Showing 1 changed file with 80 additions and 83 deletions.
163 changes: 80 additions & 83 deletions test/web-socket.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,95 +15,92 @@
* limitations under the License.
*/

import { it, describe, expect } from './fixtures';
import { it, expect } from './fixtures';

describe('web socket', (test, { browserName }) => {
}, () => {
it('should work', async ({ page, server }) => {
const value = await page.evaluate(port => {
let cb;
const result = new Promise(f => cb = f);
const ws = new WebSocket('ws://localhost:' + port + '/ws');
ws.addEventListener('message', data => { ws.close(); cb(data.data); });
return result;
}, server.PORT);
expect(value).toBe('incoming');
});
it('should work', async ({ page, server }) => {
const value = await page.evaluate(port => {
let cb;
const result = new Promise(f => cb = f);
const ws = new WebSocket('ws://localhost:' + port + '/ws');
ws.addEventListener('message', data => { ws.close(); cb(data.data); });
return result;
}, server.PORT);
expect(value).toBe('incoming');
});

it('should emit close events', async ({ page, server }) => {
let socketClosed;
const socketClosePromise = new Promise(f => socketClosed = f);
const log = [];
page.on('websocket', ws => {
log.push(`open<${ws.url()}>`);
ws.on('close', () => { log.push('close'); socketClosed(); });
});
await page.evaluate(port => {
const ws = new WebSocket('ws://localhost:' + port + '/ws');
ws.addEventListener('open', () => ws.close());
}, server.PORT);
await socketClosePromise;
expect(log.join(':')).toBe(`open<ws://localhost:${server.PORT}/ws>:close`);
it('should emit close events', async ({ page, server }) => {
let socketClosed;
const socketClosePromise = new Promise(f => socketClosed = f);
const log = [];
page.on('websocket', ws => {
log.push(`open<${ws.url()}>`);
ws.on('close', () => { log.push('close'); socketClosed(); });
});
await page.evaluate(port => {
const ws = new WebSocket('ws://localhost:' + port + '/ws');
ws.addEventListener('open', () => ws.close());
}, server.PORT);
await socketClosePromise;
expect(log.join(':')).toBe(`open<ws://localhost:${server.PORT}/ws>:close`);
});

it('should emit frame events', async ({ page, server, isFirefox }) => {
let socketClosed;
const socketClosePromise = new Promise(f => socketClosed = f);
const log = [];
page.on('websocket', ws => {
log.push('open');
ws.on('framesent', d => log.push('sent<' + d.payload + '>'));
ws.on('framereceived', d => log.push('received<' + d.payload + '>'));
ws.on('close', () => { log.push('close'); socketClosed(); });
});
await page.evaluate(port => {
const ws = new WebSocket('ws://localhost:' + port + '/ws');
ws.addEventListener('open', () => ws.send('outgoing'));
ws.addEventListener('message', () => { ws.close(); });
}, server.PORT);
await socketClosePromise;
expect(log[0]).toBe('open');
expect(log[3]).toBe('close');
log.sort();
expect(log.join(':')).toBe('close:open:received<incoming>:sent<outgoing>');
it('should emit frame events', async ({ page, server, isFirefox }) => {
let socketClosed;
const socketClosePromise = new Promise(f => socketClosed = f);
const log = [];
page.on('websocket', ws => {
log.push('open');
ws.on('framesent', d => log.push('sent<' + d.payload + '>'));
ws.on('framereceived', d => log.push('received<' + d.payload + '>'));
ws.on('close', () => { log.push('close'); socketClosed(); });
});
await page.evaluate(port => {
const ws = new WebSocket('ws://localhost:' + port + '/ws');
ws.addEventListener('open', () => ws.send('outgoing'));
ws.addEventListener('message', () => { ws.close(); });
}, server.PORT);
await socketClosePromise;
expect(log[0]).toBe('open');
expect(log[3]).toBe('close');
log.sort();
expect(log.join(':')).toBe('close:open:received<incoming>:sent<outgoing>');
});

it('should emit binary frame events', async ({ page, server }) => {
let doneCallback;
const donePromise = new Promise(f => doneCallback = f);
const sent = [];
page.on('websocket', ws => {
ws.on('close', doneCallback);
ws.on('framesent', d => sent.push(d.payload));
});
await page.evaluate(port => {
const ws = new WebSocket('ws://localhost:' + port + '/ws');
ws.addEventListener('open', () => {
const binary = new Uint8Array(5);
for (let i = 0; i < 5; ++i)
binary[i] = i;
ws.send('text');
ws.send(binary);
ws.close();
});
}, server.PORT);
await donePromise;
expect(sent[0]).toBe('text');
for (let i = 0; i < 5; ++i)
expect(sent[1][i]).toBe(i);
it('should emit binary frame events', async ({ page, server }) => {
let doneCallback;
const donePromise = new Promise(f => doneCallback = f);
const sent = [];
page.on('websocket', ws => {
ws.on('close', doneCallback);
ws.on('framesent', d => sent.push(d.payload));
});
await page.evaluate(port => {
const ws = new WebSocket('ws://localhost:' + port + '/ws');
ws.addEventListener('open', () => {
const binary = new Uint8Array(5);
for (let i = 0; i < 5; ++i)
binary[i] = i;
ws.send('text');
ws.send(binary);
ws.close();
});
}, server.PORT);
await donePromise;
expect(sent[0]).toBe('text');
for (let i = 0; i < 5; ++i)
expect(sent[1][i]).toBe(i);
});

it('should emit error', async ({page, server, isFirefox}) => {
let callback;
const result = new Promise(f => callback = f);
page.on('websocket', ws => ws.on('socketerror', callback));
page.evaluate(port => {
new WebSocket('ws://localhost:' + port + '/bogus-ws');
}, server.PORT);
const message = await result;
if (isFirefox)
expect(message).toBe('CLOSE_ABNORMAL');
else
expect(message).toContain(': 400');
});
it('should emit error', async ({page, server, isFirefox}) => {
let callback;
const result = new Promise(f => callback = f);
page.on('websocket', ws => ws.on('socketerror', callback));
page.evaluate(port => {
new WebSocket('ws://localhost:' + port + '/bogus-ws');
}, server.PORT);
const message = await result;
if (isFirefox)
expect(message).toBe('CLOSE_ABNORMAL');
else
expect(message).toContain(': 400');
});

0 comments on commit 5a9ba55

Please sign in to comment.