Skip to content

Commit 99a75ac

Browse files
authored
test(hmr): refactor live-reload tests to use temp directory (#6690)
1 parent 43144d2 commit 99a75ac

File tree

1 file changed

+22
-17
lines changed

1 file changed

+22
-17
lines changed

e2e/cases/hmr/live-reload/index.test.ts

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
1-
import fs from 'node:fs';
21
import path from 'node:path';
3-
import { expect, rspackTest, test } from '@e2e/helper';
4-
5-
const appFile = path.join(import.meta.dirname, 'src/App.jsx');
6-
let appCode: string;
7-
8-
test.beforeEach(() => {
9-
appCode = fs.readFileSync(appFile, 'utf-8');
10-
});
11-
12-
test.afterEach(() => {
13-
// recover the source code
14-
fs.writeFileSync(appFile, appCode, 'utf-8');
15-
});
2+
import { expect, rspackTest } from '@e2e/helper';
163

174
rspackTest(
185
'should fallback to live-reload when dev.hmr is false',
19-
async ({ page, dev, editFile }) => {
20-
await dev();
6+
async ({ page, dev, editFile, copySrcDir }) => {
7+
const tempSrc = await copySrcDir();
8+
const appFile = path.join(tempSrc, 'App.jsx');
9+
await dev({
10+
config: {
11+
source: {
12+
entry: {
13+
index: path.join(tempSrc, 'index.js'),
14+
},
15+
},
16+
},
17+
});
18+
2119
const testEl = page.locator('#test');
2220
await expect(testEl).toHaveText('Hello Rsbuild!');
2321
await editFile(appFile, (code) => code.replace('Rsbuild', 'Live Reload'));
@@ -27,9 +25,16 @@ rspackTest(
2725

2826
rspackTest(
2927
'should not reload page when live-reload is disabled',
30-
async ({ page, dev, editFile }) => {
28+
async ({ page, dev, editFile, copySrcDir }) => {
29+
const tempSrc = await copySrcDir();
30+
const appFile = path.join(tempSrc, 'App.jsx');
3131
await dev({
3232
config: {
33+
source: {
34+
entry: {
35+
index: path.join(tempSrc, 'index.js'),
36+
},
37+
},
3338
dev: {
3439
liveReload: false,
3540
},

0 commit comments

Comments
 (0)