forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.test.ts
More file actions
75 lines (66 loc) · 2.32 KB
/
index.test.ts
File metadata and controls
75 lines (66 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import { createNext, FileRef } from 'e2e-utils'
import { NextInstance } from 'test/lib/next-modes/base'
import { fetchViaHTTP, renderViaHTTP } from 'next-test-utils'
import fs from 'fs-extra'
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 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)
})
if ((global as any).isNextStart) {
it('should copy files correctly', async () => {
expect(next.cliOutput).not.toContain('Failed to copy traced files')
expect(
await fs.pathExists(
join(next.testDir, '.next/standalone/.next/server/pages/api/og.js')
)
).toBe(true)
expect(
await fs.pathExists(
join(next.testDir, '.next/standalone/.next/server/edge-chunks')
)
).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.`
)
})
}
})