mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-29 07:42:04 +00:00
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:
parent
480227179a
commit
bb67e5edb1
@ -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
|
||||
|
@ -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 () => {
|
||||
|
Loading…
Reference in New Issue
Block a user