|
1 | 1 | import { join } from 'path' |
2 | 2 | import { createNextDescribe } from 'e2e-utils' |
3 | 3 | import { hasRedbox, shouldRunTurboDevTest } from 'next-test-utils' |
4 | | - |
5 | | -createNextDescribe( |
6 | | - 'optimizePackageImports', |
7 | | - { |
8 | | - env: { |
9 | | - NEXT_TEST_MODE: '1', |
10 | | - }, |
11 | | - files: join(__dirname, 'fixture'), |
12 | | - packageJson: { |
13 | | - scripts: { |
14 | | - setup: `cp -r ./node_modules_bak/* ./node_modules`, |
15 | | - build: `yarn setup && next build`, |
16 | | - dev: `yarn setup && next ${ |
17 | | - shouldRunTurboDevTest() ? 'dev --turbo' : 'dev' |
18 | | - }`, |
19 | | - start: 'next start', |
| 4 | +// Skipped in Turbopack, will be added later. |
| 5 | +;(process.env.TURBOPACK ? describe.skip : describe)( |
| 6 | + 'Skipped in Turbopack', |
| 7 | + () => { |
| 8 | + createNextDescribe( |
| 9 | + 'optimizePackageImports', |
| 10 | + { |
| 11 | + env: { |
| 12 | + NEXT_TEST_MODE: '1', |
| 13 | + }, |
| 14 | + files: join(__dirname, 'fixture'), |
| 15 | + packageJson: { |
| 16 | + scripts: { |
| 17 | + setup: `cp -r ./node_modules_bak/* ./node_modules`, |
| 18 | + build: `yarn setup && next build`, |
| 19 | + dev: `yarn setup && next ${ |
| 20 | + shouldRunTurboDevTest() ? 'dev --turbo' : 'dev' |
| 21 | + }`, |
| 22 | + start: 'next start', |
| 23 | + }, |
| 24 | + }, |
| 25 | + installCommand: 'yarn', |
| 26 | + startCommand: (global as any).isNextDev ? 'yarn dev' : 'yarn start', |
| 27 | + buildCommand: 'yarn build', |
| 28 | + dependencies: { |
| 29 | + 'lucide-react': '0.264.0', |
| 30 | + '@headlessui/react': '1.7.17', |
| 31 | + '@heroicons/react': '2.0.18', |
| 32 | + '@visx/visx': '3.3.0', |
| 33 | + 'recursive-barrel': '1.0.0', |
| 34 | + '@mui/material': '5.15.4', |
| 35 | + '@emotion/styled': '11.11.0', |
| 36 | + '@emotion/react': '11.11.1', |
| 37 | + }, |
20 | 38 | }, |
21 | | - }, |
22 | | - installCommand: 'yarn', |
23 | | - startCommand: (global as any).isNextDev ? 'yarn dev' : 'yarn start', |
24 | | - buildCommand: 'yarn build', |
25 | | - dependencies: { |
26 | | - 'lucide-react': '0.264.0', |
27 | | - '@headlessui/react': '1.7.17', |
28 | | - '@heroicons/react': '2.0.18', |
29 | | - '@visx/visx': '3.3.0', |
30 | | - 'recursive-barrel': '1.0.0', |
31 | | - '@mui/material': '5.15.4', |
32 | | - '@emotion/styled': '11.11.0', |
33 | | - '@emotion/react': '11.11.1', |
34 | | - }, |
35 | | - }, |
36 | | - ({ next }) => { |
37 | | - it('app - should render the icons correctly without creating all the modules', async () => { |
38 | | - let logs = '' |
39 | | - next.on('stdout', (log) => { |
40 | | - logs += log |
41 | | - }) |
42 | | - |
43 | | - const html = await next.render('/') |
44 | | - |
45 | | - // Ensure the icons are rendered |
46 | | - expect(html).toContain('<svg xmlns="http://www.w3.org/2000/svg"') |
47 | | - |
48 | | - const modules = [ |
49 | | - ...logs.matchAll( |
50 | | - /Compiled (\/[\w-]*)*\s*in \d+(\.\d+)?(s|ms) \((\d+) modules\)/g |
51 | | - ), |
52 | | - ] |
53 | | - |
54 | | - expect(modules.length).toBeGreaterThanOrEqual(1) |
55 | | - for (const [, , , , moduleCount] of modules) { |
56 | | - // Ensure that the number of modules is less than 1000 - otherwise we're |
57 | | - // importing the entire library. |
58 | | - expect(parseInt(moduleCount)).toBeLessThan(1000) |
59 | | - } |
60 | | - }) |
61 | | - |
62 | | - it('pages - should render the icons correctly without creating all the modules', async () => { |
63 | | - let logs = '' |
64 | | - next.on('stdout', (log) => { |
65 | | - logs += log |
66 | | - }) |
67 | | - |
68 | | - const html = await next.render('/pages-route') |
69 | | - |
70 | | - // Ensure the icons are rendered |
71 | | - expect(html).toContain('<svg xmlns="http://www.w3.org/2000/svg"') |
72 | | - |
73 | | - const modules = [ |
74 | | - ...logs.matchAll( |
75 | | - /Compiled (\/[\w-]+)*\s*in \d+(\.\d+)?(s|ms) \((\d+) modules\)/g |
76 | | - ), |
77 | | - ] |
78 | | - |
79 | | - expect(modules.length).toBeGreaterThanOrEqual(1) |
80 | | - for (const [, , , , moduleCount] of modules) { |
81 | | - // Ensure that the number of modules is less than 1000 - otherwise we're |
82 | | - // importing the entire library. |
83 | | - expect(parseInt(moduleCount)).toBeLessThan(1000) |
84 | | - } |
85 | | - }) |
86 | | - |
87 | | - it('app - should optimize recursive wildcard export mapping', async () => { |
88 | | - let logs = '' |
89 | | - next.on('stdout', (log) => { |
90 | | - logs += log |
91 | | - }) |
92 | | - |
93 | | - await next.render('/recursive-barrel-app') |
94 | | - |
95 | | - const modules = [...logs.matchAll(/\((\d+) modules\)/g)] |
96 | | - |
97 | | - expect(modules.length).toBeGreaterThanOrEqual(1) |
98 | | - for (const [, moduleCount] of modules) { |
99 | | - // Ensure that the number of modules is less than 1000 - otherwise we're |
100 | | - // importing the entire library. |
101 | | - expect(parseInt(moduleCount)).toBeLessThan(1000) |
| 39 | + ({ next }) => { |
| 40 | + it('app - should render the icons correctly without creating all the modules', async () => { |
| 41 | + let logs = '' |
| 42 | + next.on('stdout', (log) => { |
| 43 | + logs += log |
| 44 | + }) |
| 45 | + |
| 46 | + const html = await next.render('/') |
| 47 | + |
| 48 | + // Ensure the icons are rendered |
| 49 | + expect(html).toContain('<svg xmlns="http://www.w3.org/2000/svg"') |
| 50 | + |
| 51 | + const modules = [ |
| 52 | + ...logs.matchAll( |
| 53 | + /Compiled (\/[\w-]*)*\s*in \d+(\.\d+)?(s|ms) \((\d+) modules\)/g |
| 54 | + ), |
| 55 | + ] |
| 56 | + |
| 57 | + expect(modules.length).toBeGreaterThanOrEqual(1) |
| 58 | + for (const [, , , , moduleCount] of modules) { |
| 59 | + // Ensure that the number of modules is less than 1000 - otherwise we're |
| 60 | + // importing the entire library. |
| 61 | + expect(parseInt(moduleCount)).toBeLessThan(1000) |
| 62 | + } |
| 63 | + }) |
| 64 | + |
| 65 | + it('pages - should render the icons correctly without creating all the modules', async () => { |
| 66 | + let logs = '' |
| 67 | + next.on('stdout', (log) => { |
| 68 | + logs += log |
| 69 | + }) |
| 70 | + |
| 71 | + const html = await next.render('/pages-route') |
| 72 | + |
| 73 | + // Ensure the icons are rendered |
| 74 | + expect(html).toContain('<svg xmlns="http://www.w3.org/2000/svg"') |
| 75 | + |
| 76 | + const modules = [ |
| 77 | + ...logs.matchAll( |
| 78 | + /Compiled (\/[\w-]+)*\s*in \d+(\.\d+)?(s|ms) \((\d+) modules\)/g |
| 79 | + ), |
| 80 | + ] |
| 81 | + |
| 82 | + expect(modules.length).toBeGreaterThanOrEqual(1) |
| 83 | + for (const [, , , , moduleCount] of modules) { |
| 84 | + // Ensure that the number of modules is less than 1000 - otherwise we're |
| 85 | + // importing the entire library. |
| 86 | + expect(parseInt(moduleCount)).toBeLessThan(1000) |
| 87 | + } |
| 88 | + }) |
| 89 | + |
| 90 | + it('app - should optimize recursive wildcard export mapping', async () => { |
| 91 | + let logs = '' |
| 92 | + next.on('stdout', (log) => { |
| 93 | + logs += log |
| 94 | + }) |
| 95 | + |
| 96 | + await next.render('/recursive-barrel-app') |
| 97 | + |
| 98 | + const modules = [...logs.matchAll(/\((\d+) modules\)/g)] |
| 99 | + |
| 100 | + expect(modules.length).toBeGreaterThanOrEqual(1) |
| 101 | + for (const [, moduleCount] of modules) { |
| 102 | + // Ensure that the number of modules is less than 1000 - otherwise we're |
| 103 | + // importing the entire library. |
| 104 | + expect(parseInt(moduleCount)).toBeLessThan(1000) |
| 105 | + } |
| 106 | + }) |
| 107 | + |
| 108 | + it('pages - should optimize recursive wildcard export mapping', async () => { |
| 109 | + let logs = '' |
| 110 | + next.on('stdout', (log) => { |
| 111 | + logs += log |
| 112 | + }) |
| 113 | + |
| 114 | + await next.render('/recursive-barrel') |
| 115 | + |
| 116 | + const modules = [...logs.matchAll(/\((\d+) modules\)/g)] |
| 117 | + |
| 118 | + expect(modules.length).toBeGreaterThanOrEqual(1) |
| 119 | + for (const [, moduleCount] of modules) { |
| 120 | + // Ensure that the number of modules is less than 1000 - otherwise we're |
| 121 | + // importing the entire library. |
| 122 | + expect(parseInt(moduleCount)).toBeLessThan(1000) |
| 123 | + } |
| 124 | + }) |
| 125 | + |
| 126 | + it('should handle recursive wildcard exports', async () => { |
| 127 | + const html = await next.render('/recursive') |
| 128 | + expect(html).toContain('<h1>42</h1>') |
| 129 | + }) |
| 130 | + |
| 131 | + it('should support visx', async () => { |
| 132 | + const html = await next.render('/visx') |
| 133 | + expect(html).toContain('<linearGradient') |
| 134 | + }) |
| 135 | + |
| 136 | + it('should support MUI', async () => { |
| 137 | + let logs = '' |
| 138 | + next.on('stdout', (log) => { |
| 139 | + logs += log |
| 140 | + }) |
| 141 | + |
| 142 | + // Ensure that MUI is working |
| 143 | + const $ = await next.render$('/mui') |
| 144 | + expect(await $('#button').text()).toContain('button') |
| 145 | + expect(await $('#typography').text()).toContain('typography') |
| 146 | + |
| 147 | + const browser = await next.browser('/mui') |
| 148 | + expect(await hasRedbox(browser)).toBe(false) |
| 149 | + |
| 150 | + const modules = [...logs.matchAll(/\((\d+) modules\)/g)] |
| 151 | + expect(modules.length).toBeGreaterThanOrEqual(1) |
| 152 | + for (const [, moduleCount] of modules) { |
| 153 | + // Ensure that the number of modules is less than 1500 - otherwise we're |
| 154 | + // importing the entire library. |
| 155 | + expect(parseInt(moduleCount)).toBeLessThan(1500) |
| 156 | + } |
| 157 | + }) |
| 158 | + |
| 159 | + it('should not break "use client" directive in optimized packages', async () => { |
| 160 | + const html = await next.render('/client') |
| 161 | + expect(html).toContain('this is a client component') |
| 162 | + }) |
| 163 | + |
| 164 | + it('should support "use client" directive in barrel file', async () => { |
| 165 | + const html = await next.render('/client-boundary') |
| 166 | + expect(html).toContain('<button>0</button>') |
| 167 | + }) |
102 | 168 | } |
103 | | - }) |
104 | | - |
105 | | - it('pages - should optimize recursive wildcard export mapping', async () => { |
106 | | - let logs = '' |
107 | | - next.on('stdout', (log) => { |
108 | | - logs += log |
109 | | - }) |
110 | | - |
111 | | - await next.render('/recursive-barrel') |
112 | | - |
113 | | - const modules = [...logs.matchAll(/\((\d+) modules\)/g)] |
114 | | - |
115 | | - expect(modules.length).toBeGreaterThanOrEqual(1) |
116 | | - for (const [, moduleCount] of modules) { |
117 | | - // Ensure that the number of modules is less than 1000 - otherwise we're |
118 | | - // importing the entire library. |
119 | | - expect(parseInt(moduleCount)).toBeLessThan(1000) |
120 | | - } |
121 | | - }) |
122 | | - |
123 | | - it('should handle recursive wildcard exports', async () => { |
124 | | - const html = await next.render('/recursive') |
125 | | - expect(html).toContain('<h1>42</h1>') |
126 | | - }) |
127 | | - |
128 | | - it('should support visx', async () => { |
129 | | - const html = await next.render('/visx') |
130 | | - expect(html).toContain('<linearGradient') |
131 | | - }) |
132 | | - |
133 | | - it('should support MUI', async () => { |
134 | | - let logs = '' |
135 | | - next.on('stdout', (log) => { |
136 | | - logs += log |
137 | | - }) |
138 | | - |
139 | | - // Ensure that MUI is working |
140 | | - const $ = await next.render$('/mui') |
141 | | - expect(await $('#button').text()).toContain('button') |
142 | | - expect(await $('#typography').text()).toContain('typography') |
143 | | - |
144 | | - const browser = await next.browser('/mui') |
145 | | - expect(await hasRedbox(browser)).toBe(false) |
146 | | - |
147 | | - const modules = [...logs.matchAll(/\((\d+) modules\)/g)] |
148 | | - expect(modules.length).toBeGreaterThanOrEqual(1) |
149 | | - for (const [, moduleCount] of modules) { |
150 | | - // Ensure that the number of modules is less than 1500 - otherwise we're |
151 | | - // importing the entire library. |
152 | | - expect(parseInt(moduleCount)).toBeLessThan(1500) |
153 | | - } |
154 | | - }) |
155 | | - |
156 | | - it('should not break "use client" directive in optimized packages', async () => { |
157 | | - const html = await next.render('/client') |
158 | | - expect(html).toContain('this is a client component') |
159 | | - }) |
160 | | - |
161 | | - it('should support "use client" directive in barrel file', async () => { |
162 | | - const html = await next.render('/client-boundary') |
163 | | - expect(html).toContain('<button>0</button>') |
164 | | - }) |
| 169 | + ) |
165 | 170 | } |
166 | 171 | ) |
0 commit comments