Skip to content
This repository has been archived by the owner on Jan 6, 2021. It is now read-only.

Commit

Permalink
feat(kill): Propagate SIGTERM to created process (#20)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Processes that emit SIGTERM now will kill the child process. You can likely upgrade without any trouble.
  • Loading branch information
marcioj authored and Kent C. Dodds committed Jul 13, 2016
1 parent f26a2af commit 8ff5555
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ function crossEnv(args) {
const [command, commandArgs, env] = getCommandArgsAndEnvVars(args);
if (command) {
const proc = spawn(command, commandArgs, {stdio: 'inherit', env});
process.on('SIGTERM', () => proc.kill('SIGTERM'));
proc.on('exit', process.exit);
return proc;
}
Expand Down
12 changes: 11 additions & 1 deletion src/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import assign from 'lodash.assign';
chai.use(sinonChai);

const {expect} = chai;
const spawned = {on: sinon.spy()};
const spawned = {on: sinon.spy(), kill: sinon.spy()};
const proxied = {
'cross-spawn': {
spawn: sinon.spy(() => spawned)
Expand Down Expand Up @@ -58,11 +58,21 @@ describe(`cross-env`, () => {
FOO_ENV: 'foo=bar'
}, 'FOO_ENV="foo=bar"');
});

it(`should do nothing given no command`, () => {
crossEnv([]);
expect(proxied['cross-spawn'].spawn).to.have.not.been.called;
});

it(`should propage SIGTERM signal`, () => {
testEnvSetting({
FOO_ENV: 'foo=bar'
}, 'FOO_ENV="foo=bar"');

process.emit('SIGTERM');
expect(spawned.kill).to.have.been.calledWith('SIGTERM');
});

function testEnvSetting(expected, ...envSettings) {
const ret = crossEnv([...envSettings, 'echo', 'hello world']);
const env = {};
Expand Down

0 comments on commit 8ff5555

Please sign in to comment.