diff --git a/src/index.js b/src/index.js index b5f2ac7..234a42b 100644 --- a/src/index.js +++ b/src/index.js @@ -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; } diff --git a/src/index.test.js b/src/index.test.js index 8f01b2d..43b0515 100644 --- a/src/index.test.js +++ b/src/index.test.js @@ -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) @@ -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 = {};