close
logo
Rstest
Guide
Config
API
English
简体中文
Guide
Config
API
English
简体中文
logo
Rstest
Overview

Test Configurations

root
name
include
exclude
setupFiles
projects
update
globals
passWithNoTests
includeSource
testNamePattern
env
retry
testTimeout
hookTimeout
maxConcurrency
pool
isolate
testEnvironment
clearMocks
resetMocks
restoreMocks
unstubEnvs
unstubGlobals
coverage
reporters
hideSkippedTests
slowTestThreshold
snapshotFormat
resolveSnapshotPath
printConsoleTrace
onConsoleLog
disableConsoleIntercept

Build Configurations

plugins
source
output
resolve
tools
dev
performance
📝 Edit this page on GitHub
Previous Pagecoverage
Next PagehideSkippedTests

#reporters

  • Type:
type Reporter = ReporterName | [ReporterName, ReporterOptions];

type Reporters = Reporter | Reporter[];
  • Default:
process.env.GITHUB_ACTIONS === 'true'
  ? ['default', 'github-actions']
  : ['default'];
  • CLI: --reporter=<name> --reporter=<name1>

Customize the reporter type.

#Built-in Reporters

#Default reporter

By default, Rstest displays test run status, results, and summary information in the terminal.

Output example:

 ✓ test/index.test.ts (2)

 Test Files 1 passed
      Tests 2 passed
   Duration 112ms (build 19ms, tests 93ms)

#Verbose reporter

The default reporter only outputs test case information when tests fail or run slowly. The verbose reporter will output all test case information after test completion.

CLI
rstest.config.ts
import { defineConfig } from '@rstest/core';

export default defineConfig({
  reporters: 'verbose'
});

With verbose reporter, Rstest outputs:

 ✓ 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 reporter

The Github Actions reporter outputs error messages in the form of workflow commands when tests fail.

#Output example

When tests fail, the Github Actions reporter outputs information in a format similar to:

::error file=src/index.ts,line=4,col=17,title=test/index.test.ts > should add two numbers correctly::expected 2 to be 4

These outputs are parsed by GitHub Actions and generate comments at the corresponding locations.

rstest-github-actions-example

#Auto-enablement

When no reporter is manually set, Rstest automatically enables this reporter when it detects a GitHub Actions environment (process.env.GITHUB_ACTIONS is 'true').

#Manual enablement

You can also manually enable this reporter:

CLI
rstest.config.ts
import { defineConfig } from '@rstest/core';

export default defineConfig({
  reporters: ['github-actions']
});

#JUnit reporter

The JUnit reporter supports outputting test reports in JUnit XML format, making it easy to integrate with CI/CD.

CLI
rstest.config.ts
import { defineConfig } from '@rstest/core';

export default defineConfig({
  reporters: [['junit', { outputPath: './junit.xml' }]]
});

#Options

  • outputPath: Configure the output path for the report. If not specified, it will output to the console.
rstest.config.ts
import { defineConfig } from '@rstest/core';

export default defineConfig({
  reporters: [['junit', { outputPath: './junit.xml' }]],
});

#Output example

The JUnit reporter generates XML format as follows:

<?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>

The JUnit reporter maps test case execution status to JUnit test status:

  • pass: Test passed
  • fail: Test failed, generates <failure> tag
  • skip: Test skipped, generates <skipped> tag
  • todo: Test todo, generates <skipped> tag