Bug 1671725 - [puppeteer] Handle async TimeoutErrors in several tests r=remote-protocol-reviewers,whimboo

This prevents the errors from being raised later on during an unrelated
test.

Differential Revision: https://phabricator.services.mozilla.com/D94244
This commit is contained in:
Maja Frydrychowicz 2020-10-22 14:12:33 +00:00
parent 480227179a
commit bb67e5edb1
2 changed files with 36 additions and 9 deletions

View File

@ -96,24 +96,38 @@ describe('BrowserContext', function () {
await context.close();
});
it('should wait for a target', async () => {
const { browser, server } = getTestState();
const { browser, puppeteer, server } = getTestState();
const context = await browser.createIncognitoBrowserContext();
let resolved = false;
const targetPromise = context.waitForTarget(
(target) => target.url() === server.EMPTY_PAGE
);
targetPromise.then(() => (resolved = true));
targetPromise
.then(() => (resolved = true))
.catch((error) => {
resolved = true;
if (error instanceof puppeteer.errors.TimeoutError) {
console.error(error);
} else throw error;
});
const page = await context.newPage();
expect(resolved).toBe(false);
await page.goto(server.EMPTY_PAGE);
const target = await targetPromise;
expect(await target.page()).toBe(page);
try {
const target = await targetPromise;
expect(await target.page()).toBe(page);
} catch (error) {
if (error instanceof puppeteer.errors.TimeoutError) {
console.error(error);
} else throw error;
}
await context.close();
});
it('should timeout waiting for a non-existent target', async () => {
const { browser, server, puppeteer } = getTestState();
const { browser, puppeteer, server } = getTestState();
const context = await browser.createIncognitoBrowserContext();
const error = await context

View File

@ -252,18 +252,31 @@ describe('Target', function () {
describe('Browser.waitForTarget', () => {
it('should wait for a target', async () => {
const { browser, server } = getTestState();
const { browser, puppeteer, server } = getTestState();
let resolved = false;
const targetPromise = browser.waitForTarget(
(target) => target.url() === server.EMPTY_PAGE
);
targetPromise.then(() => (resolved = true));
targetPromise
.then(() => (resolved = true))
.catch((error) => {
resolved = true;
if (error instanceof puppeteer.errors.TimeoutError) {
console.error(error);
} else throw error;
});
const page = await browser.newPage();
expect(resolved).toBe(false);
await page.goto(server.EMPTY_PAGE);
const target = await targetPromise;
expect(await target.page()).toBe(page);
try {
const target = await targetPromise;
expect(await target.page()).toBe(page);
} catch (error) {
if (error instanceof puppeteer.errors.TimeoutError) {
console.error(error);
} else throw error;
}
await page.close();
});
it('should timeout waiting for a non-existent target', async () => {