-
Notifications
You must be signed in to change notification settings - Fork 27.4k
/
Copy pathrevalidate-reason.test.ts
57 lines (45 loc) · 1.61 KB
/
revalidate-reason.test.ts
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import { nextTestSetup } from 'e2e-utils'
import { retry, waitFor } from 'next-test-utils'
describe('revalidate-reason', () => {
const { next, isNextDev } = nextTestSetup({
files: __dirname,
})
if (isNextDev) {
describe('development mode', () => {
// in dev mode, the revalidateReason is called on every request, and will always be considered stale
it('should support revalidateReason: "stale"', async () => {
const res = await next.fetch('/')
expect(res.status).toBe(200)
expect(next.cliOutput).toContain(
'revalidate-reason/pages/index.tsx revalidateReason: stale'
)
})
})
// skip the remaining tests as they do not apply in dev
return
}
it('should support revalidateReason: "build"', async () => {
expect(next.cliOutput).toContain(
'revalidate-reason/pages/index.tsx revalidateReason: build'
)
expect(next.cliOutput).toContain(
'revalidate-reason/pages/stale.tsx revalidateReason: build'
)
})
it('should support revalidateReason: "on-demand"', async () => {
const res = await next.fetch('/api/revalidate')
expect(res.status).toBe(200)
const $ = await next.render$('/')
expect($('#reason').text()).toBe('revalidate reason: on-demand')
})
it('should support revalidateReason: "stale"', async () => {
const res = await next.fetch('/stale')
expect(res.status).toBe(200)
// wait for the revalidation period
await waitFor(5000)
await retry(async () => {
const $ = await next.render$('/stale')
expect($('#reason').text()).toBe('revalidate reason: stale')
})
})
})