From 86783c24953ed41fea99ed359d5ebe9ff18fda62 Mon Sep 17 00:00:00 2001 From: Andrey Lushnikov Date: Tue, 5 Feb 2019 19:49:47 -0800 Subject: [PATCH] chore(firefox): run all tests without "UnhandledPromiseRejection" error (#3922) This aligns all Puppeteer tests so that they never throw the "UnhandledPromiseRejection" when run with Puppeteer-Firefox. With this patch, the `npm run funit` passes 275 of 460 Puppeteer tests. References #3889. --- test/navigation.spec.js | 8 ++++---- test/page.spec.js | 4 ++-- test/waittask.spec.js | 17 +++++++++++------ 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/test/navigation.spec.js b/test/navigation.spec.js index a9384733..63f8440b 100644 --- a/test/navigation.spec.js +++ b/test/navigation.spec.js @@ -16,7 +16,7 @@ const utils = require('./utils'); -module.exports.addTests = function({testRunner, expect, Errors}) { +module.exports.addTests = function({testRunner, expect, Errors, FFOX}) { const {describe, xdescribe, fdescribe} = testRunner; const {it, fit, xit} = testRunner; const {beforeAll, beforeEach, afterAll, afterEach} = testRunner; @@ -71,11 +71,11 @@ module.exports.addTests = function({testRunner, expect, Errors}) { const response = await page.goto(server.PREFIX + '/grid.html'); expect(response.status()).toBe(200); }); - it('should navigate to empty page with networkidle0', async({page, server}) => { + (FFOX ? xit : it)('should navigate to empty page with networkidle0', async({page, server}) => { const response = await page.goto(server.EMPTY_PAGE, {waitUntil: 'networkidle0'}); expect(response.status()).toBe(200); }); - it('should navigate to empty page with networkidle2', async({page, server}) => { + (FFOX ? xit : it)('should navigate to empty page with networkidle2', async({page, server}) => { const response = await page.goto(server.EMPTY_PAGE, {waitUntil: 'networkidle2'}); expect(response.status()).toBe(200); }); @@ -176,7 +176,7 @@ module.exports.addTests = function({testRunner, expect, Errors}) { expect(response.ok()).toBe(true); expect(response.url()).toBe(server.EMPTY_PAGE); }); - it('should wait for network idle to succeed navigation', async({page, server}) => { + (FFOX ? xit : it)('should wait for network idle to succeed navigation', async({page, server}) => { let responses = []; // Hold on to a bunch of requests without answering. server.setRoute('/fetch-request-a.js', (req, res) => responses.push(res)); diff --git a/test/page.spec.js b/test/page.spec.js index 91ef072d..dc93e1c9 100644 --- a/test/page.spec.js +++ b/test/page.spec.js @@ -918,8 +918,8 @@ module.exports.addTests = function({testRunner, expect, headless, Errors, Device const responses = new Map(); page.on('response', r => responses.set(r.url().split('/').pop(), r)); - await page.goto(server.PREFIX + '/cached/one-style.html', {waitUntil: 'networkidle2'}); - await page.reload({waitUntil: 'networkidle2'}); + await page.goto(server.PREFIX + '/cached/one-style.html'); + await page.reload(); expect(responses.get('one-style.css').fromCache()).toBe(true); await page.setCacheEnabled(false); diff --git a/test/waittask.spec.js b/test/waittask.spec.js index e65caa5e..7ea29b5e 100644 --- a/test/waittask.spec.js +++ b/test/waittask.spec.js @@ -124,9 +124,12 @@ module.exports.addTests = function({testRunner, expect, product, Errors}) { it('should work with strict CSP policy', async({page, server}) => { server.setCSP('/empty.html', 'script-src ' + server.PREFIX); await page.goto(server.EMPTY_PAGE); - const watchdog = page.waitForFunction(() => window.__FOO === 'hit', {polling: 'raf'}); - await page.evaluate(() => window.__FOO = 'hit'); - await watchdog; + let error = null; + await Promise.all([ + page.waitForFunction(() => window.__FOO === 'hit', {polling: 'raf'}).catch(e => error = e), + page.evaluate(() => window.__FOO = 'hit') + ]); + expect(error).toBe(null); }); it('should throw on bad polling value', async({page, server}) => { let error = null; @@ -222,9 +225,11 @@ module.exports.addTests = function({testRunner, expect, product, Errors}) { it('should work with removed MutationObserver', async({page, server}) => { await page.evaluate(() => delete window.MutationObserver); - const waitForSelector = page.waitForSelector('.zombo'); - await page.setContent(`
anything
`); - expect(await page.evaluate(x => x.textContent, await waitForSelector)).toBe('anything'); + const [handle] = await Promise.all([ + page.waitForSelector('.zombo'), + page.setContent(`
anything
`), + ]); + expect(await page.evaluate(x => x.textContent, handle)).toBe('anything'); }); it('should resolve promise when node is added', async({page, server}) => {