For AI agents: the complete documentation index is available at https://rstest.rs/llms.txt, the full documentation bundle is available at https://rstest.rs/llms-full.txt, and this page is available as Markdown at https://rstest.rs/config/test/env.md.
close
  • English
  • env

    • Type: Partial<NodeJS.ProcessEnv>
    • Default: {}

    Custom environment variables exposed on process.env (and import.meta.env) during tests.

    rstest.config.ts
    import { defineConfig } from '@rstest/core';
    
    export default defineConfig({
      env: {
        PRINT_LOGGER: 'true',
      },
    });

    Tests can then read process.env.PRINT_LOGGER:

    index.test.ts
    import { expect, it } from '@rstest/core';
    
    it('reads custom env', () => {
      expect(process.env.PRINT_LOGGER).toBe('true');
    });

    In Node Mode, env merges over inherited host process.env values and any changes made in globalSetup. In Browser Mode, host environment variables are not forwarded automatically (only NODE_ENV, RSTEST, and changes from the browser project's own globalSetup are included), and env takes precedence over them.