| 2 | import { isInteractive, isCI } from '../../src/utils/env'; |
| 3 | |
| 4 | function withTTY(stdout: boolean, stdin: boolean, fn: () => void): void { |
| 5 | const origStdout = Object.getOwnPropertyDescriptor(process.stdout, 'isTTY'); |
| 6 | const origStdin = Object.getOwnPropertyDescriptor(process.stdin, 'isTTY'); |
| 7 | Object.defineProperty(process.stdout, 'isTTY', { value: stdout, configurable: true }); |
| 8 | Object.defineProperty(process.stdin, 'isTTY', { value: stdin, configurable: true }); |
| 9 | try { fn(); } finally { |
| 10 | if (origStdout) { |
| 11 | Object.defineProperty(process.stdout, 'isTTY', origStdout); |
| 12 | } else { |
| 13 | delete (process.stdout as unknown as Record<string, unknown>).isTTY; |
| 14 | } |
| 15 | if (origStdin) { |
| 16 | Object.defineProperty(process.stdin, 'isTTY', origStdin); |
| 17 | } else { |
| 18 | delete (process.stdin as unknown as Record<string, unknown>).isTTY; |
| 19 | } |
| 20 | } |
| 21 | } |
| 22 | |
| 23 | describe('isInteractive', () => { |
| 24 | // Ensure CI env is clean before each test — other test files may set it |