(opts: { interceptGh?: boolean } = {})
| 48 | * By default intercepts all `gh` commands. Real git/system commands pass through. |
| 49 | */ |
| 50 | export function installShellMock(opts: { interceptGh?: boolean } = {}) { |
| 51 | calls = []; |
| 52 | rules = []; |
| 53 | |
| 54 | const interceptGh = opts.interceptGh ?? true; |
| 55 | if (interceptGh) { |
| 56 | rules.push({ match: 'gh --version', response: 'gh version 2.50.0' }); |
| 57 | rules.push({ match: /^gh /, response: '{}' }); |
| 58 | } |
| 59 | |
| 60 | _setInterceptor((args, opts) => { |
| 61 | const cmdString = args.join(' '); |
| 62 | calls.push({ command: cmdString, args: [...args], opts }); |
| 63 | |
| 64 | const rule = findRule(cmdString); |
| 65 | if (rule) { |
| 66 | if (rule.error) return { intercepted: true, error: rule.error }; |
| 67 | return { intercepted: true, result: rule.response ?? '' }; |
| 68 | } |
| 69 | |
| 70 | // Not intercepted — pass through to real implementation |
| 71 | return { intercepted: false }; |
| 72 | }); |
| 73 | } |
| 74 | |
| 75 | /** Reset mock state (calls + rules) and re-install with fresh defaults */ |
| 76 | export function resetMockState(opts: { interceptGh?: boolean } = {}) { |
no test coverage detected
searching dependent graphs…