({ basePath = '/' }: { basePath: string })
| 7 | }) |
| 8 | |
| 9 | async function runTests({ basePath = '/' }: { basePath: string }) { |
| 10 | let origRandHome = 'unintialized' |
| 11 | let origRandWithCookies = 'unintialized' |
| 12 | let Cookie = '' |
| 13 | |
| 14 | it(`should use initial rand when draft mode is disabled on ${basePath}index`, async () => { |
| 15 | const $ = await next.render$(basePath) |
| 16 | expect($('#mode').text()).toBe('DISABLED') |
| 17 | expect($('#rand').text()).toBeDefined() |
| 18 | origRandHome = $('#rand').text() |
| 19 | }) |
| 20 | |
| 21 | it(`should use initial rand when draft mode is disabled on ${basePath}with-cookies`, async () => { |
| 22 | const $ = await next.render$(`${basePath}with-cookies`) |
| 23 | expect($('#mode').text()).toBe('DISABLED') |
| 24 | expect($('#rand').text()).toBeDefined() |
| 25 | expect($('#data').text()).toBe('') |
| 26 | origRandWithCookies = $('#rand').text() |
| 27 | }) |
| 28 | |
| 29 | if (!isNextDev) { |
| 30 | if (basePath === '/') { |
| 31 | it('should not generate rand when draft mode disabled during next start', async () => { |
| 32 | const $ = await next.render$(basePath) |
| 33 | expect($('#mode').text()).toBe('DISABLED') |
| 34 | expect($('#rand').text()).toBe(origRandHome) |
| 35 | }) |
| 36 | } |
| 37 | |
| 38 | it('should not read other cookies when draft mode disabled during next start', async () => { |
| 39 | const opts = { headers: { Cookie: `data=cool` } } |
| 40 | const $ = await next.render$(`${basePath}with-cookies`, {}, opts) |
| 41 | expect($('#mode').text()).toBe('DISABLED') |
| 42 | expect($('#data').text()).toBe('') |
| 43 | }) |
| 44 | } |
| 45 | |
| 46 | it('should be disabled from api route handler', async () => { |
| 47 | const res = await next.fetch(`${basePath}state`) |
| 48 | expect(await res.text()).toBe('DISABLED') |
| 49 | }) |
| 50 | |
| 51 | it('should have set-cookie header on enable', async () => { |
| 52 | const res = await next.fetch(`${basePath}enable`) |
| 53 | const h = res.headers.get('set-cookie') || '' |
| 54 | Cookie = h.split(';').find((c) => c.startsWith('__prerender_bypass')) |
| 55 | expect(Cookie).toBeDefined() |
| 56 | }) |
| 57 | |
| 58 | it('should have set-cookie header with redirect location', async () => { |
| 59 | const res = await next.fetch(`${basePath}enable-and-redirect`, { |
| 60 | redirect: 'manual', |
| 61 | }) |
| 62 | expect(res.status).toBe(307) |
| 63 | expect(res.headers.get('location')).toContain('/some-other-page') |
| 64 | const h = res.headers.get('set-cookie') || '' |
| 65 | const c = h.split(';').find((c) => c.startsWith('__prerender_bypass')) |
| 66 | expect(c).toBeDefined() |
no test coverage detected