test('version.validate', t => { const message = 'Version should be a valid semver version.'; t.throws(() => version.validate('patch'), message); t.throws(() => version.validate('patchxxx'), message); t.throws(() => version.validate('1.0.0.0'), message); t.notThrows(() => version.validate('1.0.0')); t.notThrows(() => version.validate('1.0.0-beta')); t.notThrows(() => version.validate('1.0.0-0')); });
test('timeout kills the process if it times out, in sync mode', async t => { const {killed, timedOut} = await t.throws(() => { execa.sync('noop', {timeout: 1, message: TIMEOUT_REGEXP}); }); t.false(killed); t.true(timedOut); });
test('version.getNewVersionFrom', t => { const message = 'Version should be either patch, minor, major, prepatch, preminor, premajor, prerelease or a valid semver version.'; t.throws(() => version('1.0.0').getNewVersionFrom('patchxxx'), message); t.throws(() => version('1.0.0').getNewVersionFrom('1.0.0.0'), message); t.is(version('1.0.0').getNewVersionFrom('patch'), '1.0.1'); t.is(version('1.0.0').getNewVersionFrom('minor'), '1.1.0'); t.is(version('1.0.0').getNewVersionFrom('major'), '2.0.0'); t.is(version('1.0.0-beta').getNewVersionFrom('major'), '1.0.0'); t.is(version('1.0.0').getNewVersionFrom('prepatch'), '1.0.1-0'); t.is(version('1.0.1-0').getNewVersionFrom('prepatch'), '1.0.2-0'); t.is(version('1.0.0-0').getNewVersionFrom('prerelease'), '1.0.0-1'); t.is(version('1.0.1-0').getNewVersionFrom('prerelease'), '1.0.1-1'); });
test('`forceKillAfterTimeout` should not be NaN', t => { t.throws(() => { execa('noop').kill('SIGTERM', {forceKillAfterTimeout: NaN}); }, {instanceOf: TypeError, message: /non-negative integer/}); });
test('stdout/stderr/all on process errors, in sync mode', t => { const {stdout, stderr, all} = t.throws(() => { execa.sync('wrong command'); }); t.is(stdout, ''); t.is(stderr, WRONG_COMMAND); t.is(all, undefined); });
test('timeout must be an integer', async t => { await t.throws(() => { execa('noop', {timeout: false}); }, INVALID_TIMEOUT_REGEXP); });
test('helpful error trying to provide an input stream in sync mode', t => { t.throws( () => { execa.sync('stdin', {input: new Stream.PassThrough()}); }, /The `input` option cannot be a stream in sync mode/ ); });
test('on() - eventName must be a string or a symbol', t => { const emitter = new Emittery(); emitter.on('string', () => {}); emitter.on(Symbol('symbol'), () => {}); t.throws(() => { emitter.on(42, () => {}); }, TypeError); });
test('child_process.spawnSync() errors are propagated with a correct shape', t => { const {failed} = t.throws(() => { execa.sync('noop', {timeout: -1}); }); t.true(failed); });
test('stripFinalNewline in sync mode on failure', t => { const {stderr} = t.throws(() => { execa.sync('noop-throw', ['foo'], {stripFinalNewline: true}); }); t.is(stderr, 'foo'); });
test('result.isCanceled is false when spawned.cancel() isn\'t called in sync mode (failure)', t => { const {isCanceled} = t.throws(() => { execa.sync('fail'); }); t.false(isCanceled); });
test('execa.sync() throws error if written to stderr', t => { t.throws(() => { execa.sync('foo'); }, ENOENT_REGEXP); });
test('result.killed is false on process error, in sync mode', t => { const {killed} = t.throws(() => { execa.sync('wrong command'); }); t.false(killed); });
test('`forceKillAfterTimeout` should not be negative', t => { t.throws(() => { execa('noop').kill('SIGTERM', {forceKillAfterTimeout: -1}); }, {instanceOf: TypeError, message: /non-negative integer/}); });
test('timeout must not be negative', async t => { await t.throws(() => { execa('noop', {timeout: -1}); }, INVALID_TIMEOUT_REGEXP); });