forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test.js
64 lines (54 loc) · 1.79 KB
/
index.test.js
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
/* eslint-env jest */
/* global jasmine */
import { join } from 'path'
import getPort from 'get-port'
import { fetchViaHTTP, initNextServerScript, killApp } from 'next-test-utils'
import clone from 'clone'
const appDir = join(__dirname, '../')
let appPort
let server
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 2
const context = {}
const startServer = async (optEnv = {}) => {
const scriptPath = join(appDir, 'server.js')
context.appPort = appPort = await getPort()
const env = Object.assign(
{},
clone(process.env),
{ PORT: `${appPort}` },
optEnv
)
server = await initNextServerScript(scriptPath, /ready on/i, env)
}
describe('FileSystemPublicRoutes', () => {
beforeAll(() => startServer())
afterAll(() => killApp(server))
const fetch = (p, q) => fetchViaHTTP(context.appPort, p, q)
it('should not route to the index page', async () => {
const res = await fetch('/')
expect(res.status).toBe(404)
const body = await res.text()
expect(body).toMatch(/404/)
})
it('should route to exportPathMap defined routes in development', async () => {
const res = await fetch('/exportpathmap-route')
expect(res.status).toBe(200)
const body = await res.text()
expect(body).toMatch(/exportpathmap was here/)
})
it('should still handle /_next routes', async () => {
await fetch('/exportpathmap-route') // make sure it's built
const res = await fetch(
'/_next/static/development/pages/exportpathmap-route.js'
)
expect(res.status).toBe(200)
const body = await res.text()
expect(body).toMatch(/exportpathmap was here/)
})
it('should route to public folder files', async () => {
const res = await fetch('/hello.txt')
expect(res.status).toBe(200)
const body = await res.text()
expect(body).toMatch(/hello/)
})
})