close
  • 简体中文
  • 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');
    }