test: catch unhandled in a network test (#10242)
This commit is contained in:
parent
1e5865c911
commit
73b72b31b2
@ -371,17 +371,26 @@ describe('navigation', function () {
|
|||||||
// Ignore Error that arise from test server during hooks
|
// Ignore Error that arise from test server during hooks
|
||||||
});
|
});
|
||||||
|
|
||||||
// Navigate to a page which loads immediately and then does a bunch of
|
|
||||||
// requests via javascript's fetch method.
|
|
||||||
const navigationPromise = page.goto(server.PREFIX + '/networkidle.html', {
|
|
||||||
waitUntil: 'networkidle0',
|
|
||||||
});
|
|
||||||
// Track when the navigation gets completed.
|
// Track when the navigation gets completed.
|
||||||
let navigationFinished = false;
|
let navigationFinished = false;
|
||||||
navigationPromise.then(() => {
|
let navigationError: Error | undefined;
|
||||||
return (navigationFinished = true);
|
// Navigate to a page which loads immediately and then does a bunch of
|
||||||
|
// requests via javascript's fetch method.
|
||||||
|
const navigationPromise = page
|
||||||
|
.goto(server.PREFIX + '/networkidle.html', {
|
||||||
|
waitUntil: 'networkidle0',
|
||||||
|
})
|
||||||
|
.then(response => {
|
||||||
|
navigationFinished = true;
|
||||||
|
return response;
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
navigationError = error;
|
||||||
|
return null;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let afterNavigationError: Error | undefined;
|
||||||
|
const afterNavigationPromise = (async () => {
|
||||||
// Wait for the page's 'load' event.
|
// Wait for the page's 'load' event.
|
||||||
await waitEvent(page, 'load');
|
await waitEvent(page, 'load');
|
||||||
expect(navigationFinished).toBe(false);
|
expect(navigationFinished).toBe(false);
|
||||||
@ -411,10 +420,21 @@ describe('navigation', function () {
|
|||||||
response.statusCode = 404;
|
response.statusCode = 404;
|
||||||
response.end(`File not found`);
|
response.end(`File not found`);
|
||||||
}
|
}
|
||||||
|
})().catch(error => {
|
||||||
|
afterNavigationError = error;
|
||||||
|
});
|
||||||
|
|
||||||
const response = (await navigationPromise)!;
|
await Promise.race([navigationPromise, afterNavigationPromise]);
|
||||||
|
if (navigationError) {
|
||||||
|
throw navigationError;
|
||||||
|
}
|
||||||
|
await Promise.all([navigationPromise, afterNavigationPromise]);
|
||||||
|
if (afterNavigationError) {
|
||||||
|
throw afterNavigationError;
|
||||||
|
}
|
||||||
// Expect navigation to succeed.
|
// Expect navigation to succeed.
|
||||||
expect(response.ok()).toBe(true);
|
expect(navigationFinished).toBeTruthy();
|
||||||
|
expect((await navigationPromise)?.ok()).toBe(true);
|
||||||
});
|
});
|
||||||
it('should not leak listeners during navigation', async function () {
|
it('should not leak listeners during navigation', async function () {
|
||||||
this.timeout(25_000);
|
this.timeout(25_000);
|
||||||
|
Loading…
Reference in New Issue
Block a user