Skip to content

Commit

Permalink
Add support for custom exit code in case of failure (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
mischah authored and chrkhl committed Jul 8, 2019
1 parent 5229060 commit 63a38b9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
6 changes: 5 additions & 1 deletion cli.js
Expand Up @@ -20,13 +20,14 @@ const cli = meow(`
Note: You cannot use --topLevelOnly together
with --depth.
--depth Max depth of the dependency tree analysis.
default: Infinity
Default: Infinity
Note: You cannot use --depth together
with --topLevelOnly.
--blacklist -black Interpret content of checklist as blacklist.
--development -dev Analyze the dependency tree for devDependencies.
--production -prod Analyze the dependency tree for dependencies.
--verbose Lists unallowed dependencies.
--exitCode Exit code in case of unallowed dependencies. Default: 1
--version -v Displays the version number.
--help -h Displays the help.
Expand Down Expand Up @@ -64,6 +65,9 @@ const cli = meow(`
},
verbose: {
type: 'boolean'
},
exitCode: {
type: 'number'
}
}
});
Expand Down
2 changes: 1 addition & 1 deletion lib/run-cli.js
Expand Up @@ -52,7 +52,7 @@ const run = cli => {
}
}

process.exit(1);
process.exit(cli.flags.exitCode || 1);
};

module.exports = run;
13 changes: 12 additions & 1 deletion lib/run-cli.test.js
Expand Up @@ -146,7 +146,7 @@ describe('run(cli)', () => {
expect(spinnerFail).toHaveBeenCalledWith('Found 1 unallowed dependencies!');
});

it('calls process.exit(1)', () => {
it('calls process.exit(1) by default', () => {
const cli = {
input: [ './path/to/checklist.json' ],
flags: { }
Expand All @@ -156,6 +156,17 @@ describe('run(cli)', () => {

expect(processExit).toHaveBeenCalledWith(1);
});

it('calls process.exit() with the defined exit code', () => {
const cli = {
input: [ './path/to/checklist.json' ],
flags: { exitCode: 2 }
};

run(cli);

expect(processExit).toHaveBeenCalledWith(2);
});
});

describe('when analysis succeeded', () => {
Expand Down

0 comments on commit 63a38b9

Please sign in to comment.