|
| 1 | +import { expect, test } from "@playwright/test"; |
| 2 | +import { |
| 3 | + setupDevServer, |
| 4 | + setupBuildAndPreview, |
| 5 | + setupWaitForLogs, |
| 6 | + rgbToHex, |
| 7 | +} from "../../utils"; |
| 8 | + |
| 9 | +test("Emotion build", async ({ page }) => { |
| 10 | + const { testUrl, server } = await setupBuildAndPreview("emotion"); |
| 11 | + await page.goto(testUrl); |
| 12 | + |
| 13 | + const button = page.locator("button"); |
| 14 | + await button.hover(); |
| 15 | + await expect( |
| 16 | + rgbToHex(await button.evaluate((el) => getComputedStyle(el).color)), |
| 17 | + ).toBe("#646cff"); |
| 18 | + |
| 19 | + await button.click(); |
| 20 | + await expect(button).toHaveText("count is 1"); |
| 21 | + |
| 22 | + await server.httpServer.close(); |
| 23 | +}); |
| 24 | + |
| 25 | +test("Emotion HMR", async ({ page }) => { |
| 26 | + const { testUrl, server, editFile } = await setupDevServer("emotion"); |
| 27 | + const waitForLogs = await setupWaitForLogs(page); |
| 28 | + await page.goto(testUrl); |
| 29 | + await waitForLogs("[vite] connected."); |
| 30 | + |
| 31 | + const button = page.locator("button"); |
| 32 | + await button.hover(); |
| 33 | + await expect( |
| 34 | + rgbToHex(await button.evaluate((el) => getComputedStyle(el).color)), |
| 35 | + ).toBe("#646cff"); |
| 36 | + |
| 37 | + await button.click(); |
| 38 | + await expect(button).toHaveText("count is 1"); |
| 39 | + |
| 40 | + editFile("src/Button.tsx", [ |
| 41 | + "background-color: #d26ac2;", |
| 42 | + "background-color: #646cff;", |
| 43 | + ]); |
| 44 | + await waitForLogs("[vite] hot updated: /src/Button.tsx"); |
| 45 | + await expect(button).toHaveText("count is 1"); |
| 46 | + await expect( |
| 47 | + rgbToHex( |
| 48 | + await button.evaluate((el) => getComputedStyle(el).backgroundColor), |
| 49 | + ), |
| 50 | + ).toBe("#646cff"); |
| 51 | + |
| 52 | + editFile("src/App.tsx", ['color="#646cff"', 'color="#d26ac2"']); |
| 53 | + await waitForLogs("[vite] hot updated: /src/App.tsx"); |
| 54 | + await expect(button).toHaveText("count is 1"); |
| 55 | + await expect( |
| 56 | + rgbToHex(await button.evaluate((el) => getComputedStyle(el).color)), |
| 57 | + ).toBe("#d26ac2"); |
| 58 | + |
| 59 | + await server.close(); |
| 60 | +}); |
0 commit comments