({
optimisticClientCache,
}: {
optimisticClientCache?: boolean
})
| 15 | let next: NextInstance |
| 16 | |
| 17 | const runTests = ({ |
| 18 | optimisticClientCache, |
| 19 | }: { |
| 20 | optimisticClientCache?: boolean |
| 21 | }) => { |
| 22 | it('should not revalidate during prefetching', async () => { |
| 23 | const cliOutputStart = next.cliOutput.length |
| 24 | |
| 25 | for (let i = 0; i < 3; i++) { |
| 26 | for (const path of ['/blog/first', '/blog/second']) { |
| 27 | const res = await fetchViaHTTP( |
| 28 | next.url, |
| 29 | `/_next/data/${next.buildId}${path}.json`, |
| 30 | undefined, |
| 31 | { |
| 32 | headers: { |
| 33 | purpose: 'prefetch', |
| 34 | }, |
| 35 | } |
| 36 | ) |
| 37 | expect(res.status).toBe(200) |
| 38 | } |
| 39 | // do requests three times with 1 second between |
| 40 | // to go over revalidate period |
| 41 | await waitFor(1000) |
| 42 | } |
| 43 | expect(next.cliOutput.substring(cliOutputStart)).not.toContain( |
| 44 | 'revalidating /blog' |
| 45 | ) |
| 46 | }) |
| 47 | |
| 48 | it('should trigger revalidation after navigation', async () => { |
| 49 | const getData = () => |
| 50 | fetchViaHTTP( |
| 51 | next.url, |
| 52 | `/_next/data/${next.buildId}/blog/first.json`, |
| 53 | undefined, |
| 54 | { |
| 55 | headers: { |
| 56 | purpose: 'prefetch', |
| 57 | }, |
| 58 | } |
| 59 | ) |
| 60 | const initialDataRes = await getData() |
| 61 | const initialData = await initialDataRes.json() |
| 62 | const browser = await webdriver(next.url, '/') |
| 63 | |
| 64 | await browser.elementByCss('#to-blog-first').click() |
| 65 | |
| 66 | await check(async () => { |
| 67 | const data = await getData() |
| 68 | assert.notDeepEqual(initialData, data) |
| 69 | return 'success' |
| 70 | }, 'success') |
| 71 | }) |
| 72 | |
| 73 | it('should update cache using prefetch with unstable_skipClientCache', async () => { |
| 74 | const browser = await webdriver(next.url, '/') |
no test coverage detected