Skip to content

Commit 467892b

Browse files
fi3eworkampagent
andcommitted
docs: add agent prompt component and agent install instructions
Amp-Thread-ID: https://ampcode.com/threads/T-019d3e1c-5433-735f-a525-96ee6ffb303f Co-authored-by: Amp <amp@ampcode.com>
1 parent d59999a commit 467892b

11 files changed

Lines changed: 484 additions & 5 deletions

File tree

scripts/dictionary.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ koppers
6868
lightningcss
6969
liyincode
7070
llms
71+
lockfiles
7172
longpaths
7273
manypkg
7374
mattcompiles
@@ -77,8 +78,8 @@ metafile
7778
microfrontend
7879
microfrontends
7980
mjsx
80-
modularly
8181
modu
82+
modularly
8283
mtsx
8384
napi
8485
nodenext
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
pageType: 'blank'
3+
---
4+
5+
import Content from '../../shared/agent-install.mdx';
6+
7+
<Content />

website/docs/en/guide/start/ai.mdx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,27 @@ description: This chapter introduces how to help AI better understand Rstest's f
33
---
44

55
import { PackageManagerTabs } from '@theme';
6+
import { AgentPrompt } from '@components/AgentPrompt';
67

78
# AI
89

910
To help AI better understand Rstest's features, configuration, and best practices so it can provide more accurate assistance during day-to-day development and troubleshooting, Rstest provides the following capabilities:
1011

