|
| 1 | +import fs from 'node:fs'; |
| 2 | +import { join } from 'node:path'; |
| 3 | +import { dev, proxyConsole, rspackOnlyTest, waitFor } from '@e2e/helper'; |
| 4 | +import { expect, test } from '@playwright/test'; |
| 5 | + |
| 6 | +const cwd = __dirname; |
| 7 | + |
| 8 | +rspackOnlyTest( |
| 9 | + 'HMR should work after fixing compilation error', |
| 10 | + async ({ page }) => { |
| 11 | + if (process.platform === 'win32') { |
| 12 | + test.skip(); |
| 13 | + } |
| 14 | + |
| 15 | + await fs.promises.cp(join(cwd, 'src'), join(cwd, 'test-temp-src'), { |
| 16 | + recursive: true, |
| 17 | + }); |
| 18 | + |
| 19 | + const { logs, restore } = proxyConsole(); |
| 20 | + |
| 21 | + const rsbuild = await dev({ |
| 22 | + cwd, |
| 23 | + page, |
| 24 | + rsbuildConfig: { |
| 25 | + source: { |
| 26 | + entry: { |
| 27 | + index: join(cwd, 'test-temp-src/index.ts'), |
| 28 | + }, |
| 29 | + }, |
| 30 | + }, |
| 31 | + }); |
| 32 | + |
| 33 | + const locator = page.locator('#test'); |
| 34 | + await expect(locator).toHaveText('Hello Rsbuild!'); |
| 35 | + |
| 36 | + const appPath = join(cwd, 'test-temp-src/App.tsx'); |
| 37 | + |
| 38 | + await fs.promises.writeFile( |
| 39 | + appPath, |
| 40 | + fs |
| 41 | + .readFileSync(appPath, 'utf-8') |
| 42 | + .replace( |
| 43 | + '<div id="test">Hello Rsbuild!</div>', |
| 44 | + '<div id="test">Hello Rsbuild!</div', |
| 45 | + ), |
| 46 | + ); |
| 47 | + |
| 48 | + expect( |
| 49 | + await waitFor(() => |
| 50 | + logs.some((log) => log.includes('Module build failed')), |
| 51 | + ), |
| 52 | + ).toBeTruthy(); |
| 53 | + |
| 54 | + await fs.promises.writeFile( |
| 55 | + appPath, |
| 56 | + fs |
| 57 | + .readFileSync(appPath, 'utf-8') |
| 58 | + .replace( |
| 59 | + '<div id="test">Hello Rsbuild!</div', |
| 60 | + '<div id="test">Hello Rsbuild2!</div>', |
| 61 | + ), |
| 62 | + ); |
| 63 | + |
| 64 | + await expect(locator).toHaveText('Hello Rsbuild2!'); |
| 65 | + await rsbuild.close(); |
| 66 | + |
| 67 | + restore(); |
| 68 | + }, |
| 69 | +); |
0 commit comments