Skip to content

Commit

Permalink
added success conditon all but first
Browse files Browse the repository at this point in the history
  • Loading branch information
woody34 committed Jun 1, 2021
1 parent 10ff00c commit c1c096d
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 7 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,12 @@ General
"|" [default: ","]
-r, --raw Output only raw output of processes, disables prettifying
and concurrently coloring. [boolean]
-s, --success Return exit code of zero or one based on the success or
failure of the "first" child to terminate, the "last
child", or succeed only if "all" child processes succeed.
[choices: "first", "last", "all"] [default: "all"]
-s, --success Return exit code of zero or one based on the success or failure
of the "first" child to terminate, the "last child", "all-but-
first" child success, or succeeed only if "all" child processes
succeed
[choices: "first", "last", "all-but-first", "all"]
[default: "all"]
--no-color Disables colors from logging [boolean]
Prefix styling
Expand Down
7 changes: 4 additions & 3 deletions bin/concurrently.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ const args = yargs
alias: 'success',
describe:
'Return exit code of zero or one based on the success or failure ' +
'of the "first" child to terminate, the "last child", or succeed ' +
'only if "all" child processes succeed.',
choices: ['first', 'last', 'all'],
'of the "first" child to terminate, the "last child", all but ' +
'the first child success, or succeeed only if "all" child ' +
'processes succeed.',
choices: ['first', 'last', 'all-but-first', 'all'],
default: defaults.success
},
'r': {
Expand Down
4 changes: 4 additions & 0 deletions src/completion-listener.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ module.exports = class CompletionListener {
case 'last':
return exitCodes[exitCodes.length - 1] === 0;

case 'all-but-first':
const [, ...allButFirst] = exitCodes;
return allButFirst.every(code => code === 0);

default:
return exitCodes.every(exitCode => exitCode === 0);
/* eslint-enable indent */
Expand Down
30 changes: 30 additions & 0 deletions src/completion-listener.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,33 @@ describe('with success condition set to last', () => {
return expect(result).rejects.toEqual([{ exitCode: 0 }, { exitCode: 1 }]);
});
});

describe('with success condition set to all-but-first', () => {
beforeEach(() => {
commands.push(createFakeCommand('oof'));
});

it('succeeds if all but first process to exit has code 0', () => {
const result = createController('all-but-first').listen(commands);

commands[0].close.next({ exitCode: 1 });
commands[1].close.next({ exitCode: 0 });
commands[2].close.next({ exitCode: 0 });

scheduler.flush();

return expect(result).resolves.toEqual([{ exitCode: 1 }, { exitCode: 0 }, { exitCode: 0 }]);
});

it('fails if last process to exit has non-0 code', () => {
const result = createController('first').listen(commands);

commands[0].close.next({ exitCode: 1 });
commands[1].close.next({ exitCode: 0 });
commands[2].close.next({ exitCode: 1 });

scheduler.flush();

return expect(result).rejects.toEqual([{ exitCode: 1 }, { exitCode: 0 }, { exitCode: 1 }]);
});
});

0 comments on commit c1c096d

Please sign in to comment.