File size: 1,218 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/* eslint-disable jest/no-standalone-expect */
import { waitFor, retry } from 'next-test-utils'
import { nextTestSetup } from 'e2e-utils'

describe('app-fetch-deduping', () => {
  const { next, isTurbopack } = nextTestSetup({ files: __dirname })

  const itSkipTurbopack = isTurbopack ? it.skip : it

  // This solution consistently works in Webpack but is flaky in Turbopack.
  // This will require a follow-up
  itSkipTurbopack(
    'should still properly cache fetches when the user has a custom fetch implementation',
    async () => {
      const browser = await next.browser('/')

      let currentValue: string | undefined
      await retry(async () => {
        const initialRandom = await browser.elementById('random').text()
        expect(initialRandom).toMatch(/^0\.\d+$/)

        await browser.refresh()
        currentValue = await browser.elementById('random').text()
        expect(currentValue).toBe(initialRandom)
      })

      // wait for the revalidation period
      await waitFor(3000)

      await retry(async () => {
        await browser.refresh()
        const finalValue = await browser.elementById('random').text()
        expect(finalValue).not.toBe(currentValue)
      })
    }
  )
})