Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Success Conditon All But First #281

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 6 additions & 4 deletions README.md
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
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
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
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 }]);
});
});