Skip to content

Commit

Permalink
test(e2e): avoid writing temp files to git
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiahan committed Oct 26, 2024
1 parent a0939d8 commit 5e8b90e
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 33 deletions.
19 changes: 14 additions & 5 deletions e2e/cases/preact/prefresh-disabled/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ rspackOnlyTest('HMR should work properly', async ({ page }) => {
}

const root = __dirname;
const compFilePath = path.join(root, 'src/test-temp-B.jsx');
const compSourceCode = `const B = (props) => {
return <div id="B">B: {props.count}</div>;
};
export default B;
`;

fs.writeFileSync(compFilePath, compSourceCode, 'utf-8');

const rsbuild = await dev({
cwd: root,
Expand All @@ -27,9 +36,11 @@ rspackOnlyTest('HMR should work properly', async ({ page }) => {
await expect(b).toHaveText('B: 5');

// simulate a change to component B's source code
const filePath = path.join(root, 'src/B.jsx');
const sourceCodeB = fs.readFileSync(filePath, 'utf-8');
fs.writeFileSync(filePath, sourceCodeB.replace('B:', 'Beep:'), 'utf-8');
fs.writeFileSync(
compFilePath,
compSourceCode.replace('B:', 'Beep:'),
'utf-8',
);

await page.waitForFunction(() => {
const aText = document.querySelector('#A')!.textContent;
Expand All @@ -43,7 +54,5 @@ rspackOnlyTest('HMR should work properly', async ({ page }) => {
);
});

// recover the source code
fs.writeFileSync(filePath, sourceCodeB, 'utf-8');
await rsbuild.close();
});
2 changes: 1 addition & 1 deletion e2e/cases/preact/prefresh-disabled/src/A.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useState } from 'preact/hooks';
import B from './B';
import B from './test-temp-B';

const App = () => {
const [count, setCount] = useState(0);
Expand Down
5 changes: 0 additions & 5 deletions e2e/cases/preact/prefresh-disabled/src/B.jsx

This file was deleted.

19 changes: 14 additions & 5 deletions e2e/cases/preact/prefresh/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ rspackOnlyTest('HMR should work properly', async ({ page }) => {
}

const root = __dirname;
const compFilePath = path.join(root, 'src/test-temp-B.jsx');
const compSourceCode = `const B = (props) => {
return <div id="B">B: {props.count}</div>;
};
export default B;
`;

fs.writeFileSync(compFilePath, compSourceCode, 'utf-8');

const rsbuild = await dev({
cwd: root,
Expand All @@ -27,9 +36,11 @@ rspackOnlyTest('HMR should work properly', async ({ page }) => {
await expect(b).toHaveText('B: 5');

// simulate a change to component B's source code
const filePath = path.join(root, 'src/B.jsx');
const sourceCodeB = fs.readFileSync(filePath, 'utf-8');
fs.writeFileSync(filePath, sourceCodeB.replace('B:', 'Beep:'), 'utf-8');
fs.writeFileSync(
compFilePath,
compSourceCode.replace('B:', 'Beep:'),
'utf-8',
);

await page.waitForFunction(() => {
const aText = document.querySelector('#A')!.textContent;
Expand All @@ -43,7 +54,5 @@ rspackOnlyTest('HMR should work properly', async ({ page }) => {
);
});

// recover the source code
fs.writeFileSync(filePath, sourceCodeB, 'utf-8');
await rsbuild.close();
});
2 changes: 1 addition & 1 deletion e2e/cases/preact/prefresh/src/A.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useState } from 'preact/hooks';
import B from './B';
import B from './test-temp-B';

const App = () => {
const [count, setCount] = useState(0);
Expand Down
5 changes: 0 additions & 5 deletions e2e/cases/preact/prefresh/src/B.jsx

This file was deleted.

19 changes: 14 additions & 5 deletions e2e/cases/solid/hmr/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ rspackOnlyTest('HMR should work properly', async ({ page }) => {
}

const root = __dirname;
const compFilePath = path.join(root, 'src/test-temp-B.jsx');
const compSourceCode = `const B = (props) => {
return <div id="B">B: {props.count()}</div>;
};
export default B;
`;

fs.writeFileSync(compFilePath, compSourceCode, 'utf-8');

const rsbuild = await dev({
cwd: root,
Expand All @@ -27,9 +36,11 @@ rspackOnlyTest('HMR should work properly', async ({ page }) => {
await expect(b).toHaveText('B: 5');

// simulate a change to component B's source code
const filePath = path.join(root, 'src/B.jsx');
const sourceCodeB = fs.readFileSync(filePath, 'utf-8');
fs.writeFileSync(filePath, sourceCodeB.replace('B:', 'Beep:'), 'utf-8');
fs.writeFileSync(
compFilePath,
compSourceCode.replace('B:', 'Beep:'),
'utf-8',
);

await page.waitForFunction(() => {
const aText = document.querySelector('#A')!.textContent;
Expand All @@ -43,7 +54,5 @@ rspackOnlyTest('HMR should work properly', async ({ page }) => {
);
});

// recover the source code
fs.writeFileSync(filePath, sourceCodeB, 'utf-8');
await rsbuild.close();
});
2 changes: 1 addition & 1 deletion e2e/cases/solid/hmr/src/A.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createSignal } from 'solid-js';
import B from './B';
import B from './test-temp-B';

const App = () => {
const [count, setCount] = createSignal(0);
Expand Down
5 changes: 0 additions & 5 deletions e2e/cases/solid/hmr/src/B.jsx

This file was deleted.

0 comments on commit 5e8b90e

Please sign in to comment.