Unverified Commit 10ce117b authored by Sebastian "Sebbie" Silbermann's avatar Sebastian "Sebbie" Silbermann Committed by GitHub

[test] Fix `app-static` deploy test (#81712)

parent 9088ece1
...@@ -2763,27 +2763,51 @@ describe('app-dir static/dynamic handling', () => { ...@@ -2763,27 +2763,51 @@ describe('app-dir static/dynamic handling', () => {
for (let i = 0; i < 6; i++) { for (let i = 0; i < 6; i++) {
await waitFor(1000) await waitFor(1000)
const timings = {
start: Date.now(),
startedStreaming: 0,
}
res = await next.fetch(path) res = await next.fetch(path)
// eslint-disable-next-line no-loop-func let data: any
await new Promise<void>((resolve) => { let startedStreaming: number = -1
res.body.on('data', () => { res.body.on('data', () => {
if (!timings.startedStreaming) { if (startedStreaming === -1) {
timings.startedStreaming = Date.now() startedStreaming = Date.now()
} }
})
res.body.on('end', () => {
resolve()
})
}) })
if (res.headers.get('content-type').includes('application/json')) {
data = await res.json()
} else {
const html = await res.text()
const $ = cheerio.load(html)
const dataJSON = $('#data').text()
try {
data = JSON.parse(dataJSON)
} catch (cause) {
throw new Error(
`Failed to parse JSON from data-start attribute: "${dataJSON}"`,
{ cause }
)
}
}
expect(timings.startedStreaming - timings.start).toBeLessThan(3000) const startedResponding = +data.start
if (Number.isNaN(startedResponding)) {
throw new Error(
`Expected start to be a number. Received: "${data.start}"`
)
}
if (startedStreaming === -1) {
throw new Error(
'Expected startedStreaming to be set. This is a bug in the test.'
)
}
// We just want to ensure the response isn't blocked on revalidating the fetch.
// So we use the start time when route started processing not when we
// send off the response because that includes cold boots of the infra.
if (startedStreaming - startedResponding >= 3000) {
throw new Error(
`Response #${i} took too long to complete: ${startedStreaming - startedResponding}ms`
)
}
} }
}) })
......
...@@ -13,7 +13,7 @@ export default async function Page(props) { ...@@ -13,7 +13,7 @@ export default async function Page(props) {
return ( return (
<> <>
<p id="data"> <p id="data">
{JSON.stringify({ fetchDuration, data, now: Date.now() })} {JSON.stringify({ fetchDuration, data, now: Date.now(), start })}
</p> </p>
</> </>
) )
......
...@@ -12,5 +12,5 @@ export async function GET(req: NextRequest) { ...@@ -12,5 +12,5 @@ export async function GET(req: NextRequest) {
).then((res) => res.json()) ).then((res) => res.json())
const fetchDuration = Date.now() - start const fetchDuration = Date.now() - start
return NextResponse.json({ fetchDuration, data, now: Date.now() }) return NextResponse.json({ fetchDuration, data, now: Date.now(), start })
} }
...@@ -13,7 +13,7 @@ export default async function Page(props) { ...@@ -13,7 +13,7 @@ export default async function Page(props) {
return ( return (
<> <>
<p id="data"> <p id="data">
{JSON.stringify({ fetchDuration, data, now: Date.now() })} {JSON.stringify({ fetchDuration, data, now: Date.now(), start })}
</p> </p>
</> </>
) )
......
...@@ -12,5 +12,5 @@ export async function GET(req: NextRequest) { ...@@ -12,5 +12,5 @@ export async function GET(req: NextRequest) {
).then((res) => res.json()) ).then((res) => res.json())
const fetchDuration = Date.now() - start const fetchDuration = Date.now() - start
return NextResponse.json({ fetchDuration, data, now: Date.now() }) return NextResponse.json({ fetchDuration, data, now: Date.now(), start })
} }
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