close
logo
Rstest
指南
配置
API
English
简体中文
指南
配置
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
📝 在 GitHub 上编辑此页
上一页testNamePattern
下一页retry

#env

  • 类型: Partial<NodeJS.ProcessEnv>
  • 默认值: undefined

自定义环境变量,在测试过程中可以通过 process.env 访问。

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

export default defineConfig({
  env: {
    PRINT_LOGGER: 'true',
  },
});

在设置上述配置后,现在,你可以在测试中访问 PRINT_LOGGER 变量:

index.test.ts
import { describe, it } from '@rstest/core';

if (process.env.PRINT_LOGGER === 'true') {
  console.log('PRINT_LOGGER is enabled');
}