Skip to content

Commit d670496

Browse files
authored
test(e2e): add HMR error handling test case (#4685)
1 parent 7fec688 commit d670496

File tree

7 files changed

+99
-15
lines changed

7 files changed

+99
-15
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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+
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { defineConfig } from '@rsbuild/core';
2+
import { pluginReact } from '@rsbuild/plugin-react';
3+
4+
export default defineConfig({
5+
plugins: [pluginReact()],
6+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#test {
2+
color: rgb(255, 0, 0);
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import './App.css';
2+
3+
const App = () => <div id="test">Hello Rsbuild!</div>;
4+
export default App;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import React from 'react';
2+
import { createRoot } from 'react-dom/client';
3+
import App from './App';
4+
5+
const num = Math.ceil(Math.random() * 100);
6+
const testEl = document.createElement('div');
7+
testEl.id = 'test-keep';
8+
9+
testEl.innerHTML = String(num);
10+
11+
document.body.appendChild(testEl);
12+
13+
const container = document.getElementById('root');
14+
if (container) {
15+
const root = createRoot(container);
16+
root.render(React.createElement(App));
17+
}

e2e/cases/server/hmr/index.test.ts

-6
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,6 @@ rspackOnlyTest('HMR should work by default', async ({ page }) => {
2424
index: join(cwd, 'test-temp-src/index.ts'),
2525
},
2626
},
27-
dev: {
28-
client: {
29-
host: '',
30-
port: '',
31-
},
32-
},
3327
},
3428
});
3529

e2e/cases/server/hmr/tsconfig.json

-9
This file was deleted.

0 commit comments

Comments
 (0)