@@ -2,6 +2,7 @@ import { describe, expect, test } from 'vitest'
2
2
import {
3
3
browserErrors ,
4
4
browserLogs ,
5
+ expectWithRetry ,
5
6
getColor ,
6
7
isBuild ,
7
8
isServe ,
@@ -12,93 +13,123 @@ import {
12
13
} from '~utils'
13
14
14
15
test ( 'default + named imports from cjs dep (react)' , async ( ) => {
15
- expect ( await page . textContent ( '.cjs button' ) ) . toBe ( 'count is 0' )
16
+ await expectWithRetry ( ( ) => page . textContent ( '.cjs button' ) ) . toBe (
17
+ 'count is 0' ,
18
+ )
16
19
await page . click ( '.cjs button' )
17
- expect ( await page . textContent ( '.cjs button' ) ) . toBe ( 'count is 1' )
20
+ await expectWithRetry ( ( ) => page . textContent ( '.cjs button' ) ) . toBe (
21
+ 'count is 1' ,
22
+ )
18
23
} )
19
24
20
25
test ( 'named imports from webpacked cjs (phoenix)' , async ( ) => {
21
- expect ( await page . textContent ( '.cjs-phoenix' ) ) . toBe ( 'ok' )
26
+ await expectWithRetry ( ( ) => page . textContent ( '.cjs-phoenix' ) ) . toBe ( 'ok' )
22
27
} )
23
28
24
29
test ( 'default import from webpacked cjs (clipboard)' , async ( ) => {
25
- expect ( await page . textContent ( '.cjs-clipboard' ) ) . toBe ( 'ok' )
30
+ await expectWithRetry ( ( ) => page . textContent ( '.cjs-clipboard' ) ) . toBe ( 'ok' )
26
31
} )
27
32
28
33
test ( 'dynamic imports from cjs dep (react)' , async ( ) => {
29
- expect ( await page . textContent ( '.cjs-dynamic button' ) ) . toBe ( 'count is 0' )
34
+ await expectWithRetry ( ( ) => page . textContent ( '.cjs-dynamic button' ) ) . toBe (
35
+ 'count is 0' ,
36
+ )
30
37
await page . click ( '.cjs-dynamic button' )
31
- expect ( await page . textContent ( '.cjs-dynamic button' ) ) . toBe ( 'count is 1' )
38
+ await expectWithRetry ( ( ) => page . textContent ( '.cjs-dynamic button' ) ) . toBe (
39
+ 'count is 1' ,
40
+ )
32
41
} )
33
42
34
43
test ( 'dynamic named imports from webpacked cjs (phoenix)' , async ( ) => {
35
- expect ( await page . textContent ( '.cjs-dynamic-phoenix' ) ) . toBe ( 'ok' )
44
+ await expectWithRetry ( ( ) => page . textContent ( '.cjs-dynamic-phoenix' ) ) . toBe (
45
+ 'ok' ,
46
+ )
36
47
} )
37
48
38
49
test ( 'dynamic default import from webpacked cjs (clipboard)' , async ( ) => {
39
- expect ( await page . textContent ( '.cjs-dynamic-clipboard' ) ) . toBe ( 'ok' )
50
+ await expectWithRetry ( ( ) => page . textContent ( '.cjs-dynamic-clipboard' ) ) . toBe (
51
+ 'ok' ,
52
+ )
40
53
} )
41
54
42
55
test ( 'dynamic default import from cjs (cjs-dynamic-dep-cjs-compiled-from-esm)' , async ( ) => {
43
- expect ( await page . textContent ( '.cjs-dynamic-dep-cjs-compiled-from-esm' ) ) . toBe (
44
- 'ok' ,
45
- )
56
+ await expectWithRetry ( ( ) =>
57
+ page . textContent ( '.cjs-dynamic-dep-cjs-compiled-from-esm' ) ,
58
+ ) . toBe ( 'ok' )
46
59
} )
47
60
48
61
test ( 'dynamic default import from cjs (cjs-dynamic-dep-cjs-compiled-from-cjs)' , async ( ) => {
49
- expect ( await page . textContent ( '.cjs-dynamic-dep-cjs-compiled-from-cjs' ) ) . toBe (
50
- 'ok' ,
51
- )
62
+ await expectWithRetry ( ( ) =>
63
+ page . textContent ( '.cjs-dynamic-dep-cjs-compiled-from-cjs' ) ,
64
+ ) . toBe ( 'ok' )
52
65
} )
53
66
54
67
test ( 'dedupe' , async ( ) => {
55
- expect ( await page . textContent ( '.dedupe button' ) ) . toBe ( 'count is 0' )
68
+ await expectWithRetry ( ( ) => page . textContent ( '.dedupe button' ) ) . toBe (
69
+ 'count is 0' ,
70
+ )
56
71
await page . click ( '.dedupe button' )
57
- expect ( await page . textContent ( '.dedupe button' ) ) . toBe ( 'count is 1' )
72
+ await expectWithRetry ( ( ) => page . textContent ( '.dedupe button' ) ) . toBe (
73
+ 'count is 1' ,
74
+ )
58
75
} )
59
76
60
77
test ( 'cjs browser field (axios)' , async ( ) => {
61
- expect ( await page . textContent ( '.cjs-browser-field' ) ) . toBe ( 'pong' )
78
+ await expectWithRetry ( ( ) => page . textContent ( '.cjs-browser-field' ) ) . toBe (
79
+ 'pong' ,
80
+ )
62
81
} )
63
82
64
83
test ( 'cjs browser field bare' , async ( ) => {
65
- expect ( await page . textContent ( '.cjs-browser-field-bare' ) ) . toBe ( 'pong' )
84
+ await expectWithRetry ( ( ) => page . textContent ( '.cjs-browser-field-bare' ) ) . toBe (
85
+ 'pong' ,
86
+ )
66
87
} )
67
88
68
89
test ( 'dep from linked dep (lodash-es)' , async ( ) => {
69
- expect ( await page . textContent ( '.deps-linked' ) ) . toBe ( 'fooBarBaz' )
90
+ await expectWithRetry ( ( ) => page . textContent ( '.deps-linked' ) ) . toBe (
91
+ 'fooBarBaz' ,
92
+ )
70
93
} )
71
94
72
95
test ( 'forced include' , async ( ) => {
73
- expect ( await page . textContent ( '.force-include' ) ) . toMatch ( `[success]` )
96
+ await expectWithRetry ( ( ) => page . textContent ( '.force-include' ) ) . toMatch (
97
+ `[success]` ,
98
+ )
74
99
} )
75
100
76
101
test ( 'import * from optimized dep' , async ( ) => {
77
- expect ( await page . textContent ( '.import-star' ) ) . toMatch ( `[success]` )
102
+ await expectWithRetry ( ( ) => page . textContent ( '.import-star' ) ) . toMatch (
103
+ `[success]` ,
104
+ )
78
105
} )
79
106
80
107
test ( 'import from dep with process.env.NODE_ENV' , async ( ) => {
81
- expect ( await page . textContent ( '.node-env' ) ) . toMatch ( isBuild ? 'prod' : 'dev' )
108
+ await expectWithRetry ( ( ) => page . textContent ( '.node-env' ) ) . toMatch (
109
+ isBuild ? 'prod' : 'dev' ,
110
+ )
82
111
} )
83
112
84
113
test ( 'import from dep with .notjs files' , async ( ) => {
85
- expect ( await page . textContent ( '.not-js' ) ) . toMatch ( `[success]` )
114
+ await expectWithRetry ( ( ) => page . textContent ( '.not-js' ) ) . toMatch ( `[success]` )
86
115
} )
87
116
88
117
test ( 'Import from dependency which uses relative path which needs to be resolved by main field' , async ( ) => {
89
- expect ( await page . textContent ( '.relative-to-main' ) ) . toMatch ( `[success]` )
118
+ await expectWithRetry ( ( ) => page . textContent ( '.relative-to-main' ) ) . toMatch (
119
+ `[success]` ,
120
+ )
90
121
} )
91
122
92
123
test ( 'dep with dynamic import' , async ( ) => {
93
- expect ( await page . textContent ( '.dep-with-dynamic-import' ) ) . toMatch (
94
- `[success]` ,
95
- )
124
+ await expectWithRetry ( ( ) =>
125
+ page . textContent ( '.dep-with-dynamic-import' ) ,
126
+ ) . toMatch ( `[success]` )
96
127
} )
97
128
98
129
test ( 'dep with optional peer dep' , async ( ) => {
99
- expect ( await page . textContent ( '.dep-with-optional-peer-dep' ) ) . toMatch (
100
- `[success]` ,
101
- )
130
+ await expectWithRetry ( ( ) =>
131
+ page . textContent ( '.dep-with-optional-peer-dep' ) ,
132
+ ) . toMatch ( `[success]` )
102
133
if ( isServe ) {
103
134
expect ( browserErrors . map ( ( error ) => error . message ) ) . toEqual (
104
135
expect . arrayContaining ( [
@@ -109,8 +140,8 @@ test('dep with optional peer dep', async () => {
109
140
} )
110
141
111
142
test ( 'dep with optional peer dep submodule' , async ( ) => {
112
- expect (
113
- await page . textContent ( '.dep-with-optional-peer-dep-submodule' ) ,
143
+ expectWithRetry ( ( ) =>
144
+ page . textContent ( '.dep-with-optional-peer-dep-submodule' ) ,
114
145
) . toMatch ( `[success]` )
115
146
if ( isServe ) {
116
147
expect ( browserErrors . map ( ( error ) => error . message ) ) . toEqual (
@@ -122,61 +153,69 @@ test('dep with optional peer dep submodule', async () => {
122
153
} )
123
154
124
155
test ( 'dep with css import' , async ( ) => {
125
- expect ( await getColor ( '.dep-linked-include' ) ) . toBe ( 'red' )
156
+ await expectWithRetry ( ( ) => getColor ( '.dep-linked-include' ) ) . toBe ( 'red' )
126
157
} )
127
158
128
159
test ( 'CJS dep with css import' , async ( ) => {
129
- expect ( await getColor ( '.cjs-with-assets' ) ) . toBe ( 'blue' )
160
+ await expectWithRetry ( ( ) => getColor ( '.cjs-with-assets' ) ) . toBe ( 'blue' )
130
161
} )
131
162
132
163
test ( 'externalize known non-js files in optimize included dep' , async ( ) => {
133
- expect ( await page . textContent ( '.externalize-known-non-js' ) ) . toMatch (
134
- `[success]` ,
135
- )
164
+ await expectWithRetry ( ( ) =>
165
+ page . textContent ( '.externalize-known-non-js' ) ,
166
+ ) . toMatch ( `[success]` )
136
167
} )
137
168
138
169
test ( 'vue + vuex' , async ( ) => {
139
- expect ( await page . textContent ( '.vue' ) ) . toMatch ( `[success]` )
170
+ await expectWithRetry ( ( ) => page . textContent ( '.vue' ) ) . toMatch ( `[success]` )
140
171
} )
141
172
142
173
// When we use the Rollup CommonJS plugin instead of esbuild prebundling,
143
174
// the esbuild plugins won't apply to dependencies
144
175
test ( 'esbuild-plugin' , async ( ) => {
145
- expect ( await page . textContent ( '.esbuild-plugin' ) ) . toMatch (
176
+ await expectWithRetry ( ( ) => page . textContent ( '.esbuild-plugin' ) ) . toMatch (
146
177
`Hello from an esbuild plugin` ,
147
178
)
148
179
} )
149
180
150
181
test ( 'import from hidden dir' , async ( ) => {
151
- expect ( await page . textContent ( '.hidden-dir' ) ) . toBe ( 'hello!' )
182
+ await expectWithRetry ( ( ) => page . textContent ( '.hidden-dir' ) ) . toBe ( 'hello!' )
152
183
} )
153
184
154
185
test ( 'import optimize-excluded package that imports optimized-included package' , async ( ) => {
155
- expect ( await page . textContent ( '.nested-include' ) ) . toBe ( 'nested-include' )
186
+ await expectWithRetry ( ( ) => page . textContent ( '.nested-include' ) ) . toBe (
187
+ 'nested-include' ,
188
+ )
156
189
} )
157
190
158
191
test ( 'import aliased package with colon' , async ( ) => {
159
- expect ( await page . textContent ( '.url' ) ) . toBe ( 'vitejs.dev' )
192
+ await expectWithRetry ( ( ) => page . textContent ( '.url' ) ) . toBe ( 'vitejs.dev' )
160
193
} )
161
194
162
195
test ( 'import aliased package using absolute path' , async ( ) => {
163
- expect ( await page . textContent ( '.alias-using-absolute-path' ) ) . toBe (
164
- 'From dep- alias-using-absolute-path',
165
- )
196
+ await expectWithRetry ( ( ) =>
197
+ page . textContent ( '. alias-using-absolute-path') ,
198
+ ) . toBe ( 'From dep-alias-using-absolute-path' )
166
199
} )
167
200
168
201
test ( 'variable names are reused in different scripts' , async ( ) => {
169
- expect ( await page . textContent ( '.reused-variable-names' ) ) . toBe ( 'reused' )
202
+ await expectWithRetry ( ( ) => page . textContent ( '.reused-variable-names' ) ) . toBe (
203
+ 'reused' ,
204
+ )
170
205
} )
171
206
172
207
test ( 'flatten id should generate correctly' , async ( ) => {
173
- expect ( await page . textContent ( '.clonedeep-slash' ) ) . toBe ( 'clonedeep-slash' )
174
- expect ( await page . textContent ( '.clonedeep-dot' ) ) . toBe ( 'clonedeep-dot' )
208
+ await expectWithRetry ( ( ) => page . textContent ( '.clonedeep-slash' ) ) . toBe (
209
+ 'clonedeep-slash' ,
210
+ )
211
+ await expectWithRetry ( ( ) => page . textContent ( '.clonedeep-dot' ) ) . toBe (
212
+ 'clonedeep-dot' ,
213
+ )
175
214
} )
176
215
177
216
test ( 'non optimized module is not duplicated' , async ( ) => {
178
- expect (
179
- await page . textContent ( '.non-optimized-module-is-not-duplicated' ) ,
217
+ await expectWithRetry ( ( ) =>
218
+ page . textContent ( '.non-optimized-module-is-not-duplicated' ) ,
180
219
) . toBe ( 'from-absolute-path, from-relative-path' )
181
220
} )
182
221
@@ -227,8 +266,8 @@ test('pre bundle css require', async () => {
227
266
)
228
267
}
229
268
230
- expect ( await getColor ( '.css-require' ) ) . toBe ( 'red' )
231
- expect ( await getColor ( '.css-module-require' ) ) . toBe ( 'red' )
269
+ await expectWithRetry ( ( ) => getColor ( '.css-require' ) ) . toBe ( 'red' )
270
+ await expectWithRetry ( ( ) => getColor ( '.css-module-require' ) ) . toBe ( 'red' )
232
271
} )
233
272
234
273
test . runIf ( isBuild ) ( 'no missing deps during build' , async ( ) => {
@@ -276,5 +315,7 @@ describe.runIf(isServe)('optimizeDeps config', () => {
276
315
} )
277
316
278
317
test ( 'long file name should work' , async ( ) => {
279
- expect ( await page . textContent ( '.long-file-name' ) ) . toMatch ( `hello world` )
318
+ await expectWithRetry ( ( ) => page . textContent ( '.long-file-name' ) ) . toMatch (
319
+ `hello world` ,
320
+ )
280
321
} )
0 commit comments