Skip to content

Commit d91047b

Browse files
committed
docs: complete test command guide
1 parent caca20a commit d91047b

2 files changed

Lines changed: 164 additions & 4 deletions

File tree

website/docs/en/guide/cli/test.mdx

Lines changed: 82 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,87 @@
11
# test
22

3-
TODO.
3+
The `rs test` command uses [Rstest](https://rstest.rs/guide/basic/cli) to run tests.
4+
5+
## Usage
6+
7+
```bash
8+
rs test [command] [...filters] [options]
9+
```
10+
11+
The command loads the test configuration registered with [`define.test()`](../configuration#define-test).
12+
13+
## Options
14+
15+
`rs test` supports the same test runtime options and filters as Rstest. See the [Rstest CLI documentation](https://rstest.rs/guide/basic/cli#cli-options) and [Filtering tests](https://rstest.rs/guide/basic/test-filter) for details.
16+
17+
Examples:
18+
19+
```bash
20+
# Run a specific test file
21+
rs test tests/foo.test.ts
22+
23+
# Run tests with names containing "login"
24+
rs test -t login
25+
26+
# Collect code coverage
27+
rs test --coverage
28+
```
29+
30+
## Subcommands
31+
32+
### run
33+
34+
[`rs test run`](https://rstest.rs/guide/basic/cli#rstest-run) runs matching tests once without watch mode. It is suitable for CI environments.
35+
36+
```bash
37+
rs test run
38+
```
39+
40+
### watch
41+
42+
[`rs test watch`](https://rstest.rs/guide/basic/cli#rstest-watch) reruns related tests when a test file or its dependencies change.
43+
44+
```bash
45+
rs test watch
46+
```
47+
48+
### list
49+
50+
[`rs test list`](https://rstest.rs/guide/basic/cli#rstest-list) lists matching tests without running them.
51+
52+
```bash
53+
rs test list
54+
```
55+
56+
### merge-reports
57+
58+
[`rs test merge-reports`](https://rstest.rs/guide/basic/cli#rstest-merge-reports) merges blob reports generated by multiple test shards.
59+
60+
```bash
61+
rs test merge-reports
62+
```
63+
64+
### init
65+
66+
[`rs test init`](https://rstest.rs/guide/basic/cli#rstest-init) creates starter files for a supported Rstest project type.
67+
68+
```bash
69+
rs test init browser
70+
```
471

572
## Configuration
673

7-
See [`define.test()`](../configuration#define-test).
74+
Configure tests through [`define.test()`](../configuration#define-test) in the [Rstack configuration file](/guide/configuration#configuration-file). It accepts the standard [Rstest configuration](https://rstest.rs/config/):
75+
76+
```ts title="rstack.config.ts"
77+
import { define } from 'rstack';
78+
79+
define.app({
80+
// Shared application configuration
81+
});
82+
83+
define.test({
84+
setupFiles: ['./tests/rstest.setup.ts'],
85+
testEnvironment: 'happy-dom',
86+
});
87+
```

website/docs/zh/guide/cli/test.mdx

Lines changed: 82 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,87 @@
11
# test
22

3-
TODO.
3+
`rs test` 命令使用 [Rstest](https://rstest.rs/zh/guide/basic/cli) 运行测试。
4+
5+
## 用法 \{#usage}
6+
7+
```bash
8+
rs test [command] [...filters] [options]
9+
```
10+
11+
该命令会加载通过 [`define.test()`](../configuration#define-test) 注册的测试配置。
12+
13+
## 选项 \{#options}
14+
15+
`rs test` 支持与 Rstest 相同的测试运行选项和过滤方式,具体说明请参见 [Rstest CLI 文档](https://rstest.rs/zh/guide/basic/cli#cli-选项)[过滤测试](https://rstest.rs/zh/guide/basic/test-filter)
16+
17+
示例:
18+
19+
```bash
20+
# 运行指定的测试文件
21+
rs test tests/foo.test.ts
22+
23+
# 运行名称中包含 "login" 的测试
24+
rs test -t login
25+
26+
# 收集代码覆盖率
27+
rs test --coverage
28+
```
29+
30+
## 子命令 \{#subcommands}
31+
32+
### run
33+
34+
[`rs test run`](https://rstest.rs/zh/guide/basic/cli#rstest-run) 用于在非监听模式下单次运行匹配的测试,适合 CI 环境。
35+
36+
```bash
37+
rs test run
38+
```
39+
40+
### watch
41+
42+
[`rs test watch`](https://rstest.rs/zh/guide/basic/cli#rstest-watch) 会在测试文件或其依赖发生变化时重新运行相关测试。
43+
44+
```bash
45+
rs test watch
46+
```
47+
48+
### list
49+
50+
[`rs test list`](https://rstest.rs/zh/guide/basic/cli#rstest-list) 用于列出匹配的测试,但不运行测试。
51+
52+
```bash
53+
rs test list
54+
```
55+
56+
### merge-reports
57+
58+
[`rs test merge-reports`](https://rstest.rs/zh/guide/basic/cli#rstest-merge-reports) 用于合并多个测试分片生成的 blob 报告。
59+
60+
```bash
61+
rs test merge-reports
62+
```
63+
64+
### init
65+
66+
[`rs test init`](https://rstest.rs/zh/guide/basic/cli#rstest-init) 用于为 Rstest 支持的项目类型创建初始文件。
67+
68+
```bash
69+
rs test init browser
70+
```
471

572
## 配置 \{#configuration}
673

7-
参见 [`define.test()`](../configuration#define-test)
74+
[Rstack 配置文件](/guide/configuration#configuration-file)中通过 [`define.test()`](../configuration#define-test) 配置测试。该 API 支持标准的 [Rstest 配置](https://rstest.rs/zh/config/)
75+
76+
```ts title="rstack.config.ts"
77+
import { define } from 'rstack';
78+
79+
define.app({
80+
// 共享的应用配置
81+
});
82+
83+
define.test({
84+
setupFiles: ['./tests/rstest.setup.ts'],
85+
testEnvironment: 'happy-dom',
86+
});
87+
```

0 commit comments

Comments
 (0)