Unverified Commit 9376a5af authored by Shu Ding's avatar Shu Ding Committed by GitHub

Add image generation test to app route (#46449)

~~Currently blocked by #46448.~~
Closes https://github.com/vercel/satori/issues/410.

## Bug

- [ ] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the
feature request has been accepted for implementation before opening a
PR.
- [ ] Related issues linked using `fixes #number`
- [ ]
[e2e](https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs)
tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing
doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
parent 04547e81
import { ImageResponse } from '@vercel/og'
export async function GET() {
return new ImageResponse(<div>hi</div>, {
width: 1200,
height: 630,
})
}
export const runtime = 'edge'
/** @type {import('next').NextConfig} */
module.exports = {
output: 'standalone',
experimental: {
appDir: true,
},
}
......@@ -22,9 +22,18 @@ describe('og-api', () => {
expect(html).toContain('hello world')
})
it('should work', async () => {
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)
})
......
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