Skip to content

Commit

Permalink
Add image generation test to app route (#46449)
Browse files Browse the repository at this point in the history
~~Currently blocked by #46448.~~
Closes vercel/satori#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)
  • Loading branch information
shuding committed Feb 27, 2023
1 parent 04547e8 commit 9376a5a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
10 changes: 10 additions & 0 deletions test/e2e/og-api/app/app/og/route.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { ImageResponse } from '@vercel/og'

export async function GET() {
return new ImageResponse(<div>hi</div>, {
width: 1200,
height: 630,
})
}

export const runtime = 'edge'
3 changes: 3 additions & 0 deletions test/e2e/og-api/app/next.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
/** @type {import('next').NextConfig} */
module.exports = {
output: 'standalone',
experimental: {
appDir: true,
},
}
11 changes: 10 additions & 1 deletion test/e2e/og-api/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
Expand Down

0 comments on commit 9376a5a

Please sign in to comment.