Skip to content

Commit

Permalink
Make test fail on environments that don't have Path set
Browse files Browse the repository at this point in the history
  • Loading branch information
niik committed Jun 5, 2024
1 parent f5cf7f2 commit 5cd7d8f
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions test/fast/environment-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,27 @@ describe('environment variables', () => {
}
})

it('resulting PATH contains the original PATH', async () => {
// This test will ensure that on platforms where env vars names are
// case-insensitive (like Windows) we don't end up with an invalid PATH
// and the original one lost in the process.
const { env } = await setupEnvironment({})
expect((<any>env)['PATH']).toContain(process.env.PATH)
})
if (process.platform === 'win32') {
it('resulting PATH contains the original PATH', () => {
const originalPathKey = Object.keys(process.env).find(
k => k.toUpperCase() === 'PATH'
)
expect(originalPathKey).not.toBeUndefined()

const originalPathValue = process.env.PATH

try {
delete process.env.PATH
process.env.Path = 'wow-such-case-insensitivity'
// This test will ensure that on platforms where env vars names are
// case-insensitive (like Windows) we don't end up with an invalid PATH
// and the original one lost in the process.
const { env } = setupEnvironment({})
expect(env.PATH).toContain('wow-such-case-insensitivity')
} finally {
delete process.env.Path
process.env[originalPathKey!] = originalPathValue
}
})
}
})

0 comments on commit 5cd7d8f

Please sign in to comment.