Skip to content

Commit 1c05552

Browse files
authored
test(e2e): add react-component example test (#239)
1 parent 6d92cf4 commit 1c05552

File tree

13 files changed

+244
-9
lines changed

13 files changed

+244
-9
lines changed

.github/workflows/test-ubuntu.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,12 @@ jobs:
103103
if: steps.changes.outputs.changed == 'true'
104104
run: pnpm run test:artifact
105105

106-
- name: E2E Test (Playwright)
107-
if: steps.changes.outputs.changed == 'true'
108-
run: pnpm run test:e2e
109-
110106
- name: Examples Test
111107
if: steps.changes.outputs.changed == 'true'
112108
run: |
113109
pnpm run build:examples
110+
111+
- name: E2E Test (Playwright)
112+
if: steps.changes.outputs.changed == 'true'
113+
run: pnpm run test:e2e
114+

.github/workflows/test-windows.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,10 @@ jobs:
112112
if: steps.changes.outputs.changed == 'true'
113113
run: pnpm run test:artifact
114114

115-
- name: E2E Test (Playwright)
116-
if: steps.changes.outputs.changed == 'true'
117-
run: pnpm run test:e2e
118-
119115
- name: Examples Test
120116
if: steps.changes.outputs.changed == 'true'
121117
run: pnpm run build:examples
118+
119+
- name: E2E Test (Playwright)
120+
if: steps.changes.outputs.changed == 'true'
121+
run: pnpm run test:e2e
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { dev } from '@e2e/helper/rsbuild';
2+
import { expect, test } from '@playwright/test';
3+
4+
test('should render example "react-component" successfully', async ({
5+
page,
6+
}) => {
7+
const rsbuild = await dev({
8+
cwd: __dirname,
9+
page,
10+
});
11+
12+
const h2El = page.locator('h2');
13+
await expect(h2El).toHaveText('Counter: 0');
14+
15+
const buttonEl = page.locator('#root button');
16+
17+
const [subtractEl, addEl] = await buttonEl.all();
18+
19+
await expect(h2El).toHaveText('Counter: 0');
20+
addEl?.click();
21+
await expect(h2El).toHaveText('Counter: 1');
22+
subtractEl?.click();
23+
await expect(h2El).toHaveText('Counter: 0');
24+
25+
await rsbuild.close();
26+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "react-component-e2e",
3+
"version": "1.0.0",
4+
"private": true
5+
}
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: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { Counter } from '@examples/react-component';
2+
3+
const App = () => (
4+
<div>
5+
<Counter />
6+
</div>
7+
);
8+
9+
export default App;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import React from 'react';
2+
import ReactDOM from 'react-dom/client';
3+
import App from './App';
4+
5+
const root = ReactDOM.createRoot(document.getElementById('root')!);
6+
root.render(
7+
<React.StrictMode>
8+
<App />
9+
</React.StrictMode>,
10+
);
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"compilerOptions": {
3+
"target": "ES2020",
4+
"lib": ["DOM", "ES2020"],
5+
"module": "ESNext",
6+
"jsx": "react-jsx",
7+
"strict": true,
8+
"skipLibCheck": true,
9+
"isolatedModules": true,
10+
"resolveJsonModule": true,
11+
"moduleResolution": "bundler",
12+
"useDefineForClassFields": true
13+
},
14+
"include": ["src"]
15+
}

e2e/package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,21 @@
66
"test": "playwright test --pass-with-no-tests"
77
},
88
"dependencies": {
9-
"react": "^18.3.1"
9+
"@examples/react-component": "workspace:*",
10+
"react": "^18.3.1",
11+
"react-dom": "^18.3.1"
1012
},
1113
"devDependencies": {
1214
"@e2e/helper": "workspace:*",
1315
"@playwright/test": "1.47.2",
1416
"@rsbuild/core": "1.0.7",
17+
"@rsbuild/plugin-react": "1.0.2",
1518
"@rslib/core": "workspace:*",
1619
"@rslib/tsconfig": "workspace:*",
1720
"@types/fs-extra": "^11.0.4",
1821
"@types/node": "~18.19.39",
1922
"@types/react": "^18.3.9",
23+
"@types/react-dom": "^18.3.0",
2024
"fast-glob": "^3.3.2",
2125
"fs-extra": "^11.2.0",
2226
"path-serializer": "0.0.6",

e2e/playwright.config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,8 @@ import { defineConfig } from '@playwright/test';
33
export default defineConfig({
44
// Playwright test files with `.pw.` to distinguish from Vitest test files
55
testMatch: /.*pw.(test|spec).(js|ts|mjs)/,
6+
// Retry on CI
7+
retries: process.env.CI ? 3 : 0,
8+
// Print line for each test being run in CI
9+
reporter: 'list',
610
});

0 commit comments

Comments
 (0)