From 61ec20853eea066bac3199e046b3966dae8df5b4 Mon Sep 17 00:00:00 2001 From: Christopher Hiller Date: Wed, 1 Jul 2020 15:20:56 -0700 Subject: [PATCH] fixes failure output in mocha init w/o target `yargs.exit()` is not always present, apparently. it will throw in this case--we don't need to be calling it anyway. --- lib/cli/cli.js | 2 +- test/integration/init.spec.js | 46 +++++++++++++++++++++++++---------- 2 files changed, 34 insertions(+), 14 deletions(-) diff --git a/lib/cli/cli.js b/lib/cli/cli.js index 2e004ba4a3..ffbe5dada5 100755 --- a/lib/cli/cli.js +++ b/lib/cli/cli.js @@ -52,7 +52,7 @@ exports.main = (argv = process.argv.slice(2)) => { debug('caught error sometime before command handler: %O', err); yargs.showHelp(); console.error(`\n${symbols.error} ${ansi.red('ERROR:')} ${msg}`); - yargs.exit(1); + process.exitCode = 1; }) .help('help', 'Show usage information & exit') .alias('help', 'h') diff --git a/test/integration/init.spec.js b/test/integration/init.spec.js index 176b852c56..3961b27844 100644 --- a/test/integration/init.spec.js +++ b/test/integration/init.spec.js @@ -23,19 +23,39 @@ describe('init command', function() { } catch (ignored) {} }); - it('should break if no path supplied', function(done) { - invokeMocha( - ['init'], - function(err, result) { - if (err) { - return done(err); - } - expect(result, 'to have failed'); - expect(result.output, 'to match', /not enough non-option arguments/i); - done(); - }, - {stdio: 'pipe'} - ); + describe('when no path is supplied', function() { + it('should fail', function(done) { + invokeMocha( + ['init'], + function(err, result) { + if (err) { + return done(err); + } + expect( + result, + 'to have failed with output', + /not enough non-option arguments/i + ); + done(); + }, + {stdio: 'pipe'} + ); + }); + it('should not throw', function(done) { + invokeMocha( + ['init'], + function(err, result) { + if (err) { + return done(err); + } + expect(result, 'to have failed').and('not to satisfy', { + output: /throw/i + }); + done(); + }, + {stdio: 'pipe'} + ); + }); }); it('should create some files in the dest dir', function(done) {