Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
130 additions
and
58 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
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,4 +1,13 @@ | ||
// return the PATH array in a cross-platform way | ||
const PATH = process.env.PATH || process.env.Path || process.env.path | ||
const { delimiter } = require('path') | ||
module.exports = PATH.split(delimiter) | ||
|
||
const keys = ['PATH', 'Path', 'path'] | ||
const key = keys.find(k => process.env[k]) | ||
const value = process.env[key] | ||
|
||
module.exports = { | ||
PATH: value.split(delimiter), | ||
key, | ||
keys, | ||
value, | ||
} |
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
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
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,12 +1,38 @@ | ||
const t = require('tap') | ||
const mod = '../../../lib/utils/path.js' | ||
const delim = require('../../../lib/utils/is-windows.js') ? ';' : ':' | ||
Object.defineProperty(process, 'env', { | ||
value: {}, | ||
const mockGlobals = require('../../fixtures/mock-globals') | ||
const { delimiter } = require('path') | ||
|
||
const mockPath = () => t.mock('../../../lib/utils/path.js') | ||
|
||
mockGlobals(t, { 'process.env': {} }, { replace: true }) | ||
t.strictSame(process.env, {}) | ||
|
||
t.test('uppercase', async t => { | ||
const parts = ['foo', 'bar', 'baz'] | ||
mockGlobals(t, { 'process.env.PATH': parts.join(delimiter) }) | ||
t.match(mockPath(), { | ||
PATH: parts, | ||
key: 'PATH', | ||
value: parts.join(delimiter), | ||
}) | ||
}) | ||
|
||
t.test('mixed case', async t => { | ||
const parts = ['a', 'b', 'c'] | ||
mockGlobals(t, { 'process.env.Path': parts.join(delimiter) }) | ||
t.match(mockPath(), { | ||
PATH: parts, | ||
key: 'Path', | ||
value: parts.join(delimiter), | ||
}) | ||
}) | ||
|
||
t.test('lowercase', async t => { | ||
const parts = ['x', 'y', 'z'] | ||
mockGlobals(t, { 'process.env.path': parts.join(delimiter) }) | ||
t.match(mockPath(), { | ||
PATH: parts, | ||
key: 'path', | ||
value: parts.join(delimiter), | ||
}) | ||
}) | ||
process.env.path = ['foo', 'bar', 'baz'].join(delim) | ||
t.strictSame(t.mock(mod), ['foo', 'bar', 'baz']) | ||
process.env.Path = ['a', 'b', 'c'].join(delim) | ||
t.strictSame(t.mock(mod), ['a', 'b', 'c']) | ||
process.env.PATH = ['x', 'y', 'z'].join(delim) | ||
t.strictSame(t.mock(mod), ['x', 'y', 'z']) |