Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add E2E test for @vercel/og API route #42258

Merged
merged 1 commit into from Oct 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/next/build/utils.ts
Expand Up @@ -1658,7 +1658,9 @@ export async function copyTracedFiles(
`${normalizePagePath(page)}.js`
)
const pageTraceFile = `${pageFile}.nft.json`
await handleTraceFiles(pageTraceFile)
await handleTraceFiles(pageTraceFile).catch((err) => {
Log.warn(`Failed to copy traced files for ${pageFile}`, err)
})
}
await handleTraceFiles(path.join(distDir, 'next-server.js.nft.json'))
const serverOutputPath = path.join(
Expand Down
4 changes: 4 additions & 0 deletions test/e2e/og-api/app/next.config.js
@@ -0,0 +1,4 @@
/** @type {import('next').NextConfig} */
module.exports = {
output: 'standalone',
}
26 changes: 26 additions & 0 deletions test/e2e/og-api/app/pages/api/og.js
@@ -0,0 +1,26 @@
// /pages/api/og.jsx
import { ImageResponse } from '@vercel/og'

export const config = {
runtime: 'experimental-edge',
}

export default function () {
return new ImageResponse(
(
<div
style={{
width: '100%',
height: '100%',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
fontSize: 128,
background: 'lavender',
}}
>
Hello!
</div>
)
)
}
3 changes: 3 additions & 0 deletions test/e2e/og-api/app/pages/index.js
@@ -0,0 +1,3 @@
export default function Page() {
return <p>hello world</p>
}
30 changes: 30 additions & 0 deletions test/e2e/og-api/index.test.ts
@@ -0,0 +1,30 @@
import { createNext, FileRef } from 'e2e-utils'
import { NextInstance } from 'test/lib/next-modes/base'
import { fetchViaHTTP, renderViaHTTP } from 'next-test-utils'
import { join } from 'path'

describe('og-api', () => {
let next: NextInstance

beforeAll(async () => {
next = await createNext({
files: new FileRef(join(__dirname, 'app')),
dependencies: {
'@vercel/og': 'latest',
},
})
})
afterAll(() => next.destroy())

it('should respond from index', async () => {
const html = await renderViaHTTP(next.url, '/')
expect(html).toContain('hello world')
})

it('should work', async () => {
const res = await fetchViaHTTP(next.url, '/api/og')
expect(res.status).toBe(200)
const body = await res.blob()
expect(body.size).toBeGreaterThan(0)
})
})