File size: 2,473 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
/* eslint-disable jest/no-standalone-expect */
import { nextTestSetup } from 'e2e-utils'

const WARNING_MESSAGE = 'Webpack is configured while Turbopack is not'

const itif = (condition: boolean) => (condition ? it : it.skip)

describe('config-turbopack', () => {
  describe('when webpack is configured but Turbopack is not', () => {
    const { next, isTurbopack } = nextTestSetup({
      files: {
        'app/page.js': `
          export default function Page() {
            return <p>hello world</p>
          }
        `,
        'next.config.js': `
          module.exports = {
            webpack: (config) => {
              return config
            },
          }
        `,
      },
    })

    itif(isTurbopack)('warns', async () => {
      if (next) await next.render('/')
      expect(next.cliOutput).toContain(WARNING_MESSAGE)
    })
  })

  describe('when webpack is configured and config.turbopack is set', () => {
    const { next, isTurbopack } = nextTestSetup({
      files: {
        'app/page.js': `
          export default function Page() {
            return <p>hello world</p>
          }
        `,
        'next.config.js': `
          module.exports = {
            turbopack: {
              rules: {
                '*.foo': {
                  loaders: ['foo-loader']
                }
              }
            },
            webpack: (config) => {
              return config
            },
          }
        `,
      },
    })

    itif(isTurbopack)('does not warn', async () => {
      if (next) await next.render('/')
      expect(next.cliOutput).not.toContain(WARNING_MESSAGE)
    })
  })

  describe('when webpack is configured and config.experimental.turbo is set', () => {
    const { next, isTurbopack } = nextTestSetup({
      files: {
        'app/page.js': `
          export default function Page() {
            return <p>hello world</p>
          }
        `,
        'next.config.js': `
          module.exports = {
            experimental: {
              turbo: {
                rules: {
                  '*.foo': {
                    loaders: ['foo-loader']
                  }
                }
              }
            },
            webpack: (config) => {
              return config
            },
          }
        `,
      },
    })

    itif(isTurbopack)('does not warn', async () => {
      if (next) await next.render('/')
      expect(next.cliOutput).not.toContain(WARNING_MESSAGE)
    })
  })
})