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
Provenance
- Commit
0f48671- Tree
50e59a3- Author
ehmicky <ehmicky@users.noreply.github.com>- Committer
Sindre Sorhus <sindresorhus@gmail.com>- Parent
2210988
2 files changed+33 added−49 removed
modified:package.json+1 added-1 removed
44 unmodified lines4546474849495051525312 unmodified lines44 unmodified lines "signal-exit": "^3.0.0", "strip-final-newline": "^2.0.0" }, "devDependencies": { "ava": "^0.25.0", "ava": "^1.2.1", "cat-names": "^1.0.2", "coveralls": "^3.0.1", "delay": "^3.0.0", "is-running": "^2.0.0",12 unmodified linesmodified:test.js+32 added-48 removed
10 unmodified lines11 12 process.env.PATH = path.join(__dirname, 'fixtures') + path.delimiter + process.env.PATH;13 process.env.FOO = 'foo';14 15+const NO_NEWLINES_REGEXP = /^[^\n]*$/;16+const STDERR_STDOUT_REGEXP = /stderr[^]*stdout/;17+18 test('execa()', async t => {19 const {stdout} = await m('noop', ['foo']);20 t.is(stdout, 'foo');21 });22 unmodified lines44 t.is(stderr, 'foo');45 });46 47 test('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 });52 53 test('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 });56 57 test('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 });60 61 test('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 });64 65 test('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 });68 69 test('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 });73 74 test('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 });78 79 test('pass `stdout` to a file descriptor', async t => {22 unmodified lines102 t.throws(() => m.sync('foo'), process.platform === 'win32' ? /'foo' is not recognized as an internal or external command/ : 'spawnSync foo ENOENT');103 });104 105 test('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 });108 109 test('skip throwing when using reject option in execa.sync()', t => {110 const err = m.sync('node', ['fixtures/error-message.js'], {reject: false});6 unmodified lines117 t.is(stdout, 'foo');118 });119 120 test('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 });123 124 test('skip throwing when using reject option in execa.shellSync()', t => {125 const err = m.shellSync('node fixtures/error-message.js', {reject: false});21 unmodified lines147 148 // 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 });154 155 test.serial('localDir option', async t => {62 unmodified lines218 t.is(typeof promise.pid, 'number');219 });220 221 test('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 });225 226 test('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 });230 231 test('do not buffer stdout when `buffer` set to `false`', async t => {232 const promise = m('max-buffer', ['stdout', '10'], {buffer: false});24 unmodified lines257 });258 259 test('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 });266 267 test('use relative path with \'..\' chars', async t => {4 unmodified lines272 273 if (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 }279 280 test('error.killed is true if process was killed directly', async t => {2 unmodified lines283 setTimeout(() => {284 cp.kill();285 }, 100);286 299- const error = await t.throws(cp);287+ const error = await t.throwsAsync(cp);288 t.true(error.killed);289 });290 291 // TODO: Should this really be the case, or should we improve on child_process?3 unmodified lines295 setTimeout(() => {296 process.kill(cp.pid, 'SIGINT');297 }, 100);298 311- const error = await t.throws(cp);299+ const error = await t.throwsAsync(cp);300 t.false(error.killed);301 });302 303 if (process.platform === 'darwin') {17 unmodified lines321 setTimeout(() => {322 process.kill(cp.pid, 'SIGINT');323 }, 100);324 337- const error = await t.throws(cp);325+ const error = await t.throwsAsync(cp);326 t.is(error.signal, 'SIGINT');327 });328 329 test('error.signal is SIGTERM', async t => {2 unmodified lines332 setTimeout(() => {333 process.kill(cp.pid, 'SIGTERM');334 }, 100);335 348- const error = await t.throws(cp);336+ const error = await t.throwsAsync(cp);337 t.is(error.signal, 'SIGTERM');338 });339 340 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 line347 t.is((await m('noop')).signal, null);348 });349 350 test('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 });354 355 async 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 }358 359 test('error.code is 2', code, 2);360 test('error.code is 3', code, 3);361 test('error.code is 4', code, 4);362 363 test('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}));365 366 t.true(error.timedOut);367 t.not(error.code, 22);368 });369 370 test('timeout will not kill the process early', async t => {384- const error = await t.throws(m('delay', ['3000', '22'], {timeout: 30000}));385-371+ 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 });374 375 test('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 });379 380 test('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 });384 385 async 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 }388 389 errorMessage.title = (message, expected) => `error.message matches: ${expected}`;390 391 test(errorMessage, /Command failed: exit 2 foo bar/, 2, 'foo', 'bar');392 test(errorMessage, /Command failed: exit 3 baz quz/, 3, 'baz', 'quz');393 394 async 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}`);397 398 const result = await m('noop', args);399 t.is(result.cmd, `noop${expected}`);19 unmodified lines419 process.kill(cp.pid, signal);420 }, 100);421 });422 439- await t.throws(cp);423+ await t.throwsAsync(cp);424 425 // Give everybody some time to breath and kill things426 await delay(200);427 94 unmodified lines