File size: 1,450 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
import { join } from 'path'
import { nextTestSetup } from 'e2e-utils'
import { assertNoRedbox } from 'next-test-utils'

// Skipped in Turbopack, will be added later.
;(process.env.IS_TURBOPACK_TEST ? describe.skip : describe)(
  'Skipped in Turbopack',
  () => {
    describe('optimizePackageImports - mui', () => {
      const { next } = nextTestSetup({
        env: {
          NEXT_TEST_MODE: '1',
        },
        files: join(__dirname, 'fixture'),

        dependencies: {
          '@mui/material': '5.15.15',
          '@emotion/react': '11.11.1',
          '@emotion/styled': '11.11.0',
        },
      })

      it('should support MUI', async () => {
        let logs = ''
        next.on('stdout', (log) => {
          logs += log
        })

        // Ensure that MUI is working
        const $ = await next.render$('/mui')
        expect(await $('#button').text()).toContain('button')
        expect(await $('#typography').text()).toContain('typography')

        const browser = await next.browser('/mui')
        await assertNoRedbox(browser)

        const modules = [...logs.matchAll(/\((\d+) modules\)/g)]
        expect(modules.length).toBeGreaterThanOrEqual(1)
        for (const [, moduleCount] of modules) {
          // Ensure that the number of modules is less than 1500 - otherwise we're
          // importing the entire library.
          expect(parseInt(moduleCount)).toBeLessThan(1500)
        }
      })
    })
  }
)