Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(e2e): add HMR error handling test case #4685

Merged
merged 2 commits into from
Mar 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions e2e/cases/server/hmr-with-error/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import fs from 'node:fs';
import { join } from 'node:path';
import { dev, proxyConsole, rspackOnlyTest, waitFor } from '@e2e/helper';
import { expect, test } from '@playwright/test';

const cwd = __dirname;

rspackOnlyTest(
'HMR should work after fixing compilation error',
async ({ page }) => {
if (process.platform === 'win32') {
test.skip();
}

await fs.promises.cp(join(cwd, 'src'), join(cwd, 'test-temp-src'), {
recursive: true,
});

const { logs, restore } = proxyConsole();

const rsbuild = await dev({
cwd,
page,
rsbuildConfig: {
source: {
entry: {
index: join(cwd, 'test-temp-src/index.ts'),
},
},
},
});

const locator = page.locator('#test');
await expect(locator).toHaveText('Hello Rsbuild!');

const appPath = join(cwd, 'test-temp-src/App.tsx');

await fs.promises.writeFile(
appPath,
fs
.readFileSync(appPath, 'utf-8')
.replace(
'<div id="test">Hello Rsbuild!</div>',
'<div id="test">Hello Rsbuild!</div',
),
);

expect(
await waitFor(() =>
logs.some((log) => log.includes('Module build failed')),
),
).toBeTruthy();

await fs.promises.writeFile(
appPath,
fs
.readFileSync(appPath, 'utf-8')
.replace(
'<div id="test">Hello Rsbuild!</div',
'<div id="test">Hello Rsbuild2!</div>',
),
);

await expect(locator).toHaveText('Hello Rsbuild2!');
await rsbuild.close();

restore();
},
);
6 changes: 6 additions & 0 deletions e2e/cases/server/hmr-with-error/rsbuild.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { defineConfig } from '@rsbuild/core';
import { pluginReact } from '@rsbuild/plugin-react';

export default defineConfig({
plugins: [pluginReact()],
});
3 changes: 3 additions & 0 deletions e2e/cases/server/hmr-with-error/src/App.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#test {
color: rgb(255, 0, 0);
}
4 changes: 4 additions & 0 deletions e2e/cases/server/hmr-with-error/src/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import './App.css';

const App = () => <div id="test">Hello Rsbuild!</div>;
export default App;
17 changes: 17 additions & 0 deletions e2e/cases/server/hmr-with-error/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from 'react';
import { createRoot } from 'react-dom/client';
import App from './App';

const num = Math.ceil(Math.random() * 100);
const testEl = document.createElement('div');
testEl.id = 'test-keep';

testEl.innerHTML = String(num);

document.body.appendChild(testEl);

const container = document.getElementById('root');
if (container) {
const root = createRoot(container);
root.render(React.createElement(App));
}
6 changes: 0 additions & 6 deletions e2e/cases/server/hmr/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@ rspackOnlyTest('HMR should work by default', async ({ page }) => {
index: join(cwd, 'test-temp-src/index.ts'),
},
},
dev: {
client: {
host: '',
port: '',
},
},
},
});

Expand Down
9 changes: 0 additions & 9 deletions e2e/cases/server/hmr/tsconfig.json

This file was deleted.

Loading