function borrowEnv
borrowEnv(overrides: Record<string, string | undefined>): Disposable

Applies overrides over process.env for the scope, then restores it exactly: keys added during the scope are dropped and changed values are put back.

Key-by-key rather than process.env = snapshot, because assigning the object wholesale replaces the live binding other modules may already hold a reference to.

import { borrowEnv } from './borrowed-globals.ts';

{
  using _env = borrowEnv({ QUNITX_BORROW_EXAMPLE: '1' });
  process.env.QUNITX_BORROW_EXAMPLE; // '1'
}
process.env.QUNITX_BORROW_EXAMPLE; // undefined — the key never existed, so it is dropped

Parameters

overrides: Record<string, string | undefined>

Return Type

Disposable

Usage

import { borrowEnv } from "lib/utils/borrowed-globals.ts";