Unverified Commit 15edf7b9 authored by Janka Uryga's avatar Janka Uryga Committed by GitHub

fix hidden errors in router-act (#84603)

`createRouterAct` had a couple places where we create a promise via `new
Promise(async (resolve) => { ... })` without accounting for the fact
that some operations inside can throw, in which case the promise would
never resolve. Some tests that use `createRouterAct` like to hang
mysteriously, and i suspect this might be the reason. This PR changes
those places to use an `(async () => { ... })()` IIFE instead.
parent 1712abe1
...@@ -159,7 +159,7 @@ export function createRouterAct( ...@@ -159,7 +159,7 @@ export function createRouterAct(
// `act` controls the timing of when responses reach the client, // `act` controls the timing of when responses reach the client,
// but it should not affect the timing of when requests reach the // but it should not affect the timing of when requests reach the
// server; we pass the request to the server the immediately. // server; we pass the request to the server the immediately.
result: new Promise(async (resolve) => { result: (async () => {
const originalResponse = await page.request.fetch(request, { const originalResponse = await page.request.fetch(request, {
maxRedirects: 0, maxRedirects: 0,
}) })
...@@ -172,13 +172,13 @@ export function createRouterAct( ...@@ -172,13 +172,13 @@ export function createRouterAct(
const headers = originalResponse.headers() const headers = originalResponse.headers()
delete headers['transfer-encoding'] delete headers['transfer-encoding']
resolve({ return {
text: await originalResponse.text(), text: await originalResponse.text(),
body: await originalResponse.body(), body: await originalResponse.body(),
headers, headers,
status: originalResponse.status(), status: originalResponse.status(),
}) }
}), })(),
didProcess: false, didProcess: false,
}) })
if (onDidIssueFirstRequest !== null) { if (onDidIssueFirstRequest !== null) {
...@@ -417,14 +417,14 @@ ${fulfilled.body} ...@@ -417,14 +417,14 @@ ${fulfilled.body}
batch.pendingRequests.add({ batch.pendingRequests.add({
url: req.url(), url: req.url(),
route: null, route: null,
result: new Promise(async (resolve) => { result: (async () => {
resolve({ return {
text: await res.text(), text: await res.text(),
body: await res.body(), body: await res.body(),
headers: res.headers(), headers: res.headers(),
status: res.status(), status: res.status(),
}) }
}), })(),
didProcess: false, didProcess: false,
}) })
page.off('response', handleResponse) page.off('response', handleResponse)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment