Skip to content

Commit 1f36df7

Browse files
authored
feat(rstest): add Rstest examples (#393)
1 parent a6cd496 commit 1f36df7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+5537
-98
lines changed

.github/workflows/ci.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ jobs:
3131
- name: Install dependencies
3232
run: pnpm install
3333

34+
- name: Install Playwright browsers
35+
run: pnpm dlx playwright install chromium
36+
3437
- name: Build Rspack
3538
run: |
3639
pnpm build:rspack
@@ -50,3 +53,6 @@ jobs:
5053
- name: Build Rsdoctor
5154
run: |
5255
pnpm build:rsdoctor
56+
57+
- name: Test Rstest
58+
run: pnpm test:rstest

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ lib-cov
2323

2424
# Coverage directory used by tools like istanbul
2525
coverage
26+
!rstest/coverage/
2627
*.lcov
2728

2829
# nyc test coverage

AGENTS.md

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,33 @@ This file provides guidance for AI coding agents working in this repository.
44

55
## Repository Overview
66

7-
- This is a monorepo of example projects for the Rstack ecosystem: Rspack, Rsbuild, Rspress, Rsdoctor, and Rslib.
7+
- This is a monorepo of example projects for the Rstack ecosystem: Rspack, Rsbuild, Rspress, Rsdoctor, Rslib, and Rstest.
88
- Package manager: `pnpm` (see `package.json#packageManager`).
9-
- Workspace layout: `pnpm-workspace.yaml` includes `rspack/**`, `rsbuild/**`, `rslib/**`, `rspress/**`, `rsdoctor/**`.
9+
- Workspace layout: `pnpm-workspace.yaml` includes `rspack/**`, `rsbuild/**`, `rslib/**`, `rspress/**`, `rsdoctor/**`, `rstest/**`.
10+
11+
## Core Purpose of Examples
12+
13+
**The primary goal of each example is to demonstrate "how a specific API achieves a specific effect through specific configuration".**
14+
15+
When creating or modifying examples:
16+
- **Keep it minimal**: Only include code necessary to demonstrate the target feature/API
17+
- **Avoid over-engineering**: Don't add complex business logic that distracts from the core demonstration
18+
- **Focus on the tool, not the ecosystem**: For example, in a test runner example, focus on the test runner's APIs (mocking, assertions, configuration), not on complex DOM manipulation or third-party library integrations
19+
- **One concept per example**: Each example should ideally demonstrate one main feature or configuration pattern
20+
- **Clarity over completeness**: A simple, clear example is better than a comprehensive but confusing one
21+
22+
Example of good vs bad:
23+
```
24+
# Good: Demonstrates rstest's mocking API
25+
- Simple mock function usage
26+
- Clear before/after assertions
27+
- Minimal setup code
28+
29+
# Bad: Demonstrates rstest's mocking API
30+
- Complex React component with many interactions
31+
- Detailed DOM testing with @testing-library
32+
- Business logic mixed with test assertions
33+
```
1034

1135
## Quick Start (Local)
1236

biome.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@
1313
"**/rspress/**",
1414
"**/rsdoctor/**",
1515
"**/rslib/**",
16+
"**/rstest/**",
1617
"!**/dist",
1718
"!**/dist-*",
1819
"!**/doc_build",
1920
"!**/auto-imports.d.ts",
20-
"!**/components.d.ts"
21+
"!**/components.d.ts",
22+
"!**/__snapshots__/**"
2123
],
2224
"ignoreUnknown": true
2325
},

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@
1010
"build:rsdoctor": "pnpm --filter \"rsdoctor-*\" build",
1111
"build:rspack": "pnpm --filter \"example-*\" build",
1212
"test:rspack": "pnpm --filter \"example-*\" test",
13+
"test:rstest": "pnpm --filter \"rstest-*\" test",
1314
"build:rspress": "pnpm --filter \"rspress-*\" build",
1415
"build:rslib": "pnpm --filter \"rslib-*\" build",
1516
"prepare": "husky",
16-
"sort-package-json": "npx sort-package-json \"rspack/*/package.json\" \"rsbuild/*/package.json\" \"rspress/*/package.json\" \"rsdoctor/*/package.json\" \"rslib/*/package.json\""
17+
"sort-package-json": "npx sort-package-json \"rspack/*/package.json\" \"rsbuild/*/package.json\" \"rspress/*/package.json\" \"rsdoctor/*/package.json\" \"rslib/*/package.json\" \"rstest/*/package.json\""
1718
},
1819
"lint-staged": {
1920
"*.{js,ts,cjs,mjs,d.cts,d.mts,jsx,tsx,json,jsonc}": [

pnpm-lock.yaml

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

pnpm-workspace.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ packages:
44
- "rslib/**"
55
- "rspress/**"
66
- "rsdoctor/**"
7+
- "rstest/**"
78
- "!**/dist"
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "rstest-browser-rsbuild-react",
3+
"version": "1.0.0",
4+
"private": true,
5+
"scripts": {
6+
"dev": "rsbuild dev",
7+
"build": "rsbuild build",
8+
"test": "rstest run"
9+
},
10+
"devDependencies": {
11+
"@rsbuild/core": "^1.4.2",
12+
"@rsbuild/plugin-react": "^1.4.2",
13+
"@rstest/adapter-rsbuild": "^0.1.0",
14+
"@rstest/browser": "^0.7.9",
15+
"@rstest/browser-react": "^0.7.9",
16+
"@rstest/core": "^0.7.9",
17+
"@testing-library/dom": "^10.4.0",
18+
"@testing-library/user-event": "^14.6.1",
19+
"@types/react": "^19.1.8",
20+
"@types/react-dom": "^19.1.6",
21+
"playwright": "^1.57.0",
22+
"react": "^19.2.3",
23+
"react-dom": "^19.2.3",
24+
"typescript": "^5.8.3"
25+
}
26+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import path from 'node:path';
2+
import { defineConfig } from '@rsbuild/core';
3+
import { pluginReact } from '@rsbuild/plugin-react';
4+
5+
export default defineConfig({
6+
plugins: [pluginReact()],
7+
source: {
8+
entry: {
9+
index: './src/index.tsx',
10+
},
11+
alias: {
12+
'@': path.resolve(__dirname, 'src'),
13+
'@components': path.resolve(__dirname, 'src/components'),
14+
},
15+
define: {
16+
__APP_VERSION__: JSON.stringify('1.0.0'),
17+
},
18+
},
19+
});
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { withRsbuildConfig } from '@rstest/adapter-rsbuild';
2+
import { defineConfig, type ExtendConfigFn } from '@rstest/core';
3+
4+
export default defineConfig({
5+
extends: withRsbuildConfig() as ExtendConfigFn,
6+
browser: {
7+
enabled: true,
8+
browser: 'chromium',
9+
port: 3012,
10+
},
11+
});

0 commit comments

Comments
 (0)