Skip to content

vitest 4 broke stubEnv(..., undefined) to unset an environment variable #10525

@DamienCassou

Description

@DamienCassou

Describe the bug

According to:

I would expect

vi.stubEnv("foo", undefined);

to delete process.env.foo.

This was working fine until vitest 4: now, passing undefined as value to stubEnv() doesn't seem to do anything anymore.

Reproduction

In this PR of a dedicated repo, you will see that the same test:

  • passes in vitest 3
  • fails in vitest 4
  • fails in vitest 5-beta

The test fails in vitest 4 and 5-beta because the initial value of the environment variable remains after the call to stubEnv(..., undefined)

System Info

System:
    OS: Linux 6.17 Ubuntu 24.04.4 LTS 24.04.4 LTS (Noble Numbat)
    CPU: (4) x64 AMD EPYC 7763 64-Core Processor
    Memory: 14.62 GB / 15.61 GB
    Container: Yes
    Shell: 5.2.21 - /bin/bash
  Binaries:
    Node: 24.16.0 - /opt/hostedtoolcache/node/24.16.0/x64/bin/node
    Yarn: 1.22.22 - /usr/local/bin/yarn
    npm: 11.13.0 - /opt/hostedtoolcache/node/24.16.0/x64/bin/npm
  Browsers:
    Chrome: 148.0.7778.178
    Chromium: 148.0.7778.0
    Firefox: 151.0.1
    Firefox Developer Edition: 151.0.1
  npmPackages:
    vitest: ^4.1.8 => 4.1.8

Used Package Manager

npm

Validations

Metadata

Metadata

Assignees

No one assigned

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions