@@ -231,6 +231,71 @@ if (isBuild) {
231231 await expect . poll ( ( ) => page . textContent ( '.worker-url' ) ) . toBe ( 'worker-url' )
232232 } )
233233
234+ // The importer self-accepts, so this update arrives as an HMR patch. A patch
235+ // skips the generate phase, so without the worker files being emitted earlier
236+ // it ships a URL for a file that was never written.
237+ test ( 'worker updated through an HMR patch is served' , async ( ) => {
238+ const original = readFile ( 'worker-accept-src.js' )
239+ onTestFinished ( async ( ) => {
240+ addFile ( 'worker-accept-src.js' , original )
241+ await expect
242+ . poll ( ( ) => page . textContent ( '.worker-accept' ) )
243+ . toBe ( 'worker-accept' )
244+ } )
245+
246+ await expect
247+ . poll ( ( ) => page . textContent ( '.worker-accept' ) )
248+ . toBe ( 'worker-accept' )
249+
250+ // survives an HMR patch, but not a page reload
251+ await page . evaluate ( ( ) => {
252+ ; ( window as any ) . __workerAcceptKeptAlive = true
253+ } )
254+
255+ editFile ( 'worker-accept-src.js' , ( code ) =>
256+ code . replace ( "'worker-accept'" , "'worker-accept-updated'" ) ,
257+ )
258+ await expect
259+ . poll ( ( ) => page . textContent ( '.worker-accept' ) )
260+ . toBe ( 'worker-accept-updated' )
261+
262+ expect (
263+ await page . evaluate ( ( ) => ( window as any ) . __workerAcceptKeptAlive ) ,
264+ ) . toBe ( true )
265+ } )
266+
267+ // The inner worker is bundled on its own, so a patch that emits only the
268+ // worker it just resolved leaves one of the two files unserved.
269+ test ( 'nested worker updated through an HMR patch is served' , async ( ) => {
270+ const original = readFile ( 'worker-nested-inner.js' )
271+ onTestFinished ( async ( ) => {
272+ addFile ( 'worker-nested-inner.js' , original )
273+ await expect
274+ . poll ( ( ) => page . textContent ( '.worker-nested' ) )
275+ . toBe ( 'nested-outer+nested-inner' )
276+ } )
277+
278+ await expect
279+ . poll ( ( ) => page . textContent ( '.worker-nested' ) )
280+ . toBe ( 'nested-outer+nested-inner' )
281+
282+ // survives an HMR patch, but not a page reload
283+ await page . evaluate ( ( ) => {
284+ ; ( window as any ) . __workerNestedKeptAlive = true
285+ } )
286+
287+ editFile ( 'worker-nested-inner.js' , ( code ) =>
288+ code . replace ( "'nested-inner'" , "'nested-inner-updated'" ) ,
289+ )
290+ await expect
291+ . poll ( ( ) => page . textContent ( '.worker-nested' ) )
292+ . toBe ( 'nested-outer+nested-inner-updated' )
293+
294+ expect (
295+ await page . evaluate ( ( ) => ( window as any ) . __workerNestedKeptAlive ) ,
296+ ) . toBe ( true )
297+ } )
298+
234299 test ( 'lazy bundling' , async ( ) => {
235300 await page . click ( '#load-dynamic' )
236301 await expect . poll ( ( ) => page . textContent ( '.dynamic' ) ) . toBe ( 'loaded' )
0 commit comments