File size: 4,753 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import { nextTestSetup } from 'e2e-utils'
import { join } from 'path'
import { createSandbox } from 'development-sandbox'

const isPPREnabled = process.env.__NEXT_EXPERIMENTAL_PPR === 'true'

describe('app-root-params - cache - at runtime', () => {
  const { next, isNextDev, skipped } = nextTestSetup({
    files: join(__dirname, 'fixtures', 'use-cache-runtime'),
    skipStart: true,
    // this test asserts on build failure logs, which aren't currently observable in `next.cliOutput`.
    skipDeployment: true,
  })

  if (skipped) return

  if (isNextDev) {
    it('should error when using rootParams within a "use cache" - dev', async () => {
      await using sandbox = await createSandbox(
        next,
        undefined,
        '/en/us/use-cache'
      )
      const { session } = sandbox
      await session.assertHasRedbox()
      if (isPPREnabled) {
        // When PPR is enabled we verify that we have at least one root param value from generateStaticParams
        // Which this test does not define so we get a different error which preempts the root params error
        expect(await session.getRedboxDescription()).toInclude(
          'Required root params (lang, locale) were not provided in generateStaticParams'
        )
      } else {
        expect(await session.getRedboxDescription()).toInclude(
          'Route /[lang]/[locale]/use-cache used `unstable_rootParams()` inside `"use cache"` or `unstable_cache`'
        )
      }
    })

    it('should error when using rootParams within `unstable_cache` - dev', async () => {
      await using sandbox = await createSandbox(
        next,
        undefined,
        '/en/us/unstable_cache'
      )
      const { session } = sandbox
      await session.assertHasRedbox()
      if (isPPREnabled) {
        // When PPR is enabled we verify that we have at least one root param value from generateStaticParams
        // Which this test does not define so we get a different error which preempts the root params error
        expect(await session.getRedboxDescription()).toInclude(
          'Required root params (lang, locale) were not provided in generateStaticParams'
        )
      } else {
        expect(await session.getRedboxDescription()).toInclude(
          'Route /[lang]/[locale]/unstable_cache used `unstable_rootParams()` inside `"use cache"` or `unstable_cache`'
        )
      }
    })
  } else {
    beforeAll(async () => {
      try {
        await next.start()
      } catch (_) {
        // We expect the build to fail
      }
    })

    it('should error when using rootParams within a "use cache" - start', async () => {
      if (isPPREnabled) {
        // When PPR is enabled we verify that we have at least one root param value from generateStaticParams
        // Which this test does not define so we get a different error which preempts the root params error
        expect(next.cliOutput).toInclude(
          'Required root params (lang, locale) were not provided in generateStaticParams'
        )
      } else {
        await next.render$('/en/us/use-cache')
        expect(next.cliOutput).toInclude(
          'Error: Route /[lang]/[locale]/use-cache used `unstable_rootParams()` inside `"use cache"` or `unstable_cache`'
        )
      }
    })

    it('should error when using rootParams within `unstable_cache` - start', async () => {
      if (isPPREnabled) {
        // When PPR is enabled we verify that we have at least one root param value from generateStaticParams
        // Which this test does not define so we get a different error which preempts the root params error
        expect(next.cliOutput).toInclude(
          'Required root params (lang, locale) were not provided in generateStaticParams'
        )
      } else {
        await next.render$('/en/us/unstable_cache')
        expect(next.cliOutput).toInclude(
          'Error: Route /[lang]/[locale]/unstable_cache used `unstable_rootParams()` inside `"use cache"` or `unstable_cache`'
        )
      }
    })
  }
})

describe('app-root-params - cache - at build', () => {
  const { next, isNextDev } = nextTestSetup({
    files: join(__dirname, 'fixtures', 'use-cache-build'),
    skipStart: true,
  })

  if (isNextDev) {
    // we omit these tests in dev because they are duplicates semantically to the runtime fixture tested above
    it('noop in dev', () => {})
  } else {
    it('should error when building a project that uses rootParams within `"use cache"`', async () => {
      try {
        await next.start()
      } catch {
        // we expect the build to fail
      }
      expect(next.cliOutput).toInclude(
        'Error: Route /[lang]/[locale]/use-cache used `unstable_rootParams()` inside `"use cache"` or `unstable_cache`'
      )
    })
  }
})