Commit 5a5d6a60 authored by Tobias Koppers's avatar Tobias Koppers

Fix flaky metadata-static-route-cache test by wrapping server lifecycle in try/finally

Each next.start() is now paired with a finally block that calls next.stop(),
ensuring the server is stopped even when assertions throw mid-test. Without this,
a failed test left the server running, causing "next already started" on retry.
Co-Authored-By: 's avatarClaude <noreply@anthropic.com>
parent 2ea43d64
......@@ -14,20 +14,24 @@ describe('app dir - metadata static routes cache', () => {
})
it('should generate different content after replace the static metadata file', async () => {
await next.start()
const $ = await next.render$('/')
const faviconUrl = $('link[rel="icon"]').attr('href')
const faviconBody = await (await next.fetch(faviconUrl)).text()
const faviconMd5 = generateMD5(faviconBody)
let faviconMd5: string
let opengraphImageMd5: string
const opengraphImageUrl = $('meta[property="og:image"]').attr('href')
const opengraphImageBody = await (
await next.fetch(opengraphImageUrl)
).text()
const opengraphImageMd5 = generateMD5(opengraphImageBody)
await next.start()
try {
const $ = await next.render$('/')
const faviconUrl = $('link[rel="icon"]').attr('href')
const faviconBody = await (await next.fetch(faviconUrl)).text()
faviconMd5 = generateMD5(faviconBody)
await next.stop()
const opengraphImageUrl = $('meta[property="og:image"]').attr('href')
const opengraphImageBody = await (
await next.fetch(opengraphImageUrl)
).text()
opengraphImageMd5 = generateMD5(opengraphImageBody)
} finally {
await next.stop()
}
// Update favicon and opengraph image
const newFaviconContent = await next.readFileBuffer('app/favicon.new.ico')
......@@ -43,20 +47,26 @@ describe('app dir - metadata static routes cache', () => {
newOpengraphImageContent
)
await next.start()
const new$ = await next.render$('/')
const newFaviconUrl = new$('link[rel="icon"]').attr('href')
const newFaviconBody = await (await next.fetch(newFaviconUrl)).text()
const newFaviconMd5 = generateMD5(newFaviconBody)
let newFaviconMd5: string
let newOpengraphImageMd5: string
const newOpengraphImageUrl = new$('meta[property="og:image"]').attr('href')
const newOpengraphImageBody = await (
await next.fetch(newOpengraphImageUrl)
).text()
const newOpengraphImageMd5 = generateMD5(newOpengraphImageBody)
await next.start()
try {
const new$ = await next.render$('/')
const newFaviconUrl = new$('link[rel="icon"]').attr('href')
const newFaviconBody = await (await next.fetch(newFaviconUrl)).text()
newFaviconMd5 = generateMD5(newFaviconBody)
await next.stop()
const newOpengraphImageUrl = new$('meta[property="og:image"]').attr(
'href'
)
const newOpengraphImageBody = await (
await next.fetch(newOpengraphImageUrl)
).text()
newOpengraphImageMd5 = generateMD5(newOpengraphImageBody)
} finally {
await next.stop()
}
expect(faviconMd5).not.toBe(newFaviconMd5)
expect(opengraphImageMd5).not.toBe(newOpengraphImageMd5)
......
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