Skip to content

Commit

Permalink
test(cli): use more descriptive name for cwd
Browse files Browse the repository at this point in the history
  • Loading branch information
armano2 committed Feb 11, 2020
1 parent a048e9e commit e869e16
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
12 changes: 3 additions & 9 deletions @commitlint/cli/src/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -430,8 +430,8 @@ test('should work with relative formatter path', async () => {

test('should print help', async () => {
const cwd = await gitBootstrap('fixtures/default');
const actual = await cli(['--help'], {cwd})();
expect(escapeCwd(actual.stdout, cwd)).toMatchInlineSnapshot(`
const actual = await cli(['--help', '--cwd', './'], {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
Expand All @@ -440,7 +440,7 @@ test('should print help', async () => {
--color, -c toggle colored output [boolean] [default: true]
--config, -g path to the config file [string]
--cwd, -d directory to execute in
[string] [default: \\"__CWD__\\"]
[string] [default: (Working Directory)]
--edit, -e read last commit message from the specified file or
fallbacks to ./.git/COMMIT_EDITMSG
[string] [default: false]
Expand Down Expand Up @@ -475,9 +475,3 @@ async function writePkg(payload: unknown, options: TestOptions) {
const result = merge(pkg, payload);
await fs.writeFile(pkgPath, JSON.stringify(result, null, ' '));
}

function escapeCwd(value: string, cwd: string): string {
return value
.replace(cwd, '__CWD__')
.replace(/(\n[ ]+)(.+__CWD__)/, `$1${' '.repeat(cwd.length - 7)}$2`);
}
1 change: 1 addition & 0 deletions @commitlint/cli/src/cli.ts
Original file line number Diff line number Diff line change
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 Down

0 comments on commit e869e16

Please sign in to comment.