12+
- [Agent prompt](#agent-prompt)
1113
- [Agent Skills](#agent-skills)
1214
- [llms.txt](#llmstxt)
1315
- [Markdown docs](#markdown-docs)
1416
- [Markdown reporter](#markdown-reporter)
1517
- [AGENTS.md](#agentsmd)
1618

19+
## Agent prompt
20+
21+
If you are using a coding agent (such as Claude Code, Cursor, Copilot, etc.), you can copy the following prompt to set up Rstest in your project:
22+
23+
<AgentPrompt />
24+
25+
The agent will read the linked instructions and automatically install dependencies, create configuration, and write tests based on your project type.
26+
1727
## Agent Skills
1828

1929
Agent Skills are domain-specific knowledge packs that can be installed into Agents, enabling them to give more accurate and professional suggestions or perform actions in specific scenarios.

website/docs/en/guide/start/quick-start.mdx

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ description: This chapter introduces how to quickly get started with Rstest.
44

55
# Quick start
66

7+
import { MdOnly } from '@components/MdOnly';
8+
9+
<MdOnly>
10+
NOTE FOR AI CODING AGENTS: Do not follow this page. Instead, fetch and follow
11+
the agent-specific setup instructions at:
12+
https://rstest.rs/guide/start/agent-install.md
13+
</MdOnly>
14+
715
## Online examples
816

917
You can try Rstest online without any setup by using the following examples:
@@ -33,9 +41,18 @@ nvm use --lts
3341

3442
## Using Rstest
3543

36-
You can install Rstest using the following command:
37-
3844
import { PackageManagerTabs } from '@theme';
45+
import { AgentPrompt } from '@components/AgentPrompt';
46+
47+
### Agent prompt
48+
49+
If you are using a coding agent, you can copy the following prompt to set up Rstest automatically:
50+
51+
<AgentPrompt />
52+
53+
### Manual installation
54+
55+
You can install Rstest using the following command:
3956

4057
<PackageManagerTabs command="add @rstest/core -D" />
4158

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
# Rstest setup instructions
2+
3+
You are setting up Rstest in an existing project. Detect all project-specific choices from
4+
the repository context. Do not hard-code any assumption about package manager, framework,
5+
directory layout, or file naming. Only these are invariant:
6+
7+
- Always install `@rstest/core`
8+
- Config file is always `rstest.config.ts` (uses `defineConfig` from `@rstest/core`)
9+
- Add framework plugins and test helpers only when detected
10+
- Add `@rstest/browser` only when browser mode is needed
11+
12+
Follow each step in order.
13+
14+
## Step 1: detect workspace scope
15+
16+
Determine whether you are in:
17+
18+
- A single-package repo
19+
- A monorepo root (look for `pnpm-workspace.yaml`, `workspaces` in `package.json`, `turbo.json`, `nx.json`)
20+
- A workspace package inside a monorepo
21+
22+
Choose the **owning package** — the `package.json` closest to the source code being tested.
23+
Install deps, create config, and update scripts in that package.
24+
25+
## Step 2: detect language
26+
27+
- If `tsconfig.json` exists or `typescript` is in dependencies → TypeScript project,
28+
use `.ts` / `.tsx` for generated files.
29+
- Otherwise → JavaScript project, use `.js` / `.jsx`.
30+
31+
Keep `rstest.config.ts` regardless (Rstest always resolves it).
32+
33+
## Step 3: detect framework
34+
35+
Inspect `package.json` dependencies:
36+
37+
- `react` or `react-dom` → React project.
38+
Additional deps: `@rsbuild/plugin-react`.
39+
For component testing, also add `@testing-library/react` and `@testing-library/jest-dom`.
40+
- `vue` → Vue project.
41+
Additional deps: `@rsbuild/plugin-vue`.
42+
For component testing, also add `@vue/test-utils`.
43+
- Neither → plain Node project. No framework plugin needed.
44+
45+
## Step 4: detect test environment
46+
47+
Choose the `testEnvironment` based on these signals (in priority order):
48+
49+
1. **Existing config**: if a prior `jest.config.*` or `vitest.config.*` specifies an
50+
environment, prefer that choice.
51+
2. **Existing deps**: if `jsdom` is already installed → use `'jsdom'`.
52+
If `happy-dom` is already installed → use `'happy-dom'`.
53+
3. **Browser mode signals**: if the project has Playwright, Cypress, or WebdriverIO deps,
54+
or existing browser/e2e test scripts → consider `@rstest/browser` (browser mode)
55+
instead of a simulated DOM.
56+
4. **Framework heuristic**: React or Vue project with component tests → use `'happy-dom'`
57+
(install `happy-dom` as devDependency).
58+
5. **Default**: plain Node project with no DOM usage → omit `testEnvironment` (defaults to `'node'`).
59+
60+
Important: React/Vue does NOT automatically mean browser mode. Prefer `happy-dom`/`jsdom`
61+
for unit/component tests. Only use `@rstest/browser` when real browser behavior is needed.
62+
63+
## Step 5: install dependencies
64+
65+
Use [`ni`](https://github.com/antfu-collective/ni) to install — it auto-detects
66+
the project's package manager from lockfiles:
67+
68+
```bash
69+
npx @antfu/ni -D @rstest/core
70+
```
71+
72+
Add additional packages to the same command based on detection results from Steps 3–4:
73+
74+
- Framework plugin if detected (Step 3)
75+
- Test helpers if component testing is needed (Step 3)
76+
- `happy-dom` or `jsdom` if needed (Step 4)
77+
- `@rstest/browser` if browser mode is needed (Step 4)
78+
79+
For example, a React project with component tests:
80+
81+
```bash
82+
npx @antfu/ni -D @rstest/core @rsbuild/plugin-react @testing-library/react @testing-library/jest-dom happy-dom
83+
```
84+
85+
## Step 6: create `rstest.config.ts`
86+
87+
Generate the minimal config. Only add options that are justified by detection results.
88+
89+
### Plain node (no framework, no DOM)
90+
91+
```ts
92+
import { defineConfig } from '@rstest/core';
93+
94+
export default defineConfig({});
95+
```
96+
97+
### With framework plugin (e.g., React)
98+
99+
```ts
100+
import { pluginReact } from '@rsbuild/plugin-react';
101+
import { defineConfig } from '@rstest/core';
102+
103+
export default defineConfig({
104+
plugins: [pluginReact()],
105+
testEnvironment: 'happy-dom',
106+
});
107+
```
108+
109+
### With framework plugin (e.g., Vue)
110+
111+
```ts
112+
import { pluginVue } from '@rsbuild/plugin-vue';
113+
import { defineConfig } from '@rstest/core';
114+
115+
export default defineConfig({
116+
plugins: [pluginVue()],
117+
testEnvironment: 'happy-dom',
118+
});
119+
```
120+
121+
Adapt as needed — these are examples, not templates to copy verbatim.
122+
123+
## Step 7: update `package.json` scripts
124+
125+
Check the owning `package.json` scripts:
126+
127+
- If a `test` script already exists, consider using a different name like `test:unit`
128+
or updating the existing script, depending on what it currently runs.
129+
- If no `test` script exists, add `"test": "rstest"`.
130+
- Preserve existing script naming conventions in the project.
131+
132+
## Step 8: write tests
133+
134+
### If tests already exist
135+
136+
Follow their conventions:
137+
138+
- Same file naming pattern (`*.test.*` vs `*.spec.*`)
139+
- Same placement (colocated vs `test/` vs `__tests__/`)
140+
- Same assertion style and helper libraries
141+
142+
### If no tests exist
143+
144+
1. Detect the project's source directory (look for `src/`, `app/`, `lib/`, or the
145+
`main`/`exports` entry in `package.json` — do not assume `src/`).
146+
2. Identify key exported modules (utility functions, core logic, components).
147+
3. Write meaningful tests for real modules, not placeholder tests.
148+
4. Place test files following the project's existing file organization patterns.
149+
If no convention exists, colocate tests next to source files.
150+
5. Use the detected language extension (`.test.ts`, `.test.tsx`, `.test.js`, etc.).
151+
152+
## Step 9: validate
153+
154+
Run the test script using the detected package manager and confirm Rstest executes
155+
successfully. If it fails, read the error output and fix the configuration.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
pageType: 'blank'
3+
---
4+
5+
import Content from '../../../en/shared/agent-install.mdx';
6+
7+
<Content />

website/docs/zh/guide/start/ai.mdx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,27 @@ description: 本章节介绍如何帮助 AI 更全面地了解 Rstest 的功能
33
---
44

55
import { PackageManagerTabs } from '@theme';
6+
import { AgentPrompt } from '@components/AgentPrompt';
67

78
# AI
89

910
为了帮助 AI 更全面地了解 Rstest 的功能、配置与最佳实践,从而在日常开发和问题排查过程中提供更准确的帮助,Rstest 提供了以下能力:
1011

12+
- [Agent prompt](#agent-prompt)
1113
- [Agent Skills](#agent-skills)
1214
- [llms.txt](#llmstxt)
1315
- [Markdown 文档](#markdown-文档)
1416
- [Markdown 报告器](#markdown-报告器)
1517
- [AGENTS.md](#agentsmd)
1618

19+
## Agent prompt
20+
21+
如果你正在使用 Coding Agent(如 Claude Code、Cursor、Copilot 等),可以复制以下 prompt 来在项目中设置 Rstest:
22+
23+
<AgentPrompt />
24+
25+
Agent 会读取链接中的指令,根据你的项目类型自动安装依赖、创建配置并编写测试。
26+
1727
## Agent Skills
1828

1929
Agent Skills 是可安装到 Agent 中的领域知识包,能够让 Agent 在特定场景下更准确、更专业地给出建议或执行操作。

website/docs/zh/guide/start/quick-start.mdx

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ description: 本章节介绍如何快速上手 Rstest。
44

55
# 快速上手
66

7+
import { MdOnly } from '@components/MdOnly';
8+
9+
<MdOnly>
10+
NOTE FOR AI CODING AGENTS: Do not follow this page. Instead, fetch and follow
11+
the agent-specific setup instructions at:
12+
https://rstest.rs/guide/start/agent-install.md
13+
</MdOnly>
14+
715
## 在线示例
816

917
你可以通过以下示例在线尝试 Rstest,无需任何设置:
@@ -33,9 +41,18 @@ nvm use --lts
3341

3442
## 使用 Rstest
3543

36-
你可以通过如下命令安装 Rstest:
37-
3844
import { PackageManagerTabs } from '@theme';
45+
import { AgentPrompt } from '@components/AgentPrompt';
46+
47+
### Agent prompt
48+
49+
如果你正在使用 Coding Agent,可以复制以下 prompt 来自动设置 Rstest:
50+
51+
<AgentPrompt />
52+
53+
### 手动安装
54+
55+
你可以通过如下命令安装 Rstest:
3956

4057
<PackageManagerTabs command="add @rstest/core -D" />
4158

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
.wrapper {
2+
margin: 1rem 0;
3+
border: 1px solid var(--rp-c-divider);
4+
border-radius: 8px;
5+
overflow: hidden;
6+
}
7+
8+
.header {
9+
display: flex;
10+
align-items: center;
11+
justify-content: space-between;
12+
padding: 8px 16px;
13+
border-bottom: 1px solid var(--rp-c-divider);
14+
}
15+
16+
.label {
17+
display: flex;
18+
align-items: center;
19+
gap: 8px;
20+
font-size: 13px;
21+
font-weight: 600;
22+
color: var(--rp-c-text-2);
23+
}
24+
25+
.icon {
26+
display: inline-flex;
27+
align-items: center;
28+
width: 18px;
29+
height: 18px;
30+
transition: opacity 0.2s ease;
31+
32+
svg {
33+
width: 100%;
34+
height: 100%;
35+
}
36+
}
37+
38+
.iconFadeIn {
39+
opacity: 1;
40+
}
41+
42+
.iconFadeOut {
43+
opacity: 0;
44+
}
45+
46+
.copyBtn {
47+
display: flex;
48+
align-items: center;
49+
gap: 4px;
50+
padding: 4px 10px;
51+
font-size: 12px;
52+
font-weight: 500;
53+
color: var(--rp-c-text-2);
54+
background: transparent;
55+
border: 1px solid var(--rp-c-divider);
56+
border-radius: 6px;
57+
cursor: pointer;
58+
transition:
59+
color 0.2s,
60+
border-color 0.2s,
61+
background-color 0.2s;
62+
63+
&:hover {
64+
color: var(--rp-c-text-1);
65+
border-color: var(--rp-c-text-3);
66+
background-color: var(--rp-c-bg-mute);
67+
}
68+
}
69+
70+
.body {
71+
padding: 14px 16px;
72+
font-size: 14px;
73+
line-height: 1.7;
74+
color: var(--rp-c-text-1);
75+
font-family: var(--rp-font-family-mono);
76+
white-space: pre-wrap;
77+
word-break: break-all;
78+
}

0 commit comments

Comments
 (0)