| 19 | |
| 20 | // Run the cli with args as argv |
| 21 | const cli = (...args) => { |
| 22 | mocks.init(); |
| 23 | const stdin = mocks.stdin(); |
| 24 | |
| 25 | let code; |
| 26 | try { |
| 27 | code = shx.call(stdin, ['', '', ...args]); |
| 28 | } catch (e) { |
| 29 | if (Object.prototype.hasOwnProperty.call(e, 'code')) { |
| 30 | // Shx is returning an error with a specified code |
| 31 | code = e.code; |
| 32 | } else { |
| 33 | // Shx is throwing an exception |
| 34 | throw e; |
| 35 | } |
| 36 | } finally { |
| 37 | mocks.restore(); |
| 38 | } |
| 39 | |
| 40 | return { |
| 41 | code, |
| 42 | stdout: mocks.stdout(), |
| 43 | stderr: mocks.stderr(), |
| 44 | }; |
| 45 | }; |
| 46 | |
| 47 | describe('cli', () => { |
| 48 | beforeEach(() => { |