MCPcopy
hub / github.com/vercel/next.js / runTests

Function runTests

test/integration/prerender-preview/test/index.test.ts:37–267  ·  view source on GitHub ↗
(startServer = nextStart)

Source from the content-addressed store, hash-verified

35}
36
37function runTests(startServer = nextStart) {
38 it('should compile successfully', async () => {
39 await fs.remove(join(appDir, '.next'))
40 const { code, stdout } = await nextBuild(appDir, [], {
41 stdout: true,
42 })
43 expect(code).toBe(0)
44 expect(stdout).toMatch(/Compiled successfully/)
45 })
46
47 let appPort, app
48 it('should start production application', async () => {
49 appPort = await findPort()
50 app = await startServer(appDir, appPort)
51 })
52
53 it('should return prerendered page on first request', async () => {
54 const html = await renderViaHTTP(appPort, '/')
55 const { nextData, pre, routerData } = getData(html)
56 expect(nextData).toMatchObject({ isFallback: false })
57 expect(nextData.isPreview).toBeUndefined()
58 expect(pre).toBe('false and null')
59 expect(routerData.isPreview).toBe(false)
60 })
61
62 it('should return prerendered page on second request', async () => {
63 const html = await renderViaHTTP(appPort, '/')
64 const { nextData, pre, routerData } = getData(html)
65 expect(nextData).toMatchObject({ isFallback: false })
66 expect(nextData.isPreview).toBeUndefined()
67 expect(pre).toBe('false and null')
68 expect(routerData.isPreview).toBe(false)
69 })
70
71 it('should throw error when setting too large of preview data', async () => {
72 const res = await fetchViaHTTP(appPort, '/api/preview?tooBig=true')
73 expect(res.status).toBe(500)
74 expect(await res.text()).toBe('too big')
75 })
76
77 let previewCookieString
78 it('should enable preview mode', async () => {
79 const res = await fetchViaHTTP(appPort, '/api/preview', { lets: 'goooo' })
80 expect(res.status).toBe(200)
81
82 const originalCookies = res.headers.get('set-cookie').split(',')
83 const cookies = originalCookies.map((cookieRaw) => cookie.parse(cookieRaw))
84
85 expect(originalCookies.every((c) => c.includes('; Secure;'))).toBe(true)
86
87 expect(cookies.length).toBe(2)
88 expect(cookies[0]).toMatchObject({ Path: '/', SameSite: 'None' })
89 expect(cookies[0]).toHaveProperty('__prerender_bypass')
90 expect(cookies[0]).not.toHaveProperty('Max-Age')
91 expect(cookies[1]).toMatchObject({ Path: '/', SameSite: 'None' })
92 expect(cookies[1]).toHaveProperty('__next_preview_data')
93 expect(cookies[1]).not.toHaveProperty('Max-Age')
94

Callers 1

index.test.tsFile · 0.70

Calls 15

joinFunction · 0.90
nextBuildFunction · 0.90
findPortFunction · 0.90
renderViaHTTPFunction · 0.90
fetchViaHTTPFunction · 0.90
killAppFunction · 0.90
splitMethod · 0.80
everyMethod · 0.80
includesMethod · 0.80
getDataFunction · 0.70
getBuildIdFunction · 0.70
textMethod · 0.65

Tested by

no test coverage detected