type Reporter = ReporterName | [ReporterName, ReporterOptions];
type Reporters = Reporter | Reporter[];process.env.GITHUB_ACTIONS === 'true'
? ['default', 'github-actions']
: ['default'];--reporter=<name> --reporter=<name1>自定义输出报告器的类型。
默认情况下,Rstest 会在终端显示测试运行状态、结果以及汇总信息。
输出如下:
✓ test/index.test.ts (2)
Test Files 1 passed
Tests 2 passed
Duration 112ms (build 19ms, tests 93ms)默认报告器仅在测试运行失败或耗时缓慢时输出相关的测试用例信息,Verbose 报告器会在测试完成后输出所有的测试用例信息。
npx rstest --reporter=verbose此时,Rstest 输出如下:
✓ test/index.test.ts (2) 2ms
✓ Index > should add two numbers correctly (1ms)
✓ Index > should test source code correctly (1ms)
Test Files 1 passed
Tests 2 passed
Duration 112ms (build 19ms, tests 93ms)GitHub Actions 报告器将在测试失败时以 workflow commands 的形式输出错误信息。
当测试失败时,GitHub Actions 报告器会输出类似以下格式的信息:
::error file=src/index.ts,line=4,col=17,title=test/index.test.ts > should add two numbers correctly::expected 2 to be 4这些输出会被 GitHub Actions 解析,并在对应的位置生成注释。

当未手动设置任何 reporter 时,Rstest 会在检测到 GitHub Actions 环境(process.env.GITHUB_ACTIONS 为 'true')时自动启用此报告器。
你也可以手动启用此报告器:
npx rstest --reporter=github-actionsJUnit 报告器支持以 JUnit XML 格式输出测试报告,方便与 CI/CD 系统集成。
npx rstest --reporter=junitoutputPath: 配置报告输出的路径,如果不指定则输出到控制台。import { defineConfig } from '@rstest/core';
export default defineConfig({
reporters: [['junit', { outputPath: './junit.xml' }]],
});JUnit 报告器生成的 XML 格式如下:
<?xml version="1.0" encoding="UTF-8"?>
<testsuites name="rstest tests" tests="3" failures="1" errors="1" skipped="1" time="0.3" timestamp="2024-01-01T00:00:00.000Z">
<testsuite name="test1.test.ts" tests="3" failures="1" errors="1" skipped="1" time="0.3" timestamp="2024-01-01T00:00:00.000Z">
<testcase name="should pass" classname="test1.test.ts" time="0.1">
</testcase>
<testcase name="should fail" classname="test1.test.ts" time="0.2">
<failure message="Test failed" type="AssertionError">expected 'hi' to be 'hii' // Object.is equality - Expected + Received - hii + hi at test1.test.ts:10:21</failure>
</testcase>
<testcase name="should skip" classname="test1.test.ts" time="0.0">
<skipped/>
</testcase>
</testsuite>
</testsuites>JUnit 报告器会根据测试用例的执行状态,将其映射为 JUnit 测试状态:
pass: 测试通过fail: 测试失败,会生成 <failure> 标签skip: 测试跳过,会生成 <skipped> 标签todo: 测试待办,会生成 <skipped> 标签