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

Commit

Permalink
fix(defaults): macOS env.APPDATA should be undefined (#27)
Browse files Browse the repository at this point in the history
* fix(defaults): macOS env.APPDATA should be undefined

Close #24

* fix(defaults): macOS env.APPDATA should be undefined

Close #24
  • Loading branch information
jiangyuan authored and Kent C. Dodds committed Aug 29, 2016
1 parent b7f6245 commit 9976b5e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
6 changes: 4 additions & 2 deletions src/index.js
Expand Up @@ -14,7 +14,7 @@ function crossEnv(args) {
}
}

function getCommandArgsAndEnvVars(args) {
function getCommandArgsAndEnvVars(args) { // eslint-disable-line
let command;
const envVars = assign({}, process.env);
const commandArgs = args.slice();
Expand All @@ -27,7 +27,9 @@ function getCommandArgsAndEnvVars(args) {
command = shifted;
break;
}
envVars.APPDATA = process.env.APPDATA;
if (process.env.APPDATA) {
envVars.APPDATA = process.env.APPDATA;
}
}
return [command, commandArgs, envVars];
}
23 changes: 19 additions & 4 deletions src/index.test.js
Expand Up @@ -28,11 +28,19 @@ describe(`cross-env`, () => {
}, 'FOO_ENV=production');
});

it(`should APPDATA be undefined and not string`, () => {
testEnvSetting({
FOO_ENV: 'production',
APPDATA: 2
}, 'FOO_ENV=production');
});

it(`should handle multiple env variables`, () => {
testEnvSetting({
FOO_ENV: 'production',
BAR_ENV: 'dev'
}, 'FOO_ENV=production', 'BAR_ENV=dev');
BAR_ENV: 'dev',
APPDATA: '0'
}, 'FOO_ENV=production', 'BAR_ENV=dev', 'APPDATA=0');
});

it(`should handle special characters`, () => {
Expand Down Expand Up @@ -74,11 +82,18 @@ describe(`cross-env`, () => {
});

function testEnvSetting(expected, ...envSettings) {
if (expected.APPDATA === 2) { // kill the APPDATA to test both is undefined
delete process.env.APPDATA;
delete expected.APPDATA;
} else if (!process.env.APPDATA && expected.APPDATA === '0') { // set APPDATA and test it
process.env.APPDATA = '0';
}
const ret = crossEnv([...envSettings, 'echo', 'hello world']);
const env = {};
env.APPDATA = process.env.APPDATA;
if (process.env.APPDATA) {
env.APPDATA = process.env.APPDATA;
}
assign(env, expected);

expect(ret, 'returns what spawn returns').to.equal(spawned);
expect(proxied['cross-spawn'].spawn).to.have.been.calledOnce;
expect(proxied['cross-spawn'].spawn).to.have.been.calledWith(
Expand Down

0 comments on commit 9976b5e

Please sign in to comment.