File tree Expand file tree Collapse file tree
packages/daemon/src/daemon/server Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ /**
2+ * Unit tests for the withEnv test helper.
3+ */
4+
5+ import { describe , it , expect } from 'vitest' ;
6+ import { withEnv } from './test-env.js' ;
7+
8+ describe ( 'withEnv' , ( ) => {
9+ it ( 'restores a previously set env value after the callback' , async ( ) => {
10+ const key = 'ABBENAY_TEST_ENV_RESTORE' ;
11+ process . env [ key ] = 'original' ;
12+ try {
13+ await withEnv ( key , 'temporary' , ( ) => {
14+ expect ( process . env [ key ] ) . toBe ( 'temporary' ) ;
15+ } ) ;
16+ expect ( process . env [ key ] ) . toBe ( 'original' ) ;
17+ } finally {
18+ delete process . env [ key ] ;
19+ }
20+ } ) ;
21+
22+ it ( 'deletes the key when it was previously unset' , async ( ) => {
23+ const key = 'ABBENAY_TEST_ENV_DELETE' ;
24+ delete process . env [ key ] ;
25+ await withEnv ( key , 'temporary' , ( ) => {
26+ expect ( process . env [ key ] ) . toBe ( 'temporary' ) ;
27+ } ) ;
28+ expect ( process . env [ key ] ) . toBeUndefined ( ) ;
29+ } ) ;
30+ } ) ;
You can’t perform that action at this time.
0 commit comments