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.
This commit is contained in:
Andrey Lushnikov 2019-02-05 19:49:47 -08:00 committed by GitHub
parent bc71e9236d
commit 86783c2495
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 12 deletions

View File

@ -16,7 +16,7 @@
const utils = require('./utils'); 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 {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit} = testRunner; const {it, fit, xit} = testRunner;
const {beforeAll, beforeEach, afterAll, afterEach} = 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'); const response = await page.goto(server.PREFIX + '/grid.html');
expect(response.status()).toBe(200); 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'}); const response = await page.goto(server.EMPTY_PAGE, {waitUntil: 'networkidle0'});
expect(response.status()).toBe(200); 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'}); const response = await page.goto(server.EMPTY_PAGE, {waitUntil: 'networkidle2'});
expect(response.status()).toBe(200); expect(response.status()).toBe(200);
}); });
@ -176,7 +176,7 @@ module.exports.addTests = function({testRunner, expect, Errors}) {
expect(response.ok()).toBe(true); expect(response.ok()).toBe(true);
expect(response.url()).toBe(server.EMPTY_PAGE); 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 = []; let responses = [];
// Hold on to a bunch of requests without answering. // Hold on to a bunch of requests without answering.
server.setRoute('/fetch-request-a.js', (req, res) => responses.push(res)); server.setRoute('/fetch-request-a.js', (req, res) => responses.push(res));

View File

@ -918,8 +918,8 @@ module.exports.addTests = function({testRunner, expect, headless, Errors, Device
const responses = new Map(); const responses = new Map();
page.on('response', r => responses.set(r.url().split('/').pop(), r)); page.on('response', r => responses.set(r.url().split('/').pop(), r));
await page.goto(server.PREFIX + '/cached/one-style.html', {waitUntil: 'networkidle2'}); await page.goto(server.PREFIX + '/cached/one-style.html');
await page.reload({waitUntil: 'networkidle2'}); await page.reload();
expect(responses.get('one-style.css').fromCache()).toBe(true); expect(responses.get('one-style.css').fromCache()).toBe(true);
await page.setCacheEnabled(false); await page.setCacheEnabled(false);

View File

@ -124,9 +124,12 @@ module.exports.addTests = function({testRunner, expect, product, Errors}) {
it('should work with strict CSP policy', async({page, server}) => { it('should work with strict CSP policy', async({page, server}) => {
server.setCSP('/empty.html', 'script-src ' + server.PREFIX); server.setCSP('/empty.html', 'script-src ' + server.PREFIX);
await page.goto(server.EMPTY_PAGE); await page.goto(server.EMPTY_PAGE);
const watchdog = page.waitForFunction(() => window.__FOO === 'hit', {polling: 'raf'}); let error = null;
await page.evaluate(() => window.__FOO = 'hit'); await Promise.all([
await watchdog; 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}) => { it('should throw on bad polling value', async({page, server}) => {
let error = null; let error = null;
@ -222,9 +225,11 @@ module.exports.addTests = function({testRunner, expect, product, Errors}) {
it('should work with removed MutationObserver', async({page, server}) => { it('should work with removed MutationObserver', async({page, server}) => {
await page.evaluate(() => delete window.MutationObserver); await page.evaluate(() => delete window.MutationObserver);
const waitForSelector = page.waitForSelector('.zombo'); const [handle] = await Promise.all([
await page.setContent(`<div class='zombo'>anything</div>`); page.waitForSelector('.zombo'),
expect(await page.evaluate(x => x.textContent, await waitForSelector)).toBe('anything'); page.setContent(`<div class='zombo'>anything</div>`),
]);
expect(await page.evaluate(x => x.textContent, handle)).toBe('anything');
}); });
it('should resolve promise when node is added', async({page, server}) => { it('should resolve promise when node is added', async({page, server}) => {