|
| 1 | +import { describe, it } from 'node:test'; |
| 2 | +import assert from 'node:assert'; |
| 3 | + |
| 4 | +import { |
| 5 | + forceRunAsync, |
| 6 | + runAsync, |
| 7 | + runSync |
| 8 | +} from '../../lib/run.js'; |
| 9 | + |
| 10 | +describe('runSync', () => { |
| 11 | + it('echo test', () => { |
| 12 | + const test = runSync('echo', ['test']).trim(); |
| 13 | + assert.strictEqual( |
| 14 | + test, |
| 15 | + 'test', |
| 16 | + 'should run a sync cmd and return stdout' |
| 17 | + ); |
| 18 | + }); |
| 19 | + it('missing cmd', () => { |
| 20 | + assert.throws( |
| 21 | + () => { runSync('./not-a-cmd'); }, |
| 22 | + /ENOENT/, |
| 23 | + 'should throw an error' |
| 24 | + ); |
| 25 | + }); |
| 26 | +}); |
| 27 | + |
| 28 | +describe('runAsync', () => { |
| 29 | + it('echo test', async() => { |
| 30 | + const test = |
| 31 | + (await runAsync('echo', ['test'], { captureStdout: true })).trim(); |
| 32 | + assert.strictEqual( |
| 33 | + test, |
| 34 | + 'test', |
| 35 | + 'should run an async cmd and return stdout' |
| 36 | + ); |
| 37 | + }); |
| 38 | +}); |
| 39 | + |
| 40 | +describe('forceRunAsync', () => { |
| 41 | + it('echo test', async() => { |
| 42 | + const test = |
| 43 | + await forceRunAsync('echo', ['test'], { captureStdout: true }); |
| 44 | + assert.strictEqual( |
| 45 | + test.trim(), |
| 46 | + 'test', |
| 47 | + 'should run an async cmd and return stdout' |
| 48 | + ); |
| 49 | + }); |
| 50 | + it('missing cmd', async() => { |
| 51 | + assert.rejects( |
| 52 | + forceRunAsync('./not-a-cmd'), |
| 53 | + /ENOENT/, |
| 54 | + 'should throw an error' |
| 55 | + ); |
| 56 | + }); |
| 57 | +}); |
0 commit comments