@@ -318,11 +318,83 @@ function defineTest(f: Fixture) {
318318 } )
319319
320320 test ( 'shared hmr' , async ( { page } ) => {
321- // TODO:
322- // modify src/routes/hmr-shared/shared1.tsx to confirm component hmr
323- // modify src/routes/hmr-shared/shared2.tsx to confirm non-comonent hmr
324- // modify src/routes/hmr-shared/aomic/shared.tsx to confirm server/client updates are not atomic
325- page
321+ await page . goto ( f . url ( ) )
322+ await waitForHydration ( page )
323+ await using _ = await expectNoReload ( page )
324+
325+ // Test initial state
326+ await expect ( page . getByTestId ( 'test-hmr-shared-server' ) ) . toContainText (
327+ '(shared1, shared2)' ,
328+ )
329+ await expect ( page . getByTestId ( 'test-hmr-shared-client' ) ) . toContainText (
330+ '(shared1, shared2)' ,
331+ )
332+ await expect ( page . getByTestId ( 'test-hmr-shared-atomic' ) ) . toContainText (
333+ 'ok (test-shared)' ,
334+ )
335+
336+ // Test 1: Component HMR (shared1.tsx)
337+ const editor1 = f . createEditor ( 'src/routes/hmr-shared/shared1.tsx' )
338+ editor1 . edit ( ( s ) => s . replace ( 'shared1' , 'shared1-edit' ) )
339+
340+ // Verify both server and client components updated
341+ await expect ( page . getByTestId ( 'test-hmr-shared-server' ) ) . toContainText (
342+ '(shared1-edit, shared2)' ,
343+ )
344+ await expect ( page . getByTestId ( 'test-hmr-shared-client' ) ) . toContainText (
345+ '(shared1-edit, shared2)' ,
346+ )
347+
348+ editor1 . reset ( )
349+ await expect ( page . getByTestId ( 'test-hmr-shared-server' ) ) . toContainText (
350+ '(shared1, shared2)' ,
351+ )
352+ await expect ( page . getByTestId ( 'test-hmr-shared-client' ) ) . toContainText (
353+ '(shared1, shared2)' ,
354+ )
355+
356+ // Test 2: Non-component HMR (shared2.tsx)
357+ const editor2 = f . createEditor ( 'src/routes/hmr-shared/shared2.tsx' )
358+ editor2 . edit ( ( s ) => s . replace ( 'shared2' , 'shared2-edit' ) )
359+
360+ // Verify both server and client components updated
361+ await expect ( page . getByTestId ( 'test-hmr-shared-server' ) ) . toContainText (
362+ '(shared1, shared2-edit)' ,
363+ )
364+ await expect ( page . getByTestId ( 'test-hmr-shared-client' ) ) . toContainText (
365+ '(shared1, shared2-edit)' ,
366+ )
367+
368+ editor2 . reset ( )
369+ await expect ( page . getByTestId ( 'test-hmr-shared-server' ) ) . toContainText (
370+ '(shared1, shared2)' ,
371+ )
372+ await expect ( page . getByTestId ( 'test-hmr-shared-client' ) ) . toContainText (
373+ '(shared1, shared2)' ,
374+ )
375+
376+ // Test 3: Atomic updates (atomic/shared.tsx)
377+ // This tests if server/client updates are atomic or if there can be temporary mismatches
378+ const editor3 = f . createEditor ( 'src/routes/hmr-shared/atomic/shared.tsx' )
379+ editor3 . edit ( ( s ) => s . replace ( 'test-shared' , 'test-shared-edit' ) )
380+
381+ // The atomic test should either:
382+ // 1. Update atomically and show "ok (test-shared-edit)" immediately
383+ // 2. Show a temporary error if updates are not atomic, then recover
384+ await expect ( async ( ) => {
385+ const text = await page
386+ . getByTestId ( 'test-hmr-shared-atomic' )
387+ . textContent ( )
388+ // Should eventually show either the updated value or recover from error
389+ expect ( text ) . toMatch ( / o k \( t e s t - s h a r e d - e d i t \) | E r r o r B o u n d a r y c a u g h t / )
390+ } ) . toPass ( { timeout : 5000 } )
391+
392+ // Wait a bit longer to see if it recovers to the correct state
393+ await page . waitForTimeout ( 1000 )
394+ await expect ( page . getByText ( 'ok (test-shared-edit)' ) ) . toBeVisible ( )
395+
396+ editor3 . reset ( )
397+ await expect ( page . getByText ( 'ok (test-shared)' ) ) . toBeVisible ( )
326398 } )
327399 } )
328400
0 commit comments