Skip to content
Myr

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

1 file+38 added−28 removed

modified:test.js+38 added-28 removed
55 unmodified lines
56 t.is(result.all, '132');57});5859test('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});6566test('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 lines
79 await t.throwsAsync(execa('fixtures/error-message.js', {stdio: [undefined, 'inherit', 'inherit']}), {message: NO_NEWLINES_REGEXP});80});8182test('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});8687test('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});9192test('pass `stdout` to a file descriptor', async t => {93 const file = tempfile('.txt');
17 unmodified lines
111 t.is(stdout, 'foo\nbar');112});113114test('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});119120test('ignore consecutive spaces in string arguments', async t => {121 const {stdout} = await execa('node fixtures/echo foo bar');
25 unmodified lines
147 t.is(stdout, 'foo');148});149150test('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});155156test('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});161162test('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});167168test('execa.shellSync()', t => {169 const {stdout} = execa.shellSync('node fixtures/noop foo');170 t.is(stdout, 'foo');171});172173test('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});178179test('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});184185test('stripEof option (legacy)', async t => {186 const {stdout} = await execa('noop', ['foo'], {stripEof: false});
63 unmodified lines
250});251252test('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 lines
601602// TOOD: Remove the `if`-guard when targeting Node.js 10603if (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 });612613 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 });622623 test('throw in finally function bubbles up on success', async t => {624 const result = await t.throwsAsync(execa('noop', ['foo']).finally(() => {
66 unmodified lines