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
Describe the bug
According to:
I would expect
to delete
process.env.foo.This was working fine until vitest 4: now, passing
undefinedas value tostubEnv()doesn't seem to do anything anymore.Reproduction
In this PR of a dedicated repo, you will see that the same test:
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.8Used Package Manager
npm
Validations