Skip to content

Commit

Permalink
Include killed boolean in command result (#250)
Browse files Browse the repository at this point in the history
  • Loading branch information
Roaders committed May 9, 2021
1 parent e8f0706 commit d38ab32
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 5 deletions.
6 changes: 3 additions & 3 deletions README.md
Expand Up @@ -258,9 +258,9 @@ concurrently can be used programmatically by using the API documented below:

> Returns: a `Promise` that resolves if the run was successful (according to `successCondition` option),
> or rejects, containing an array of objects with information for each command that has been run, in the order
> that the commands terminated. The objects have the shape `{ command, index, exitCode }`, where `command` is the object
> passed in the `commands` array and `index` its index there. Default values (empty strings or objects) are returned for
> the fields that were not specified.
> that the commands terminated. The objects have the shape `{ command, index, exitCode, killed }`, where `command` is the object
> passed in the `commands` array, `index` its index there and `killed` indicates if the process was killed as a result of
> `killOthers`. Default values (empty strings or objects) are returned for the fields that were not specified.
Example:

Expand Down
2 changes: 1 addition & 1 deletion bin/concurrently.spec.js
Expand Up @@ -300,7 +300,7 @@ describe('--kill-others-on-fail', () => {
});

describe('--handle-input', () => {
it('is alised to -i', done => {
it('is aliased to -i', done => {
const child = run('-i "node fixtures/read-echo.js"');
child.log.subscribe(line => {
if (/READING/.test(line)) {
Expand Down
3 changes: 3 additions & 0 deletions src/command.js
Expand Up @@ -14,6 +14,7 @@ module.exports = class Command {
this.killProcess = killProcess;
this.spawn = spawn;
this.spawnOpts = spawnOpts;
this.killed = false;

this.error = new Rx.Subject();
this.close = new Rx.Subject();
Expand Down Expand Up @@ -41,6 +42,7 @@ module.exports = class Command {
},
index: this.index,
exitCode: exitCode === null ? signal : exitCode,
killed: this.killed,
});
});
child.stdout && pipeTo(Rx.fromEvent(child.stdout, 'data'), this.stdout);
Expand All @@ -50,6 +52,7 @@ module.exports = class Command {

kill(code) {
if (this.killable) {
this.killed = true;
this.killProcess(this.pid, code);
}
}
Expand Down
16 changes: 16 additions & 0 deletions src/command.spec.js
Expand Up @@ -60,6 +60,7 @@ describe('#start()', () => {

command.close.subscribe(data => {
expect(data.exitCode).toBe(0);
expect(data.killed).toBe(false);
expect(command.process).toBeUndefined();
done();
});
Expand All @@ -74,6 +75,7 @@ describe('#start()', () => {

command.close.subscribe(data => {
expect(data.exitCode).toBe('SIGKILL');
expect(data.killed).toBe(false);
done();
});

Expand All @@ -98,6 +100,7 @@ describe('#start()', () => {

command.close.subscribe(data => {
expect(data.command).toEqual(commandInfo);
expect(data.killed).toBe(false);
expect(data.index).toBe(1);
done();
});
Expand Down Expand Up @@ -164,4 +167,17 @@ describe('#kill()', () => {

expect(killProcess).not.toHaveBeenCalled();
});

it('marks the command as killed', done => {
command.start();

command.close.subscribe(data => {
expect(data.exitCode).toBe(1);
expect(data.killed).toBe(true);
done();
});

command.kill();
process.emit('close', 1, null);
});
});
2 changes: 1 addition & 1 deletion src/completion-listener.js
@@ -1,5 +1,5 @@
const Rx = require('rxjs');
const { bufferCount, map, switchMap, take } = require('rxjs/operators');
const { bufferCount, switchMap, take } = require('rxjs/operators');

module.exports = class CompletionListener {
constructor({ successCondition, scheduler }) {
Expand Down

0 comments on commit d38ab32

Please sign in to comment.