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

Commit

Permalink
fix(env): checks if windows platform, then send in APPDATA env var.
Browse files Browse the repository at this point in the history
  • Loading branch information
NogsMPLS committed Nov 11, 2015
1 parent 452ea5a commit a18d2b3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
}
},
"dependencies": {
"cross-spawn": "2.0.0",
"cross-spawn-async": "2.0.0",
"manage-path": "2.0.0"
}
}
5 changes: 4 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {spawn} from 'cross-spawn';
import {spawn} from 'cross-spawn-async';
import getPathVar from 'manage-path/dist/get-path-var';
export default crossEnv;

Expand All @@ -24,6 +24,9 @@ function getCommandArgsAndEnvVars(args) {
command = shifted;
break;
}
if (process.platform === 'win32') {
envVars.APPDATA = process.env.APPDATA;
}
}
return [command, commandArgs, envVars];
}
13 changes: 8 additions & 5 deletions src/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ chai.use(sinonChai);

const {expect} = chai;
const proxied = {
'cross-spawn': {
'cross-spawn-async': {
spawn: sinon.spy(() => 'spawn-returned')
}
};
Expand All @@ -17,7 +17,7 @@ const crossEnv = proxyquire('./index', proxied);
describe(`cross-env`, () => {

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

it(`should set environment variables and run the remaining command`, () => {
Expand All @@ -30,20 +30,23 @@ describe(`cross-env`, () => {

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

function testEnvSetting(...envSettings) {
const ret = crossEnv([...envSettings, 'echo', 'hello world']);
const env = {[getPathVar()]: process.env[getPathVar()]};
if (process.platform === 'win32') {
env.APPDATA = process.env.APPDATA;
}
envSettings.forEach(setting => {
const [prop, val] = setting.split('=');
env[prop] = val;
});

expect(ret, 'returns what spawn returns').to.equal('spawn-returned');
expect(proxied['cross-spawn'].spawn).to.have.been.calledOnce;
expect(proxied['cross-spawn'].spawn).to.have.been.calledWith(
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}
);
}
Expand Down

0 comments on commit a18d2b3

Please sign in to comment.