Repository: vercel/next.js
Pull request: Turbopack Build: Fix metadata test

## What?

Changes the test to not use the `.next` folder but instead fetch the running server which makes sure it does not rely on specific formats.

Closes PACK-4699

Changed files:
filename: test/lib/next-modes/base.ts
patch: @@ -545,6 +545,16 @@ export class NextInstance {
     return fs.readFile(path.join(this.testDir, filename), 'utf8')
   }
 
+  public async readFileBuffer(
+    filename: string
+  ): Promise<Buffer<ArrayBufferLike>> {
+    return fs.readFile(path.join(this.testDir, filename))
+  }
+
+  public async writeFileBuffer(filename: string, data: Buffer): Promise<void> {
+    return fs.writeFile(path.join(this.testDir, filename), data)
+  }
+
   public async readFiles(
     dirname: string,
     predicate: (filename: string) => boolean

filename: test/production/app-dir/metadata-static-route-cache/app/layout.tsx
patch: @@ -0,0 +1,7 @@
+export default function Layout({ children }: { children: React.ReactNode }) {
+  return (
+    <html>
+      <body>{children}</body>
+    </html>
+  )
+}

filename: test/production/app-dir/metadata-static-route-cache/app/page.tsx
patch: @@ -0,0 +1,3 @@
+export default function Page() {
+  return <h1>Hello World</h1>
+}

filename: test/production/app-dir/metadata-static-route-cache/metadata-static-route-cache.test.ts
patch: @@ -14,39 +14,51 @@ describe('app dir - metadata static routes cache', () => {
   })
 
   it('should generate different content after replace the static metadata file', async () => {
-    await next.build()
+    await next.start()
 
-    const faviconBuildContent = await next.readFile(
-      '.next/server/app/favicon.ico.body'
-    )
-    const opengrpahImageBuildContent = await next.readFile(
-      '.next/server/app/opengraph-image.png.body'
-    )
+    const $ = await next.render$('/')
+    const faviconUrl = $('link[rel="icon"]').attr('href')
+    const faviconBody = await (await next.fetch(faviconUrl)).text()
+    const faviconMd5 = generateMD5(faviconBody)
 
-    const faviconMd5 = generateMD5(faviconBuildContent)
-    const opengraphImageMd5 = generateMD5(opengrpahImageBuildContent)
+    const opengraphImageUrl = $('meta[property="og:image"]').attr('href')
+    const opengraphImageBody = await (
+      await next.fetch(opengraphImageUrl)
+    ).text()
+    const opengraphImageMd5 = generateMD5(opengraphImageBody)
 
-    // Update favicon and opengraph image
-    const newFaviconContent = await next.readFile('app/favicon.ico.new')
-    await next.patchFile('app/favicon.ico', newFaviconContent)
+    await next.stop()
 
-    const newOpengraphImageContent = await next.readFile(
-      'app/opengraph-image.png.new'
-    )
-    await next.patchFile('app/opengraph-image.png', newOpengraphImageContent)
+    // Update favicon and opengraph image
+    const newFaviconContent = await next.readFileBuffer('app/favicon.new.ico')
+    await next.remove('app/favicon.ico')
+    await next.writeFileBuffer('app/favicon.ico', newFaviconContent)
 
-    await next.build()
-    const faviconBuildContentNew = await next.readFile(
-      '.next/server/app/favicon.ico.body'
+    const newOpengraphImageContent = await next.readFileBuffer(
+      'app/opengraph-image.new.png'
     )
-    const opengrpahImageBuildContentNew = await next.readFile(
-      '.next/server/app/opengraph-image.png.body'
+    await next.remove('app/opengraph-image.png')
+    await next.writeFileBuffer(
+      'app/opengraph-image.png',
+      newOpengraphImageContent
     )
 
-    const faviconMd5New = generateMD5(faviconBuildContentNew)
-    const opengraphImageMd5New = generateMD5(opengrpahImageBuildContentNew)
+    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)
+
+    const newOpengraphImageUrl = new$('meta[property="og:image"]').attr('href')
+    const newOpengraphImageBody = await (
+      await next.fetch(newOpengraphImageUrl)
+    ).text()
+    const newOpengraphImageMd5 = generateMD5(newOpengraphImageBody)
+
+    await next.stop()
 
-    expect(faviconMd5).not.toBe(faviconMd5New)
-    expect(opengraphImageMd5).not.toBe(opengraphImageMd5New)
+    expect(faviconMd5).not.toBe(newFaviconMd5)
+    expect(opengraphImageMd5).not.toBe(newOpengraphImageMd5)
   })
 })

filename: test/turbopack-build-tests-manifest.json
patch: @@ -18519,10 +18519,10 @@
     "runtimeError": false
   },
   "test/production/app-dir/metadata-static-route-cache/metadata-static-route-cache.test.ts": {
-    "passed": [],
-    "failed": [
+    "passed": [
       "app dir - metadata static routes cache should generate different content after replace the static metadata file"
     ],
+    "failed": [],
     "pending": [],
     "flakey": [],
     "runtimeError": false