Skip to content

Commit

Permalink
test(websockets): add web sockets tests (#1758)
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelfeldman committed Apr 13, 2020
1 parent 277c7d8 commit 97c4054
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
12 changes: 12 additions & 0 deletions test/capabilities.spec.js
Expand Up @@ -21,4 +21,16 @@ describe('Capabilities', function() {
await page.goto(server.PREFIX + '/wasm/table2.html');
expect(await page.evaluate(() => loadTable())).toBe('42, 83');
});

it('WebSocket 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); });
ws.addEventListener('error', error => cb('Error'));
return result;
}, server.PORT);
expect(value).toBe('incoming');
});
});
30 changes: 29 additions & 1 deletion test/ignorehttpserrors.spec.js
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

const {FFOX, CHROMIUM, WEBKIT} = require('./utils').testOptions(browserType);
const {FFOX, CHROMIUM, WEBKIT, MAC} = require('./utils').testOptions(browserType);

describe('ignoreHTTPSErrors', function() {
it('should work', async({browser, httpsServer}) => {
Expand Down Expand Up @@ -60,4 +60,32 @@ describe('ignoreHTTPSErrors', function() {
expect(await page.frames()[1].evaluate('2 + 3')).toBe(5);
await context.close();
});
it.fail(WEBKIT && MAC)('should work with WebSocket', async({browser, httpsServer}) => {
const context = await browser.newContext({ ignoreHTTPSErrors: true });
const page = await context.newPage();
const value = await page.evaluate(endpoint => {
let cb;
const result = new Promise(f => cb = f);
const ws = new WebSocket(endpoint);
ws.addEventListener('message', data => { ws.close(); cb(data.data); });
ws.addEventListener('error', error => cb('Error'));
return result;
}, httpsServer.PREFIX.replace(/https/, 'wss') + '/ws');
expect(value).toBe('incoming');
await context.close();
});
it('should fail with WebSocket if not ignored', async({browser, httpsServer}) => {
const context = await browser.newContext();
const page = await context.newPage();
const value = await page.evaluate(endpoint => {
let cb;
const result = new Promise(f => cb = f);
const ws = new WebSocket(endpoint);
ws.addEventListener('message', data => { ws.close(); cb(data.data); });
ws.addEventListener('error', error => cb('Error'));
return result;
}, httpsServer.PREFIX.replace(/https/, 'wss') + '/ws');
expect(value).toBe('Error');
await context.close();
});
});

0 comments on commit 97c4054

Please sign in to comment.