Skip to content

Commit ada844f

Browse files
authored
test(e2e): add HMR reconnect test case (#6045)
1 parent 00075e9 commit ada844f

File tree

4 files changed

+67
-0
lines changed

4 files changed

+67
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import fs from 'node:fs';
2+
import { join } from 'node:path';
3+
import { dev, rspackOnlyTest } from '@e2e/helper';
4+
import { expect } from '@playwright/test';
5+
6+
const cwd = __dirname;
7+
8+
rspackOnlyTest(
9+
'should reconnect Web Socket server as expected',
10+
async ({ page }) => {
11+
await fs.promises.cp(join(cwd, 'src'), join(cwd, 'test-temp-src'), {
12+
recursive: true,
13+
});
14+
15+
const entry = {
16+
index: join(cwd, 'test-temp-src/index.ts'),
17+
};
18+
19+
const rsbuild = await dev({
20+
cwd,
21+
page,
22+
rsbuildConfig: {
23+
source: { entry },
24+
},
25+
});
26+
27+
const locator = page.locator('#test');
28+
await expect(locator).toHaveText('Hello Rsbuild!');
29+
30+
const { port } = rsbuild;
31+
await rsbuild.close();
32+
33+
const rsbuild2 = await dev({
34+
cwd,
35+
rsbuildConfig: {
36+
server: { port },
37+
source: { entry },
38+
},
39+
});
40+
41+
const appPath = join(cwd, 'test-temp-src/App.tsx');
42+
await fs.promises.writeFile(
43+
appPath,
44+
fs.readFileSync(appPath, 'utf-8').replace('Hello Rsbuild', 'Hello Test'),
45+
);
46+
await expect(locator).toHaveText('Hello Test!');
47+
48+
await rsbuild2.close();
49+
},
50+
);
Lines changed: 6 additions & 0 deletions
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+
});
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
const App = () => <div id="test">Hello Rsbuild!</div>;
2+
export default App;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import React from 'react';
2+
import { createRoot } from 'react-dom/client';
3+
import App from './App';
4+
5+
const container = document.getElementById('root');
6+
if (container) {
7+
const root = createRoot(container);
8+
root.render(React.createElement(App));
9+
}

0 commit comments

Comments
 (0)