Skip to content

Commit

Permalink
Change kill signal and add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
carnun committed May 19, 2020
1 parent 10554b2 commit c120b9a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
6 changes: 3 additions & 3 deletions lib/killer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const psTree = require('ps-tree');
const spawn = require('cross-spawn');
const { exec } = require('child_process');

let KILL_SIGNAL = '15'; // SIGTERM
let KILL_SIGNAL = '-15'; // SIGTERM
let hasPS = true;

const isWindows = process.platform === 'win32';
Expand All @@ -21,10 +21,10 @@ module.exports = function kill(child) {
} else {
if (hasPS) {
psTree(child.pid, function(err, kids) {
spawn('kill', ['-s', KILL_SIGNAL, child.pid].concat( kids.map(p => p.PID) )).on('close', resolve);
spawn('kill', [KILL_SIGNAL, child.pid].concat( kids.map(p => p.PID) )).on('close', resolve);
});
} else {
exec('kill -s ' + KILL_SIGNAL + ' ' + child.pid, resolve);
exec('kill ' + KILL_SIGNAL + ' ' + child.pid, resolve);
}
}
});
Expand Down
1 change: 0 additions & 1 deletion test/client.it.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ const sinon = require('sinon');
const mochaEventually = require('mocha-eventually');
const eventually = fn => mochaEventually(fn, 8000, 50);
const TscWatchClient = require('../lib/client');
const { driver: tscWatchDriver } = require('./driver.js');

describe('Client Events', () => {
let watchClient;
Expand Down
23 changes: 23 additions & 0 deletions test/runner.it.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const { expect } = require('chai');
const runner = require('../lib/runner');

describe.only('Runner', () => {
it('Should start a long running process and kill it before it finishes', (done) => {
const kill = runner('sleep 10')
setTimeout(function() {
kill().then(function(result) {
expect(result).to.deep.equal([0,null])
done()
})
}, 1)
})
it('Should start a short running process and not kill it before it finishes', (done) => {
const kill = runner('echo')
setTimeout(function() {
kill().then(function(result) {
expect(result).to.deep.equal([1,0])
done()
})
}, 5)
})
})

0 comments on commit c120b9a

Please sign in to comment.