(startServer = nextStart)
| 35 | } |
| 36 | |
| 37 | function 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 |
no test coverage detected