index.ts 652 B

12345678910111213141516171819202122232425262728
  1. import { Instance } from "../project/instance"
  2. export namespace Env {
  3. const state = Instance.state(() => {
  4. // Create a shallow copy to isolate environment per instance
  5. // Prevents parallel tests from interfering with each other's env vars
  6. return { ...process.env } as Record<string, string | undefined>
  7. })
  8. export function get(key: string) {
  9. const env = state()
  10. return env[key]
  11. }
  12. export function all() {
  13. return state()
  14. }
  15. export function set(key: string, value: string) {
  16. const env = state()
  17. env[key] = value
  18. }
  19. export function remove(key: string) {
  20. const env = state()
  21. delete env[key]
  22. }
  23. }