@@ -3,8 +3,6 @@ import { retry, waitFor } from 'next-test-utils'
3
3
4
4
const envFile = '.env.development.local'
5
5
6
- const isPPREnabledByDefault = process . env . __NEXT_EXPERIMENTAL_PPR === 'true'
7
-
8
6
describe ( `app-dir-hmr` , ( ) => {
9
7
const { next } = nextTestSetup ( {
10
8
files : __dirname ,
@@ -73,58 +71,67 @@ describe(`app-dir-hmr`, () => {
73
71
const fastRefreshLogs = logs . filter ( ( log ) => {
74
72
return log . message . startsWith ( '[Fast Refresh]' )
75
73
} )
76
- // FIXME: 3+ "rebuilding" but single "done" is confusing.
74
+ // FIXME: 3+ "rebuilding" but no "done" is confusing.
77
75
// There may actually be more "rebuilding" but not reliably.
78
76
// To ignore this flakiness, we just assert on subset matches.
79
77
// Once the bug is fixed, each "rebuilding" should be paired with a "done in" exactly.
80
78
expect ( fastRefreshLogs ) . toEqual (
81
79
expect . arrayContaining ( [
82
80
{ source : 'log' , message : '[Fast Refresh] rebuilding' } ,
83
81
{ source : 'log' , message : '[Fast Refresh] rebuilding' } ,
84
- {
85
- source : 'log' ,
86
- message : expect . stringContaining ( '[Fast Refresh] done in ' ) ,
87
- } ,
88
82
{ source : 'log' , message : '[Fast Refresh] rebuilding' } ,
89
83
] )
90
84
)
85
+ // FIXME: Turbopack should have matching "done in" for each "rebuilding"
86
+ expect ( logs ) . not . toEqual (
87
+ expect . arrayContaining ( [
88
+ expect . objectContaining ( {
89
+ message : expect . stringContaining ( '[Fast Refresh] done in' ) ,
90
+ source : 'log' ,
91
+ } ) ,
92
+ ] )
93
+ )
91
94
} )
92
95
} else {
93
96
await retry (
94
97
async ( ) => {
95
- const fastRefreshLogs = logs . filter ( ( log ) => {
96
- return log . message . startsWith ( '[Fast Refresh]' )
98
+ const envValue = await browser . elementByCss ( 'p' ) . text ( )
99
+ const mpa = await browser . eval (
100
+ 'window.__TEST_NO_RELOAD === undefined'
101
+ )
102
+ // Used to be flaky but presumably no longer is.
103
+ // If this flakes again, please add the received value as a commnet.
104
+ expect ( { envValue, mpa } ) . toEqual ( {
105
+ envValue : 'ipad' ,
106
+ mpa : false ,
97
107
} )
98
- // FIXME: Should be either a single "rebuilding"+"done" or the last "rebuilding" should be followed by "done"
99
- expect ( fastRefreshLogs ) . toEqual ( [
100
- { source : 'log' , message : '[Fast Refresh] rebuilding' } ,
101
- { source : 'log' , message : '[Fast Refresh] rebuilding' } ,
102
- {
103
- source : 'log' ,
104
- message : expect . stringContaining ( '[Fast Refresh] done in ' ) ,
105
- } ,
106
- { source : 'log' , message : '[Fast Refresh] rebuilding' } ,
107
- ] )
108
108
} ,
109
109
// Very slow Hot Update for some reason.
110
110
// May be related to receiving 3 rebuild events but only one finish event
111
111
5000
112
112
)
113
+
114
+ const fastRefreshLogs = logs . filter ( ( log ) => {
115
+ return log . message . startsWith ( '[Fast Refresh]' )
116
+ } )
117
+ expect ( fastRefreshLogs ) . toEqual ( [
118
+ { source : 'log' , message : '[Fast Refresh] rebuilding' } ,
119
+ {
120
+ source : 'log' ,
121
+ message : expect . stringContaining ( '[Fast Refresh] done in ' ) ,
122
+ } ,
123
+ { source : 'log' , message : '[Fast Refresh] rebuilding' } ,
124
+ { source : 'log' , message : '[Fast Refresh] rebuilding' } ,
125
+ {
126
+ source : 'log' ,
127
+ message : expect . stringContaining ( '[Fast Refresh] done in ' ) ,
128
+ } ,
129
+ {
130
+ source : 'log' ,
131
+ message : expect . stringContaining ( '[Fast Refresh] done in ' ) ,
132
+ } ,
133
+ ] )
113
134
}
114
- const envValue = await browser . elementByCss ( 'p' ) . text ( )
115
- const mpa = await browser . eval ( 'window.__TEST_NO_RELOAD === undefined' )
116
- // Flaky sometimes in Webpack:
117
- // A. misses update and just receives `{ envValue: 'mac', mpa: false }`
118
- // B. triggers error on server resulting in MPA: `{ envValue: 'ipad', mpa: true }` and server logs: ⨯ [TypeError: Cannot read properties of undefined (reading 'polyfillFiles')] ⨯ [TypeError: Cannot read properties of null (reading 'default')]
119
- // A is more common than B.
120
- expect ( { envValue, mpa } ) . toEqual ( {
121
- envValue :
122
- isPPREnabledByDefault && ! process . env . TURBOPACK
123
- ? // FIXME: Should be 'ipad' but PPR+Webpack swallows the update reliably
124
- 'mac'
125
- : 'ipad' ,
126
- mpa : false ,
127
- } )
128
135
} finally {
129
136
await next . patchFile ( envFile , envContent )
130
137
}
@@ -158,14 +165,26 @@ describe(`app-dir-hmr`, () => {
158
165
expect ( await browser . elementByCss ( 'p' ) . text ( ) ) . toBe ( 'ipad' )
159
166
} )
160
167
161
- expect ( logs ) . toEqual (
162
- expect . arrayContaining ( [
163
- expect . objectContaining ( {
164
- message : expect . stringContaining ( '[Fast Refresh] done in' ) ,
165
- source : 'log' ,
166
- } ) ,
167
- ] )
168
- )
168
+ if ( process . env . TURBOPACK ) {
169
+ // FIXME: Turbopack should have matching "done in" for each "rebuilding"
170
+ expect ( logs ) . not . toEqual (
171
+ expect . arrayContaining ( [
172
+ expect . objectContaining ( {
173
+ message : expect . stringContaining ( '[Fast Refresh] done in' ) ,
174
+ source : 'log' ,
175
+ } ) ,
176
+ ] )
177
+ )
178
+ } else {
179
+ expect ( logs ) . toEqual (
180
+ expect . arrayContaining ( [
181
+ expect . objectContaining ( {
182
+ message : expect . stringContaining ( '[Fast Refresh] done in' ) ,
183
+ source : 'log' ,
184
+ } ) ,
185
+ ] )
186
+ )
187
+ }
169
188
} finally {
170
189
await next . patchFile ( envFile , envContent )
171
190
}
@@ -198,14 +217,26 @@ describe(`app-dir-hmr`, () => {
198
217
expect ( await browser . elementByCss ( 'p' ) . text ( ) ) . toBe ( 'ipad' )
199
218
} )
200
219
201
- expect ( logs ) . toEqual (
202
- expect . arrayContaining ( [
203
- expect . objectContaining ( {
204
- message : expect . stringContaining ( '[Fast Refresh] done in' ) ,
205
- source : 'log' ,
206
- } ) ,
207
- ] )
208
- )
220
+ if ( process . env . TURBOPACK ) {
221
+ // FIXME: Turbopack should have matching "done in" for each "rebuilding"
222
+ expect ( logs ) . not . toEqual (
223
+ expect . arrayContaining ( [
224
+ expect . objectContaining ( {
225
+ message : expect . stringContaining ( '[Fast Refresh] done in' ) ,
226
+ source : 'log' ,
227
+ } ) ,
228
+ ] )
229
+ )
230
+ } else {
231
+ expect ( logs ) . toEqual (
232
+ expect . arrayContaining ( [
233
+ expect . objectContaining ( {
234
+ message : expect . stringContaining ( '[Fast Refresh] done in' ) ,
235
+ source : 'log' ,
236
+ } ) ,
237
+ ] )
238
+ )
239
+ }
209
240
} finally {
210
241
await next . patchFile ( envFile , envContent )
211
242
}
0 commit comments