|
| 1 | +import { test, expect } from "@playwright/test"; |
| 2 | +import { withTestEnv } from "next-yak-e2e"; |
| 3 | + |
| 4 | +test( |
| 5 | + "HMR recovers after a syntax error in a .yak.ts dependency", |
| 6 | + withTestEnv("hmr-yak-syntax-error-recovery", async (fsTmp, page) => { |
| 7 | + await page.goto(fsTmp.url); |
| 8 | + |
| 9 | + const box = page.getByTestId("box"); |
| 10 | + await expect(box).toHaveCSS("padding", "40px"); |
| 11 | + await expect(box).toHaveCSS("color", "rgb(0, 128, 128)"); |
| 12 | + |
| 13 | + // Set marker to detect full page reloads |
| 14 | + await page.evaluate(() => { |
| 15 | + window.__hmr = true; |
| 16 | + }); |
| 17 | + |
| 18 | + // Introduce a syntax error in the .yak.ts file |
| 19 | + await fsTmp.writeFile( |
| 20 | + "tokens.yak.ts", |
| 21 | + "export const spacing = 5 * 8;\nexport const brand = <<<BROKEN>>>;\n", |
| 22 | + ); |
| 23 | + |
| 24 | + // Wait for the error to propagate |
| 25 | + await page.waitForTimeout(3_000); |
| 26 | + |
| 27 | + // Fix the syntax error with new values |
| 28 | + await fsTmp.writeFile( |
| 29 | + "tokens.yak.ts", |
| 30 | + 'export const spacing = 2 * 8;\nexport const brand = "red";\n', |
| 31 | + ); |
| 32 | + |
| 33 | + // After recovery, the new values should be applied |
| 34 | + await expect(box).toHaveCSS("padding", "16px", { timeout: 15_000 }); |
| 35 | + await expect(box).toHaveCSS("color", "rgb(255, 0, 0)"); |
| 36 | + |
| 37 | + // Verify no full page reload occurred |
| 38 | + expect(await page.evaluate(() => window.__hmr)).toBe(true); |
| 39 | + }), |
| 40 | +); |
0 commit comments