Skip to content

Commit

Permalink
chore(firefox): run all tests without "UnhandledPromiseRejection" error
Browse files Browse the repository at this point in the history
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 puppeteer#3889.
  • Loading branch information
aslushnikov committed Feb 6, 2019
1 parent bc71e92 commit 0cb9f27
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
8 changes: 4 additions & 4 deletions test/navigation.spec.js
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
});
Expand Down Expand Up @@ -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));
Expand Down
4 changes: 2 additions & 2 deletions test/page.spec.js
Expand Up @@ -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);
Expand Down
17 changes: 11 additions & 6 deletions test/waittask.spec.js
Expand Up @@ -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;
Expand Down Expand Up @@ -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(`<div class='zombo'>anything</div>`);
expect(await page.evaluate(x => x.textContent, await waitForSelector)).toBe('anything');
const [handle] = await Promise.all([
page.waitForSelector('.zombo'),
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}) => {
Expand Down

0 comments on commit 0cb9f27

Please sign in to comment.