Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: extract unroute behavior tests into a separate file #28674

Merged
merged 1 commit into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 0 additions & 126 deletions tests/library/browsercontext-route.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,102 +79,6 @@ it('should unroute', async ({ browser, server }) => {
await context.close();
});

it('unroute should not wait for pending handlers to complete', async ({ page, context, server }) => {
it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/23781' });
let secondHandlerCalled = false;
await context.route(/.*/, async route => {
secondHandlerCalled = true;
await route.continue();
});
let routeCallback;
const routePromise = new Promise(f => routeCallback = f);
let continueRouteCallback;
const routeBarrier = new Promise(f => continueRouteCallback = f);
const handler = async route => {
routeCallback();
await routeBarrier;
await route.fallback();
};
await context.route(/.*/, handler);
const navigationPromise = page.goto(server.EMPTY_PAGE);
await routePromise;
await context.unroute(/.*/, handler);
continueRouteCallback();
await navigationPromise;
expect(secondHandlerCalled).toBe(true);
});

it('unrouteAll removes all handlers', async ({ page, context, server }) => {
await context.route('**/*', route => {
void route.abort();
});
await context.route('**/empty.html', route => {
void route.abort();
});
await context.unrouteAll();
await page.goto(server.EMPTY_PAGE);
});

it('unrouteAll should wait for pending handlers to complete', async ({ page, context, server }) => {
it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/23781' });
let secondHandlerCalled = false;
await context.route(/.*/, async route => {
secondHandlerCalled = true;
await route.abort();
});
let routeCallback;
const routePromise = new Promise(f => routeCallback = f);
let continueRouteCallback;
const routeBarrier = new Promise(f => continueRouteCallback = f);
const handler = async route => {
routeCallback();
await routeBarrier;
await route.fallback();
};
await context.route(/.*/, handler);
const navigationPromise = page.goto(server.EMPTY_PAGE);
await routePromise;
let didUnroute = false;
const unroutePromise = context.unrouteAll({ behavior: 'wait' }).then(() => didUnroute = true);
await new Promise(f => setTimeout(f, 500));
expect(didUnroute).toBe(false);
continueRouteCallback();
await unroutePromise;
expect(didUnroute).toBe(true);
await navigationPromise;
expect(secondHandlerCalled).toBe(false);
});

it('unrouteAll should not wait for pending handlers to complete if behavior is ignoreErrors', async ({ page, context, server }) => {
it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/23781' });
let secondHandlerCalled = false;
await context.route(/.*/, async route => {
secondHandlerCalled = true;
await route.abort();
});
let routeCallback;
const routePromise = new Promise(f => routeCallback = f);
let continueRouteCallback;
const routeBarrier = new Promise(f => continueRouteCallback = f);
const handler = async route => {
routeCallback();
await routeBarrier;
throw new Error('Handler error');
};
await context.route(/.*/, handler);
const navigationPromise = page.goto(server.EMPTY_PAGE);
await routePromise;
let didUnroute = false;
const unroutePromise = context.unrouteAll({ behavior: 'ignoreErrors' }).then(() => didUnroute = true);
await new Promise(f => setTimeout(f, 500));
await unroutePromise;
expect(didUnroute).toBe(true);
continueRouteCallback();
await navigationPromise.catch(e => void e);
// The error in the unrouted handler should be silently caught and remaining handler called.
expect(secondHandlerCalled).toBe(false);
});

it('should yield to page.route', async ({ browser, server }) => {
const context = await browser.newContext();
await context.route('**/empty.html', route => {
Expand Down Expand Up @@ -483,33 +387,3 @@ it('should fall back async', async ({ page, context, server }) => {
await page.goto(server.EMPTY_PAGE);
expect(intercepted).toEqual([3, 2, 1]);
});

it('page.close should not wait for active route handlers on the owning context', async ({ page, context, server }) => {
it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/23781' });
let routeCallback;
const routePromise = new Promise(f => routeCallback = f);
await context.route(/.*/, async route => {
routeCallback();
});
await page.route(/.*/, async route => {
await route.fallback();
});
page.goto(server.EMPTY_PAGE).catch(() => {});
await routePromise;
await page.close();
});

it('context.close should not wait for active route handlers on the owned pages', async ({ page, context, server }) => {
it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/23781' });
let routeCallback;
const routePromise = new Promise(f => routeCallback = f);
await page.route(/.*/, async route => {
routeCallback();
});
await page.route(/.*/, async route => {
await route.fallback();
});
page.goto(server.EMPTY_PAGE).catch(() => {});
await routePromise;
await context.close();
});
Loading
Loading