Skip to content

Commit 3232aa6

Browse files
committed
test: add e2e test
1 parent f22f9fd commit 3232aa6

File tree

7 files changed

+88
-21
lines changed

7 files changed

+88
-21
lines changed

examples/react-component-bundle/rslib.config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ export default defineConfig({
1616
output: {
1717
distPath: {
1818
root: './dist/esm',
19+
css: '.',
20+
cssAsync: '.',
1921
},
2022
},
2123
},
@@ -25,6 +27,8 @@ export default defineConfig({
2527
output: {
2628
distPath: {
2729
root: './dist/cjs',
30+
css: '.',
31+
cssAsync: '.',
2832
},
2933
},
3034
},
Lines changed: 55 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
1-
import { expect, test } from '@playwright/test';
1+
import { type Page, expect, test } from '@playwright/test';
22
import { dev } from 'test-helper/rsbuild';
33

4-
test('should render example "react-component" successfully', async ({
5-
page,
6-
}) => {
7-
const rsbuild = await dev({
8-
cwd: __dirname,
9-
page,
10-
});
11-
4+
async function counterCompShouldWork(page: Page) {
125
const h2El = page.locator('h2');
136
await expect(h2El).toHaveText('Counter: 0');
147

@@ -21,6 +14,59 @@ test('should render example "react-component" successfully', async ({
2114
await expect(h2El).toHaveText('Counter: 1');
2215
subtractEl?.click();
2316
await expect(h2El).toHaveText('Counter: 0');
17+
}
18+
19+
async function styleShouldWork(page: Page) {
20+
const h2El = page.locator('h2');
21+
expect(h2El).toHaveCSS('font-size', '50px');
22+
23+
const buttonEl = page.locator('#root button');
24+
const [subtractEl, addEl] = await buttonEl.all();
25+
subtractEl &&
26+
expect(subtractEl).toHaveCSS('background-color', 'rgb(255, 255, 0)');
27+
addEl && expect(addEl).toHaveCSS('background-color', 'rgb(255, 255, 0)');
28+
}
29+
30+
test('should render example "react-component-bundle" successfully', async ({
31+
page,
32+
}) => {
33+
const rsbuild = await dev({
34+
cwd: __dirname,
35+
page,
36+
rsbuildConfig: {
37+
source: {
38+
entry: {
39+
index: './src/bundle.tsx',
40+
},
41+
},
42+
},
43+
});
44+
45+
await counterCompShouldWork(page);
46+
47+
await styleShouldWork(page);
48+
49+
await rsbuild.close();
50+
});
51+
52+
test('should render example "react-component-bundle-false" successfully', async ({
53+
page,
54+
}) => {
55+
const rsbuild = await dev({
56+
cwd: __dirname,
57+
page,
58+
rsbuildConfig: {
59+
source: {
60+
entry: {
61+
index: './src/bundleFalse.tsx',
62+
},
63+
},
64+
},
65+
});
66+
67+
await counterCompShouldWork(page);
68+
69+
await styleShouldWork(page);
2470

2571
await rsbuild.close();
2672
});
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
{
22
"name": "react-component-e2e",
33
"version": "1.0.0",
4-
"private": true
4+
"private": true,
5+
"dependencies": {
6+
"@examples/react-component-bundle": "workspace:*",
7+
"@examples/react-component-bundle-false": "workspace:*"
8+
}
59
}

tests/e2e/react-component/src/App.tsx

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { Counter } from '@examples/react-component-bundle';
2+
import React from 'react';
3+
import ReactDOM from 'react-dom/client';
4+
import '@examples/react-component-bundle/dist/esm/index.css';
5+
6+
const App = () => (
7+
<div>
8+
<Counter />
9+
</div>
10+
);
11+
12+
const root = ReactDOM.createRoot(document.getElementById('root')!);
13+
root.render(
14+
<React.StrictMode>
15+
<App />
16+
</React.StrictMode>,
17+
);

tests/e2e/react-component/src/index.tsx renamed to tests/e2e/react-component/src/bundleFalse.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1+
import { Counter } from '@examples/react-component-bundle-false';
12
import React from 'react';
23
import ReactDOM from 'react-dom/client';
3-
import App from './App';
4+
5+
const App = () => (
6+
<div>
7+
<Counter />
8+
</div>
9+
);
410

511
const root = ReactDOM.createRoot(document.getElementById('root')!);
612
root.render(

tests/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
"test:e2e": "playwright test --pass-with-no-tests"
88
},
99
"dependencies": {
10-
"@examples/react-component-bundle-false": "workspace:*",
1110
"react": "^18.3.1",
1211
"react-dom": "^18.3.1"
1312
},

0 commit comments

Comments
 (0)