Skip to content

Commit 00841c9

Browse files
test(daemon): cover withEnv restore path for previously set keys
Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 8ca5edb commit 00841c9

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
});

0 commit comments

Comments
 (0)