Skip to content

Commit 5f075aa

Browse files
authored
Add react-rstest example (#315)
1 parent 5af7021 commit 5f075aa

File tree

14 files changed

+944
-198
lines changed

14 files changed

+944
-198
lines changed

pnpm-lock.yaml

Lines changed: 775 additions & 198 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rsbuild/react-rstest/.gitignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Local
2+
.DS_Store
3+
*.local
4+
*.log*
5+
6+
# Dist
7+
node_modules
8+
dist/
9+
10+
# IDE
11+
.vscode/*
12+
!.vscode/extensions.json
13+
.idea

rsbuild/react-rstest/README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Rsbuild Project
2+
3+
## Setup
4+
5+
Install the dependencies:
6+
7+
```bash
8+
pnpm install
9+
```
10+
11+
## Get Started
12+
13+
Start the dev server:
14+
15+
```bash
16+
pnpm dev
17+
```
18+
19+
Build the app for production:
20+
21+
```bash
22+
pnpm build
23+
```
24+
25+
Preview the production build locally:
26+
27+
```bash
28+
pnpm preview
29+
```
30+
31+
Run unit tests via Rstest:
32+
33+
```bash
34+
pnpm test
35+
```

rsbuild/react-rstest/package.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "rsbuild-react-rstest",
3+
"version": "1.0.0",
4+
"private": true,
5+
"scripts": {
6+
"build": "rsbuild build",
7+
"dev": "rsbuild dev --open",
8+
"preview": "rsbuild preview",
9+
"test": "rstest run"
10+
},
11+
"dependencies": {
12+
"react": "^19.1.0",
13+
"react-dom": "^19.1.0"
14+
},
15+
"devDependencies": {
16+
"@rsbuild/core": "^1.4.8",
17+
"@rsbuild/plugin-react": "^1.1.1",
18+
"@testing-library/jest-dom": "^6.6.3",
19+
"@testing-library/react": "^16.2.0",
20+
"@types/react": "^19.0.12",
21+
"@types/react-dom": "^19.0.4",
22+
"@rstest/core": "0.0.10",
23+
"ts-node": "^10.9.2",
24+
"typescript": "^5.8.2"
25+
}
26+
}
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 { defineConfig } from '@rstest/core';
2+
import rsbuildConfig from './rsbuild.config';
3+
4+
export default defineConfig({
5+
...rsbuildConfig,
6+
testEnvironment: 'jsdom',
7+
globals: true,
8+
setupFiles: ['./rstest.setup.ts'],
9+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import '@testing-library/jest-dom';

rsbuild/react-rstest/src/App.css

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
body {
2+
margin: 0;
3+
color: #fff;
4+
font-family: Inter, Avenir, Helvetica, Arial, sans-serif;
5+
background-image: linear-gradient(to bottom, #020917, #101725);
6+
}
7+
8+
.content {
9+
display: flex;
10+
min-height: 100vh;
11+
line-height: 1.1;
12+
text-align: center;
13+
flex-direction: column;
14+
justify-content: center;
15+
}
16+
17+
.content h1 {
18+
font-size: 3.6rem;
19+
font-weight: 700;
20+
}
21+
22+
.content p {
23+
font-size: 1.2rem;
24+
font-weight: 400;
25+
opacity: 0.5;
26+
}

rsbuild/react-rstest/src/App.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import './App.css';
2+
3+
const App = () => {
4+
return (
5+
<div className="content">
6+
<h1>Rsbuild with React</h1>
7+
<p>Start building amazing things with Rsbuild.</p>
8+
</div>
9+
);
10+
};
11+
12+
export default App;

rsbuild/react-rstest/src/env.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/// <reference types="@rsbuild/core/types" />

0 commit comments

Comments
 (0)