Skip to content
Myr

Upgrade ava to 1.2.1 (#178)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by ehmicky · committed by Sindre Sorhus · parent 2210988 · Browse files · 2 files+33 added−49 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+33 added−49 removed

  • other:+33 added−49 removed

2 files+33 added−49 removed

modified:package.json+1 added-1 removed
modified:test.js+32 added-48 removed
10 unmodified lines
1112process.env.PATH = path.join(__dirname, 'fixtures') + path.delimiter + process.env.PATH;13process.env.FOO = 'foo';1415const NO_NEWLINES_REGEXP = /^[^\n]*$/;16const STDERR_STDOUT_REGEXP = /stderr[^]*stdout/;1718test('execa()', async t => {19 const {stdout} = await m('noop', ['foo']);20 t.is(stdout, 'foo');21});
22 unmodified lines
44 t.is(stderr, 'foo');45});4647test('stdout/stderr available on errors', async t => {45 const err = await t.throws(m('exit', ['2']));48 const err = await t.throwsAsync(m('exit', ['2']));49 t.is(typeof err.stdout, 'string');50 t.is(typeof err.stderr, 'string');51});5253test('include stdout and stderr in errors for improved debugging', async t => {51 const err = await t.throws(m('fixtures/error-message.js'));52 t.regex(err.message, /stdout/);53 t.regex(err.message, /stderr/);54 t.is(err.code, 1);54 await t.throwsAsync(m('fixtures/error-message.js'), {message: STDERR_STDOUT_REGEXP, code: 1});55});5657test('do not include in errors when `stdio` is set to `inherit`', async t => {58 const err = await t.throws(m('fixtures/error-message.js', {stdio: 'inherit'}));59 t.notRegex(err.message, /\n/);58 await t.throwsAsync(m('fixtures/error-message.js', {stdio: 'inherit'}), {message: NO_NEWLINES_REGEXP});59});6061test('do not include `stderr` and `stdout` in errors when set to `inherit`', async t => {63 const err = await t.throws(m('fixtures/error-message.js', {stdout: 'inherit', stderr: 'inherit'}));64 t.notRegex(err.message, /\n/);62 await t.throwsAsync(m('fixtures/error-message.js', {stdout: 'inherit', stderr: 'inherit'}), {message: NO_NEWLINES_REGEXP});63});6465test('do not include `stderr` and `stdout` in errors when `stdio` is set to `inherit`', async t => {68 const err = await t.throws(m('fixtures/error-message.js', {stdio: [null, 'inherit', 'inherit']}));69 t.notRegex(err.message, /\n/);66 await t.throwsAsync(m('fixtures/error-message.js', {stdio: [null, 'inherit', 'inherit']}), {message: NO_NEWLINES_REGEXP});67});6869test('do not include `stdout` in errors when set to `inherit`', async t => {73 const err = await t.throws(m('fixtures/error-message.js', {stdout: 'inherit'}));70 const err = await t.throwsAsync(m('fixtures/error-message.js', {stdout: 'inherit'}), {message: /stderr/});71 t.notRegex(err.message, /stdout/);75 t.regex(err.message, /stderr/);72});7374test('do not include `stderr` in errors when set to `inherit`', async t => {79 const err = await t.throws(m('fixtures/error-message.js', {stderr: 'inherit'}));80 t.regex(err.message, /stdout/);75 const err = await t.throwsAsync(m('fixtures/error-message.js', {stderr: 'inherit'}), {message: /stdout/});76 t.notRegex(err.message, /stderr/);77});7879test('pass `stdout` to a file descriptor', async t => {
22 unmodified lines
102 t.throws(() => m.sync('foo'), process.platform === 'win32' ? /'foo' is not recognized as an internal or external command/ : 'spawnSync foo ENOENT');103});104105test('execa.sync() includes stdout and stderr in errors for improved debugging', t => {111 const err = t.throws(() => m.sync('node', ['fixtures/error-message.js']));112 t.regex(err.message, /stdout/);113 t.regex(err.message, /stderr/);114 t.is(err.code, 1);106 t.throws(() => m.sync('node', ['fixtures/error-message.js']), {message: STDERR_STDOUT_REGEXP, code: 1});107});108109test('skip throwing when using reject option in execa.sync()', t => {110 const err = m.sync('node', ['fixtures/error-message.js'], {reject: false});
6 unmodified lines
117 t.is(stdout, 'foo');118});119120test('execa.shellSync() includes stdout and stderr in errors for improved debugging', t => {129 const err = t.throws(() => m.shellSync('node fixtures/error-message.js'));130 t.regex(err.message, /stdout/);131 t.regex(err.message, /stderr/);132 t.is(err.code, 1);121 t.throws(() => m.shellSync('node fixtures/error-message.js'), {message: STDERR_STDOUT_REGEXP, code: 1});122});123124test('skip throwing when using reject option in execa.shellSync()', t => {125 const err = m.shellSync('node fixtures/error-message.js', {reject: false});
21 unmodified lines
147148 // Account for npm adding local binaries to the PATH149 const _path = process.env.PATH;150 process.env.PATH = '';162 await t.throws(m('cat-names', {preferLocal: false}), /spawn .* ENOENT/);151 await t.throwsAsync(m('cat-names', {preferLocal: false}), /spawn .* ENOENT/);152 process.env.PATH = _path;153});154155test.serial('localDir option', async t => {
62 unmodified lines
218 t.is(typeof promise.pid, 'number');219});220221test('maxBuffer affects stdout', async t => {233 await t.throws(m('max-buffer', ['stdout', '11'], {maxBuffer: 10}), /stdout maxBuffer exceeded/);234 await t.notThrows(m('max-buffer', ['stdout', '10'], {maxBuffer: 10}));222 await t.throwsAsync(m('max-buffer', ['stdout', '11'], {maxBuffer: 10}), /stdout maxBuffer exceeded/);223 await t.notThrowsAsync(m('max-buffer', ['stdout', '10'], {maxBuffer: 10}));224});225226test('maxBuffer affects stderr', async t => {238 await t.throws(m('max-buffer', ['stderr', '13'], {maxBuffer: 12}), /stderr maxBuffer exceeded/);239 await t.notThrows(m('max-buffer', ['stderr', '12'], {maxBuffer: 12}));227 await t.throwsAsync(m('max-buffer', ['stderr', '13'], {maxBuffer: 12}), /stderr maxBuffer exceeded/);228 await t.notThrowsAsync(m('max-buffer', ['stderr', '12'], {maxBuffer: 12}));229});230231test('do not buffer stdout when `buffer` set to `false`', async t => {232 const promise = m('max-buffer', ['stdout', '10'], {buffer: false});
24 unmodified lines
257});258259test('execa() returns code and failed properties', async t => {260 const {code, failed} = await m('noop', ['foo']);272 const error = await t.throws(m('exit', ['2']));261 const error = await t.throwsAsync(m('exit', ['2']), {code: 2});262 t.is(code, 0);263 t.false(failed);275 t.is(error.code, 2);264 t.true(error.failed);265});266267test('use relative path with \'..\' chars', async t => {
4 unmodified lines
272273if (process.platform !== 'win32') {274 test('execa() rejects if running non-executable', async t => {275 const cp = m('non-executable');288 await t.throws(cp);276 await t.throwsAsync(cp);277 });278}279280test('error.killed is true if process was killed directly', async t => {
2 unmodified lines
283 setTimeout(() => {284 cp.kill();285 }, 100);286299 const error = await t.throws(cp);287 const error = await t.throwsAsync(cp);288 t.true(error.killed);289});290291// TODO: Should this really be the case, or should we improve on child_process?
3 unmodified lines
295 setTimeout(() => {296 process.kill(cp.pid, 'SIGINT');297 }, 100);298311 const error = await t.throws(cp);299 const error = await t.throwsAsync(cp);300 t.false(error.killed);301});302303if (process.platform === 'darwin') {
17 unmodified lines
321 setTimeout(() => {322 process.kill(cp.pid, 'SIGINT');323 }, 100);324337 const error = await t.throws(cp);325 const error = await t.throwsAsync(cp);326 t.is(error.signal, 'SIGINT');327 });328329 test('error.signal is SIGTERM', async t => {
2 unmodified lines
332 setTimeout(() => {333 process.kill(cp.pid, 'SIGTERM');334 }, 100);335348 const error = await t.throws(cp);336 const error = await t.throwsAsync(cp);337 t.is(error.signal, 'SIGTERM');338 });339340 test('custom error.signal', async t => {353 const error = await t.throws(m('delay', ['3000', '0'], {killSignal: 'SIGHUP', timeout: 1500}));341 const error = await t.throwsAsync(m('delay', ['3000', '0'], {killSignal: 'SIGHUP', timeout: 1500}));342 t.is(error.signal, 'SIGHUP');343 });344}345
1 unmodified line
347 t.is((await m('noop')).signal, null);348});349350test('result.signal is null if process failed, but was not killed', async t => {363 const error = await t.throws(m('exit', [2]));351 const error = await t.throwsAsync(m('exit', [2]));352 t.is(error.signal, null);353});354355async function code(t, num) {368 const error = await t.throws(m('exit', [`${num}`]));369 t.is(error.code, num);356 await t.throwsAsync(m('exit', [`${num}`]), {code: num});357}358359test('error.code is 2', code, 2);360test('error.code is 3', code, 3);361test('error.code is 4', code, 4);362363test('timeout will kill the process early', async t => {377 const error = await t.throws(m('delay', ['60000', '0'], {timeout: 1500}));364 const error = await t.throwsAsync(m('delay', ['60000', '0'], {timeout: 1500}));365366 t.true(error.timedOut);367 t.not(error.code, 22);368});369370test('timeout will not kill the process early', async t => {384 const error = await t.throws(m('delay', ['3000', '22'], {timeout: 30000}));385371 const error = await t.throwsAsync(m('delay', ['3000', '22'], {timeout: 30000}), {code: 22});372 t.false(error.timedOut);387 t.is(error.code, 22);373});374375test('timedOut will be false if no timeout was set and zero exit code', async t => {376 const result = await m('delay', ['1000', '0']);377 t.false(result.timedOut);378});379380test('timedOut will be false if no timeout was set and non-zero exit code', async t => {396 const error = await t.throws(m('delay', ['1000', '3']));381 const error = await t.throwsAsync(m('delay', ['1000', '3']));382 t.false(error.timedOut);383});384385async function errorMessage(t, expected, ...args) {401 const error = await t.throws(m('exit', args));402 t.regex(error.message, expected);386 await t.throwsAsync(m('exit', args), {message: expected});387}388389errorMessage.title = (message, expected) => `error.message matches: ${expected}`;390391test(errorMessage, /Command failed: exit 2 foo bar/, 2, 'foo', 'bar');392test(errorMessage, /Command failed: exit 3 baz quz/, 3, 'baz', 'quz');393394async function cmd(t, expected, ...args) {411 const error = await t.throws(m('fail', args));395 const error = await t.throwsAsync(m('fail', args));396 t.is(error.cmd, `fail${expected}`);397398 const result = await m('noop', args);399 t.is(result.cmd, `noop${expected}`);
19 unmodified lines
419 process.kill(cp.pid, signal);420 }, 100);421 });422439 await t.throws(cp);423 await t.throwsAsync(cp);424425 // Give everybody some time to breath and kill things426 await delay(200);427
94 unmodified lines