(isDev: boolean)
| 27 | } |
| 28 | |
| 29 | function runTests(isDev: boolean) { |
| 30 | it('should get preview cookie correctly', async () => { |
| 31 | const res = await fetchViaHTTP(appPort, '/api/enable') |
| 32 | previewCookie = '' |
| 33 | |
| 34 | expect(res.headers.get('set-cookie')).toMatch( |
| 35 | /(__prerender_bypass|__next_preview_data)/ |
| 36 | ) |
| 37 | |
| 38 | res.headers |
| 39 | .get('set-cookie') |
| 40 | .split(',') |
| 41 | .forEach((c) => { |
| 42 | const cookies = cookie.parse(c) |
| 43 | const isBypass = cookies.__prerender_bypass |
| 44 | |
| 45 | if (isBypass || cookies.__next_preview_data) { |
| 46 | if (previewCookie) previewCookie += '; ' |
| 47 | |
| 48 | previewCookie += `${ |
| 49 | isBypass ? '__prerender_bypass' : '__next_preview_data' |
| 50 | }=${cookies[isBypass ? '__prerender_bypass' : '__next_preview_data']}` |
| 51 | } |
| 52 | }) |
| 53 | }) |
| 54 | |
| 55 | it('should not write preview index SSG page to cache', async () => { |
| 56 | const html = await renderViaHTTP(appPort, '/') |
| 57 | const props = JSON.parse(cheerio.load(html)('#props').text()) |
| 58 | |
| 59 | expect(props).toEqual({ |
| 60 | preview: false, |
| 61 | previewData: null, |
| 62 | }) |
| 63 | |
| 64 | const res = await fetchViaHTTP(appPort, '/', undefined, { |
| 65 | headers: { |
| 66 | cookie: previewCookie, |
| 67 | }, |
| 68 | }) |
| 69 | |
| 70 | const previewHtml = await res.text() |
| 71 | const previewProps = JSON.parse(cheerio.load(previewHtml)('#props').text()) |
| 72 | expect(previewProps).toEqual({ |
| 73 | preview: true, |
| 74 | previewData: {}, |
| 75 | }) |
| 76 | |
| 77 | if (!isDev) { |
| 78 | const fsHtml = await fs.readFile(getCacheFile('index.html')) |
| 79 | const fsProps = JSON.parse(cheerio.load(fsHtml)('#props').text()) |
| 80 | |
| 81 | expect(fsProps).toEqual({ |
| 82 | preview: false, |
| 83 | previewData: null, |
| 84 | }) |
| 85 | } |
| 86 | const html2 = await renderViaHTTP(appPort, '/') |
no test coverage detected