This repository has been archived by the owner on Jan 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 245
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: remove env variables that don't exist from the converted command…
…s in Windows. (#149) * Remove trailing comma on arguments list (unsupported in Node v6 LTS) * Remove non-defined env variables from the command (and command args), since those have a different behaviour in Windows. * Fixed tests * Added new test cases * Fixed lint error
- Loading branch information
Showing
4 changed files
with
42 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
const jestConfig = require('kcd-scripts/config').jest | ||
|
||
jestConfig.coveragePathIgnorePatterns = jestConfig.coveragePathIgnorePatterns.concat( | ||
['/bin/'], | ||
['/bin/'] | ||
) | ||
module.exports = jestConfig |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,74 @@ | ||
import isWindowsMock from 'is-windows' | ||
import commandConvert from '../command' | ||
|
||
const env = { | ||
test: 'a', | ||
test1: 'b', | ||
test2: 'c', | ||
test3: 'd', | ||
'empty_var': '' | ||
} | ||
|
||
beforeEach(() => { | ||
isWindowsMock.__mock.reset() | ||
}) | ||
|
||
test(`converts unix-style env variable usage for windows`, () => { | ||
isWindowsMock.__mock.returnValue = true | ||
expect(commandConvert('$test')).toBe('%test%') | ||
expect(commandConvert('$test', env)).toBe('%test%') | ||
}) | ||
|
||
test(`leaves command unchanged when not a variable`, () => { | ||
expect(commandConvert('test')).toBe('test') | ||
expect(commandConvert('test', env)).toBe('test') | ||
}) | ||
|
||
test(`doesn't convert windows-style env variable`, () => { | ||
isWindowsMock.__mock.returnValue = false | ||
expect(commandConvert('%test%')).toBe('%test%') | ||
expect(commandConvert('%test%', env)).toBe('%test%') | ||
}) | ||
|
||
test(`leaves variable unchanged when using correct operating system`, () => { | ||
isWindowsMock.__mock.returnValue = false | ||
expect(commandConvert('$test')).toBe('$test') | ||
expect(commandConvert('$test', env)).toBe('$test') | ||
}) | ||
|
||
test(`is stateless`, () => { | ||
// this test prevents falling into regexp traps like this: | ||
// http://stackoverflow.com/a/1520853/971592 | ||
isWindowsMock.__mock.returnValue = true | ||
expect(commandConvert('$test')).toBe(commandConvert('$test')) | ||
expect(commandConvert('$test', env)).toBe(commandConvert('$test', env)) | ||
}) | ||
|
||
test(`converts embedded unix-style env variables usage for windows`, () => { | ||
isWindowsMock.__mock.returnValue = true | ||
expect(commandConvert('$test1/$test2/$test3')).toBe('%test1%/%test2%/%test3%') | ||
expect(commandConvert('$test1/$test2/$test3', env)).toBe('%test1%/%test2%/%test3%') | ||
}) | ||
|
||
// eslint-disable-next-line max-len | ||
test(`leaves embedded variables unchanged when using correct operating system`, () => { | ||
isWindowsMock.__mock.returnValue = false | ||
expect(commandConvert('$test1/$test2/$test3')).toBe('$test1/$test2/$test3') | ||
expect(commandConvert('$test1/$test2/$test3', env)).toBe('$test1/$test2/$test3') | ||
}) | ||
|
||
test(`converts braced unix-style env variable usage for windows`, () => { | ||
isWindowsMock.__mock.returnValue = true | ||
// eslint-disable-next-line no-template-curly-in-string | ||
expect(commandConvert('${test}')).toBe('%test%') | ||
expect(commandConvert('${test}', env)).toBe('%test%') | ||
}) | ||
|
||
test(`removes non-existent variables from the converted command`, () => { | ||
isWindowsMock.__mock.returnValue = true | ||
expect(commandConvert('$test1/$foo/$test2', env)).toBe('%test1%//%test2%') | ||
}) | ||
|
||
test(`removes empty variables from the converted command`, () => { | ||
isWindowsMock.__mock.returnValue = true | ||
expect(commandConvert('$foo/$test/$empty_var', env)).toBe('/%test%/') | ||
}) | ||
|
||
test(`normalizes command on windows`, () => { | ||
isWindowsMock.__mock.returnValue = true | ||
// index.js calls `commandConvert` with `normalize` param | ||
// as `true` for command only | ||
expect(commandConvert('./cmd.bat', true)).toBe('cmd.bat') | ||
expect(commandConvert('./cmd.bat', env, true)).toBe('cmd.bat') | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters