-
Notifications
You must be signed in to change notification settings - Fork 26k
/
index.test.ts
48 lines (42 loc) · 1.28 KB
/
index.test.ts
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
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', async () => {
const res = await fetchViaHTTP(next.url, '/api/og')
expect(res.status).toBe(200)
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)
})
}
})