Skip to content

Commit

Permalink
chore: update the example
Browse files Browse the repository at this point in the history
  • Loading branch information
SoonIter committed Dec 18, 2024
1 parent f6f98b8 commit 613168c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion examples/react-component-bundle/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const Counter: React.FC = () => {

return (
<div>
<h1 className="counter-title">Counter React Component</h1>
<h1 className="counter-title">React</h1>
<h2 className="counter-text">Counter: {count}</h2>
<CounterButton onClick={decrement} label="-" />
<CounterButton onClick={increment} label="+" />
Expand Down
18 changes: 15 additions & 3 deletions tests/e2e/react-component/index.pw.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import fs from 'node:fs';
import path from 'node:path';
import { type Page, expect, test } from '@playwright/test';
import { dev } from 'test-helper/rsbuild';
import assert from 'node:assert';

function getCwdByExample(exampleName: string) {
return path.join(__dirname, '../../../examples', exampleName);
Expand All @@ -27,9 +28,19 @@ async function styleShouldWork(page: Page) {

const buttonEl = page.locator('#root button');
const [subtractEl, addEl] = await buttonEl.all();
subtractEl &&
expect(subtractEl).toHaveCSS('background-color', 'rgb(255, 255, 0)');
addEl && expect(addEl).toHaveCSS('background-color', 'rgb(255, 255, 0)');
assert(subtractEl);
assert(addEl);
expect(subtractEl).toHaveCSS('background-color', 'rgb(255, 255, 0)');
expect(addEl).toHaveCSS('background-color', 'rgb(255, 255, 0)');
}

async function assetShouldWork(page: Page) {
// asset in css url('./logo.svg')
const h1El = page.locator('h1');
assert(h1El);
expect(h1El).toHaveCSS('background', /static\/svg\/logo/);

// TODO: asset in js
}

test('should render example "react-component-bundle" successfully', async ({
Expand All @@ -43,6 +54,7 @@ test('should render example "react-component-bundle" successfully', async ({

await counterCompShouldWork(page);
await styleShouldWork(page);
await assetShouldWork(page);
await rsbuild.close();
});

Expand Down
1 change: 1 addition & 0 deletions tests/e2e/react-component/rsbuild.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export default defineConfig({
},
output: {
target: 'web',
dataUriLimit: 0
},
plugins: [
pluginReact({
Expand Down

0 comments on commit 613168c

Please sign in to comment.