Skip to content

Commit df9773a

Browse files
committed
test(env): fix CI test failures for getCI() on Ubuntu and Windows
On CI systems (GitHub Actions Ubuntu/Windows), the CI environment variable exists in process.env. After clearEnv('CI'), getCI() was falling back to process.env.CI which is truthy on CI systems, causing tests to fail. Fixed by using vi.stubEnv to clear the actual CI environment variable before testing the cleared state.
1 parent 3d2ee1b commit df9773a

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

test/unit/env/rewire.test.mts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,12 @@ describe('env rewiring', () => {
5656
setEnv('CI', '')
5757
expect(getCI()).toBe(true)
5858

59-
// CI returns false only when cleared
59+
// CI returns false only when cleared AND not in process.env
60+
// On CI systems, process.env.CI exists, so stub it out first
61+
vi.stubEnv('CI', undefined)
6062
clearEnv('CI')
6163
expect(getCI()).toBe(false)
64+
vi.unstubAllEnvs()
6265
})
6366

6467
it('should allow undefined overrides', () => {
@@ -100,8 +103,11 @@ describe('env rewiring', () => {
100103
setEnv('CI', 'false')
101104
expect(getCI()).toBe(true) // Key exists, so true
102105

106+
// Clear both override and process.env (for CI systems where CI is set)
107+
vi.stubEnv('CI', undefined)
103108
clearEnv('CI')
104109
expect(getCI()).toBe(false) // Key doesn't exist
110+
vi.unstubAllEnvs()
105111
})
106112

107113
it('test 3: should not be affected by previous tests', () => {

0 commit comments

Comments
 (0)