Files
2ca0d5df1c [test] split og-api test suite into default and standalone variants (#93915)
The fixture's `next.config.js` had `output: 'standalone'` hardcoded,
which is meaningless on Vercel deployments (the standalone directory is
ignored) but became a build-time crash after #93684 made the Turbopack
NFT generator skip `next-server.js.nft.json` whenever an adapter is
configured. With `output: 'standalone'` still active,
`writeStandaloneDirectory` then fails with `ENOENT` when it tries to
read that file
([x-ref](https://github.com/vercel/next.js/actions/runs/26006483168/job/76441905221)).

This PR splits the `og-api` E2E suite into a default variant and a
`standalone.test.ts` wrapper that enables `output: 'standalone'` via the
`TEST_OUTPUT_STANDALONE` env var, and excludes the standalone wrapper
from the deploy test manifest.

The default variant still runs in `deploy` mode and preserves coverage
of `next/og` from Pages Router API routes, App Router route handlers
(edge and node), and middleware — paths not covered by the metadata-*
fixtures. The standalone variant continues to exercise the trace-copy
assertion in `next start` mode.

---------

Co-authored-by: Tim Neutkens <[email protected]>
2026-05-18 12:14:43 +00:00

87 lines
2.7 KiB
TypeScript

import { FileRef, nextTestSetup } from 'e2e-utils'
import { fetchViaHTTP, renderViaHTTP } from 'next-test-utils'
import fs from 'fs-extra'
import { join } from 'path'
describe('og-api', () => {
const { next, skipped } = nextTestSetup({
files: new FileRef(join(__dirname, 'app')),
skipDeployment: process.env.TEST_OUTPUT_STANDALONE === 'true',
})
if (skipped) return
it('should respond from index', async () => {
const html = await renderViaHTTP(next.url, '/')
expect(html).toContain('hello world')
})
it('should work in pages/api', async () => {
const res = await fetchViaHTTP(next.url, '/api/og')
expect(res.status).toBe(200)
expect(res.headers.get('content-type')).toContain('image/png')
const body = await res.blob()
expect(body.size).toBeGreaterThan(0)
})
it('should work in app route', async () => {
const res = await fetchViaHTTP(next.url, '/og')
expect(res.status).toBe(200)
expect(res.headers.get('content-type')).toContain('image/png')
const body = await res.blob()
expect(body.size).toBeGreaterThan(0)
})
it('should work in app route in node runtime', async () => {
const res = await fetchViaHTTP(next.url, '/og-node')
expect(res.status).toBe(200)
expect(res.headers.get('content-type')).toContain('image/png')
const body = await res.blob()
expect(body.size).toBeGreaterThan(0)
})
it('should work in middleware', async () => {
const res = await fetchViaHTTP(next.url, '/middleware')
expect(res.status).toBe(200)
expect(res.headers.get('content-type')).toContain('image/png')
const body = await res.blob()
expect(body.size).toBeGreaterThan(0)
})
if (
(global as any).isNextStart &&
process.env.TEST_OUTPUT_STANDALONE === 'true'
) {
it('should copy files correctly', async () => {
expect(next.cliOutput).not.toContain('Failed to copy traced files')
let manifest = await fs.readJSON(
join(
next.testDir,
'.next/standalone/.next/server/middleware-manifest.json'
)
)
let apiOg = manifest.functions['/api/og']
let files = apiOg.files.concat(
[...apiOg.wasm, ...apiOg.assets].map((f) => f.filePath)
)
for (let f of files) {
expect(
await fs.pathExists(join(next.testDir, '.next/standalone/.next', f))
).toBe(true)
}
})
}
if ((global as any).isNextDev) {
it('should throw error when returning a response object in pages/api in node runtime', async () => {
const res = await fetchViaHTTP(next.url, '/api/og-wrong-runtime')
expect(res.status).toBe(500)
expect(await res.text()).toContain(
`API route returned a Response object in the Node.js runtime, this is not supported.`
)
})
}
})