-
Notifications
You must be signed in to change notification settings - Fork 27k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test case for image generation (#42693)
This PR adds a basic test case to ensure Next.js and Edge Runtime changes don't break the image generation feature, as well as record the usage. ## Bug - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Errors have a helpful link attached, see `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` - [x] Integration tests added - [ ] Documentation added - [x] Telemetry added. In case of a feature if it's used or not. - [ ] Errors have a helpful link attached, see `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
Showing
8 changed files
with
176 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { ImageResponse } from '@vercel/og' | ||
|
||
export default async () => { | ||
return new ImageResponse(<div tw="w-full h-full text-5xl">hello</div>) | ||
} | ||
|
||
export const config = { | ||
runtime: 'experimental-edge', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* eslint-env jest */ | ||
import { | ||
fetchViaHTTP, | ||
findPort, | ||
killApp, | ||
nextBuild, | ||
nextStart, | ||
} from 'next-test-utils' | ||
import { join } from 'path' | ||
|
||
const appDir = join(__dirname, '../app') | ||
|
||
describe('Image Generation', () => { | ||
describe('Prod', () => { | ||
let app | ||
let appPort | ||
|
||
beforeAll(async () => { | ||
await nextBuild(appDir) | ||
appPort = await findPort() | ||
app = await nextStart(appDir, appPort) | ||
}) | ||
afterAll(async () => { | ||
await killApp(app) | ||
}) | ||
|
||
it('should generate the image without errors', async () => { | ||
const res = await fetchViaHTTP(appPort, '/api/image') | ||
expect(res.status).toBe(200) | ||
expect(res.headers.get('Content-Type')).toBe('image/png') | ||
|
||
const buffer = await res.buffer() | ||
|
||
// It should be a PNG | ||
expect( | ||
[0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a].every( | ||
(b, i) => buffer[i] === b | ||
) | ||
).toBeTrue() | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { ImageResponse } from '@vercel/og' | ||
|
||
export default async () => { | ||
return new ImageResponse(<div tw="w-full h-full text-5xl">hello</div>) | ||
} | ||
|
||
export const config = { | ||
runtime: 'experimental-edge', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters