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

Function runTests

test/integration/getserversideprops-preview/test/index.test.ts:37–174  ·  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 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 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 let previewCookieString
72 it('should enable preview mode', async () => {
73 const res = await fetchViaHTTP(appPort, '/api/preview', { lets: 'goooo' })
74 expect(res.status).toBe(200)
75
76 const originalCookies = res.headers.get('set-cookie').split(',')
77 const cookies = originalCookies.map((rawCookie) => cookie.parse(rawCookie))
78
79 expect(originalCookies.every((c) => c.includes('; Secure;'))).toBe(true)
80
81 expect(cookies.length).toBe(2)
82 expect(cookies[0]).toMatchObject({ Path: '/', SameSite: 'None' })
83 expect(cookies[0]).toHaveProperty('__prerender_bypass')
84 expect(cookies[0]).not.toHaveProperty('Max-Age')
85 expect(cookies[1]).toMatchObject({ Path: '/', SameSite: 'None' })
86 expect(cookies[1]).toHaveProperty('__next_preview_data')
87 expect(cookies[1]).not.toHaveProperty('Max-Age')
88
89 previewCookieString =
90 cookie.serialize('__prerender_bypass', cookies[0].__prerender_bypass) +
91 '; ' +
92 cookie.serialize('__next_preview_data', cookies[1].__next_preview_data)
93 })
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
getMethod · 0.65

Tested by

no test coverage detected