Minor test code style tweaks
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Sindre Sorhus · committed by Sindre Sorhus · parent 31c89d1 · Browse files · 1 file·+38 added−28 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+38 added−28 removed
- other:+38 added−28 removed
Provenance
- Commit
f6db264- Tree
22042a0- Author
Sindre Sorhus <sindresorhus@gmail.com>- Committer
Sindre Sorhus <sindresorhus@gmail.com>- Parent
31c89d1
1 file changed+38 added−28 removed
modified:test.js+38 added-28 removed
55 unmodified lines56 t.is(result.all, '132');57 });58 59 test('stdout/stderr/all available on errors', async t => {60- const err = await t.throwsAsync(execa('exit', ['2']), {message: getExitRegExp('2')});61- t.is(typeof err.stdout, 'string');62- t.is(typeof err.stderr, 'string');63- t.is(typeof err.all, 'string');60+ const error = await t.throwsAsync(execa('exit', ['2']), {message: getExitRegExp('2')});61+ t.is(typeof error.stdout, 'string');62+ t.is(typeof error.stderr, 'string');63+ t.is(typeof error.all, 'string');64 });65 66 test('include stdout and stderr in errors for improved debugging', async t => {67 await t.throwsAsync(execa('fixtures/error-message.js'), {message: STDERR_STDOUT_REGEXP, code: 1});11 unmodified lines79 await t.throwsAsync(execa('fixtures/error-message.js', {stdio: [undefined, 'inherit', 'inherit']}), {message: NO_NEWLINES_REGEXP});80 });81 82 test('do not include `stdout` in errors when set to `inherit`', async t => {83- const err = await t.throwsAsync(execa('fixtures/error-message.js', {stdout: 'inherit'}), {message: /stderr/});84- t.notRegex(err.message, /stdout/);83+ const error = await t.throwsAsync(execa('fixtures/error-message.js', {stdout: 'inherit'}), {message: /stderr/});84+ t.notRegex(error.message, /stdout/);85 });86 87 test('do not include `stderr` in errors when set to `inherit`', async t => {88- const err = await t.throwsAsync(execa('fixtures/error-message.js', {stderr: 'inherit'}), {message: /stdout/});89- t.notRegex(err.message, /stderr/);88+ const error = await t.throwsAsync(execa('fixtures/error-message.js', {stderr: 'inherit'}), {message: /stdout/});89+ t.notRegex(error.message, /stderr/);90 });91 92 test('pass `stdout` to a file descriptor', async t => {93 const file = tempfile('.txt');17 unmodified lines111 t.is(stdout, 'foo\nbar');112 });113 114 test('forbid string arguments together with array arguments', t => {115- t.throws(() => execa('node fixtures/echo foo bar', ['foo', 'bar']), /Arguments cannot be inside/);115+ t.throws(() => {116+ execa('node fixtures/echo foo bar', ['foo', 'bar']);117+ }, /Arguments cannot be inside/);118 });119 120 test('ignore consecutive spaces in string arguments', async t => {121 const {stdout} = await execa('node fixtures/echo foo bar');25 unmodified lines147 t.is(stdout, 'foo');148 });149 150 test('execa.sync() throws error if written to stderr', t => {151+ t.throws(() => {152+ execa.sync('foo');149- t.throws(() => execa.sync('foo'), process.platform === 'win32' ? /'foo' is not recognized as an internal or external command/ : /spawnSync foo ENOENT/);153+ }, process.platform === 'win32' ? /'foo' is not recognized as an internal or external command/ : /spawnSync foo ENOENT/);154 });155 156 test('execa.sync() includes stdout and stderr in errors for improved debugging', t => {153- t.throws(() => execa.sync('node', ['fixtures/error-message.js']), {message: STDERR_STDOUT_REGEXP, code: 1});157+ t.throws(() => {158+ execa.sync('node', ['fixtures/error-message.js']);159+ }, {message: STDERR_STDOUT_REGEXP, code: 1});160 });161 162 test('skip throwing when using reject option in execa.sync()', t => {157- const err = execa.sync('node', ['fixtures/error-message.js'], {reject: false});158- t.is(typeof err.stdout, 'string');159- t.is(typeof err.stderr, 'string');163+ const error = execa.sync('node', ['fixtures/error-message.js'], {reject: false});164+ t.is(typeof error.stdout, 'string');165+ t.is(typeof error.stderr, 'string');166 });167 168 test('execa.shellSync()', t => {169 const {stdout} = execa.shellSync('node fixtures/noop foo');170 t.is(stdout, 'foo');171 });172 173 test('execa.shellSync() includes stdout and stderr in errors for improved debugging', t => {168- t.throws(() => execa.shellSync('node fixtures/error-message.js'), {message: STDERR_STDOUT_REGEXP, code: 1});174+ t.throws(() => {175+ execa.shellSync('node fixtures/error-message.js');176+ }, {message: STDERR_STDOUT_REGEXP, code: 1});177 });178 179 test('skip throwing when using reject option in execa.shellSync()', t => {172- const err = execa.shellSync('node fixtures/error-message.js', {reject: false});173- t.is(typeof err.stdout, 'string');174- t.is(typeof err.stderr, 'string');180+ const error = execa.shellSync('node fixtures/error-message.js', {reject: false});181+ t.is(typeof error.stdout, 'string');182+ t.is(typeof error.stderr, 'string');183 });184 185 test('stripEof option (legacy)', async t => {186 const {stdout} = await execa('noop', ['foo'], {stripEof: false});63 unmodified lines250 });251 252 test('helpful error trying to provide an input stream in sync mode', t => {253 t.throws(246- () => execa.sync('stdin', {input: new stream.PassThrough()}),254+ () => {255+ execa.sync('stdin', {input: new stream.PassThrough()});256+ },257 /The `input` option cannot be a stream in sync mode/258 );259 });260 340 unmodified lines601 602 // TOOD: Remove the `if`-guard when targeting Node.js 10603 if (Promise.prototype.finally) {604 test('finally function is executed on success', async t => {595- let called = false;605+ let isCalled = false;606 const {stdout} = await execa('noop', ['foo']).finally(() => {597- called = true;607+ isCalled = true;608 });599- t.is(called, true);609+ t.is(isCalled, true);610 t.is(stdout, 'foo');611 });612 613 test('finally function is executed on failure', async t => {604- let called = false;605- const err = await t.throwsAsync(execa('exit', ['2']).finally(() => {606- called = true;614+ let isError = false;615+ const error = await t.throwsAsync(execa('exit', ['2']).finally(() => {616+ isError = true;617 }));608- t.is(called, true);609- t.is(typeof err.stdout, 'string');610- t.is(typeof err.stderr, 'string');618+ t.is(isError, true);619+ t.is(typeof error.stdout, 'string');620+ t.is(typeof error.stderr, 'string');621 });622 623 test('throw in finally function bubbles up on success', async t => {624 const result = await t.throwsAsync(execa('noop', ['foo']).finally(() => {66 unmodified lines