Skip to content

Commit 36a35f0

Browse files
committed
test(env): fix CI test failures for getCI() on Ubuntu and Windows
1 parent aa181c0 commit 36a35f0

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

test/unit/env/ci.test.mts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
import { getCI } from '@socketsecurity/lib/env/ci'
1212
import { clearEnv, resetEnv, setEnv } from '@socketsecurity/lib/env/rewire'
13-
import { afterEach, describe, expect, it } from 'vitest'
13+
import { afterEach, describe, expect, it, vi } from 'vitest'
1414

1515
describe('env/ci', () => {
1616
afterEach(() => {
@@ -90,8 +90,11 @@ describe('env/ci', () => {
9090
setEnv('CI', 'true')
9191
expect(getCI()).toBe(true)
9292

93+
// On CI systems, process.env.CI exists, so stub it out first
94+
vi.stubEnv('CI', undefined)
9395
clearEnv('CI')
9496
expect(getCI()).toBe(false)
97+
vi.unstubAllEnvs()
9598
})
9699

97100
it('should handle consecutive reads', () => {

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)