Skip to content

Commit

Permalink
test(cli): add unit test for help and version commands
Browse files Browse the repository at this point in the history
  • Loading branch information
armano2 committed Feb 11, 2020
1 parent 4246081 commit 712f4cd
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
41 changes: 41 additions & 0 deletions @commitlint/cli/src/cli.test.ts
Expand Up @@ -428,6 +428,47 @@ test('should work with relative formatter path', async () => {
expect(actual.exitCode).toBe(0);
});

test('should print help', async () => {
const cwd = await gitBootstrap('fixtures/default');
const actual = await cli(['--help'], {cwd})();
expect(actual.stdout).toMatchInlineSnapshot(`
"@commitlint/cli@8.3.5 - Lint your commit messages
[input] reads from stdin if --edit, --env, --from and --to are omitted
Options:
--color, -c toggle colored output [boolean] [default: true]
--config, -g path to the config file [string]
--cwd, -d directory to execute in
[string] [default: (Working Directory)]
--edit, -e read last commit message from the specified file or
fallbacks to ./.git/COMMIT_EDITMSG
[string] [default: false]
--env, -E check message in the file at path given by environment
variable value [string]
--extends, -x array of shareable configurations to extend [array]
--help-url, -H help url in error message [string]
--from, -f lower end of the commit range to lint; applies if
edit=false [string]
--format, -o output format of the results [string]
--parser-preset, -p configuration preset to use for
conventional-commits-parser [string]
--quiet, -q toggle console output [boolean] [default: false]
--to, -t upper end of the commit range to lint; applies if
edit=false [string]
--verbose, -V enable verbose output for reports without problems
[boolean]
-v, --version display version information [boolean]
-h, --help Show help [boolean]"
`);
});

test('should print version', async () => {
const cwd = await gitBootstrap('fixtures/default');
const actual = await cli(['--version'], {cwd})();
expect(actual.stdout).toMatch('@commitlint/cli@');
});

async function writePkg(payload: unknown, options: TestOptions) {
const pkgPath = path.join(options.cwd, 'package.json');
const pkg = JSON.parse(await fs.readFile(pkgPath, 'utf-8'));
Expand Down
3 changes: 2 additions & 1 deletion @commitlint/cli/src/cli.ts
Expand Up @@ -36,6 +36,7 @@ const cli = yargs
cwd: {
alias: 'd',
default: process.cwd(),
defaultDescription: '(Working Directory)',
description: 'directory to execute in',
type: 'string'
},
Expand All @@ -60,7 +61,7 @@ const cli = yargs
'help-url': {
alias: 'H',
type: 'string',
description: 'helpurl in error message'
description: 'help url in error message'
},
from: {
alias: 'f',
Expand Down

0 comments on commit 712f4cd

Please sign in to comment.