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

Commit

Permalink
Merge pull request #9 from nkbt/exit-code
Browse files Browse the repository at this point in the history
fix(spawn): Propagate spawned process exit code
  • Loading branch information
Kent C. Dodds committed Jan 3, 2016
2 parents 412cb1d + 559e3d1 commit 20d35cd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ const envSetterRegex = /(\w+)=('(.+)'|"(.+)"|(.+))/;
function crossEnv(args) {
const [command, commandArgs, env] = getCommandArgsAndEnvVars(args);
if (command) {
return spawn(command, commandArgs, {stdio: 'inherit', env});
const proc = spawn(command, commandArgs, {stdio: 'inherit', env});
proc.on('exit', process.exit);
return proc;
}
}

Expand Down
9 changes: 7 additions & 2 deletions src/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import assign from 'lodash.assign';
chai.use(sinonChai);

const {expect} = chai;
const spawned = {on: sinon.spy()};
const proxied = {
'cross-spawn-async': {
spawn: sinon.spy(() => 'spawn-returned')
spawn: sinon.spy(() => spawned)
}
};

Expand All @@ -19,6 +20,7 @@ describe(`cross-env`, () => {

beforeEach(() => {
proxied['cross-spawn-async'].spawn.reset();
spawned.on.reset();
});

it(`should set environment variables and run the remaining command`, () => {
Expand Down Expand Up @@ -69,13 +71,16 @@ describe(`cross-env`, () => {
env.APPDATA = process.env.APPDATA;
assign(env, expected);

expect(ret, 'returns what spawn returns').to.equal('spawn-returned');
expect(ret, 'returns what spawn returns').to.equal(spawned);
expect(proxied['cross-spawn-async'].spawn).to.have.been.calledOnce;
expect(proxied['cross-spawn-async'].spawn).to.have.been.calledWith(
'echo', ['hello world'], {
stdio: 'inherit',
env: assign({}, process.env, env)
}
);

expect(spawned.on).to.have.been.calledOnce;
expect(spawned.on).to.have.been.calledWith('exit');
}
});

0 comments on commit 20d35cd

Please sign in to comment.