diff --git a/bin/cli.js b/bin/cli.js index e71422a784..e97bbd1df9 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -341,7 +341,7 @@ function invoke(env) { .catch(exit); }); - if (!commander._args.length) { + if (!process.argv.slice(2).length) { commander.outputHelp(); } diff --git a/package.json b/package.json index 4e2d6298ab..19f843ac0c 100644 --- a/package.json +++ b/package.json @@ -79,7 +79,7 @@ "JSONStream": "^1.3.5", "chai": "^4.2.0", "chai-subset-in-order": "^2.1.3", - "cli-testlab": "^1.8.0", + "cli-testlab": "^1.10.0", "coveralls": "^3.0.9", "cross-env": "^6.0.3", "dtslint": "2.0.2", diff --git a/test/cli/help.spec.js b/test/cli/help.spec.js new file mode 100644 index 0000000000..a503b7f655 --- /dev/null +++ b/test/cli/help.spec.js @@ -0,0 +1,32 @@ +'use strict'; + +const path = require('path'); +const { execCommand } = require('cli-testlab'); + +const KNEX = path.normalize(__dirname + '/../../bin/cli.js'); + +describe('help', () => { + it('Prints help', () => { + return execCommand(`node ${KNEX} --help`, { + expectedOutput: 'Usage', + }); + }); + + it('Prints help using -h flag', () => { + return execCommand(`node ${KNEX} -h`, { + expectedOutput: 'Usage', + }); + }); + + it('Prints help when no arguments are given', () => { + return execCommand(`node ${KNEX}`, { + expectedOutput: 'Usage', + }); + }); + + it('Does not print help when argument is given', () => { + return execCommand(`node ${KNEX} -V`, { + notExpectedOutput: 'Usage', + }); + }); +}); diff --git a/test/index.js b/test/index.js index da39d21087..37331aa2bc 100644 --- a/test/index.js +++ b/test/index.js @@ -93,4 +93,5 @@ describe('CLI tests', function() { require('./cli/migrate-make.spec'); require('./cli/seed-make.spec'); require('./cli/version.spec'); + require('./cli/help.spec'); });