-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: bypass libnpmconfig bug on win32
Removed libnpmconfig, use direct "npm config command".
- Loading branch information
Showing
3 changed files
with
63 additions
and
39 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
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,67 +1,87 @@ | ||
const test = require('ava'); | ||
const {execSync} = require('child_process'); | ||
const getAgent = require('../lib/get-https-proxy-agent'); | ||
|
||
function getAgentWith(mock) { | ||
for (let key in mock.npmrc) { | ||
execSync(`npm set ${key} ${mock.npmrc[key]}`); | ||
} | ||
for (let key in mock.env) { | ||
process.env[key] = mock.env[key]; | ||
} | ||
try { | ||
return getAgent(); | ||
} finally { | ||
for (let key in mock.npmrc) { | ||
execSync(`npm config delete ${key}`); | ||
} | ||
for (let key in mock.env) { | ||
delete process.env[key]; | ||
} | ||
} | ||
} | ||
|
||
test.serial('getHttpsProxyAgent gets https-proxy from npmrc', async t => { | ||
|
||
const agent = getAgent({ | ||
_npmrc: { 'https-proxy' : 'https://domain1.com'}, | ||
_env: {} | ||
const agent = getAgentWith({ | ||
npmrc: { 'https-proxy' : 'https://domain1.com'}, | ||
env: {} | ||
}); | ||
t.is(agent.proxy.href, 'https://domain1.com/'); | ||
}); | ||
|
||
test.serial('getHttpsProxyAgent gets proxy from npmrc', async t => { | ||
const agent = getAgent({ | ||
_npmrc: { 'proxy' : 'https://domain2.com:80443'}, | ||
_env: {} | ||
const agent = getAgentWith({ | ||
npmrc: { 'proxy' : 'https://domain2.com:80443'}, | ||
env: {} | ||
}); | ||
t.is(agent.proxy.href, 'https://domain2.com:80443/'); | ||
}); | ||
|
||
test.serial('getHttpsProxyAgent gets proxy from npmrc, but reject non-http proxy', async t => { | ||
const agent = getAgent({ | ||
_npmrc: { 'proxy' : 'what.ever.proxy'}, | ||
_env: {} | ||
const agent = getAgentWith({ | ||
npmrc: { 'proxy' : 'what.ever.proxy'}, | ||
env: {} | ||
}); | ||
t.is(agent, undefined); | ||
}); | ||
|
||
test.serial('getHttpsProxyAgent gets HTTPS_PROXY from env', async t => { | ||
const agent = getAgent({ | ||
_npmrc: {}, | ||
_env: {HTTPS_PROXY: 'https://domain3.com'} | ||
const agent = getAgentWith({ | ||
npmrc: {}, | ||
env: {HTTPS_PROXY: 'https://domain3.com'} | ||
}); | ||
t.is(agent.proxy.href, 'https://domain3.com/'); | ||
}); | ||
|
||
test.serial('getHttpsProxyAgent gets https_proxy from env', async t => { | ||
const agent = getAgent({ | ||
_npmrc: {}, | ||
_env: {https_proxy: 'https://domain4.com'} | ||
const agent = getAgentWith({ | ||
npmrc: {}, | ||
env: {https_proxy: 'https://domain4.com'} | ||
}); | ||
t.is(agent.proxy.href, 'https://domain4.com/'); | ||
}); | ||
|
||
test.serial('getHttpsProxyAgent gets HTTP_PROXY from env', async t => { | ||
const agent = getAgent({ | ||
_npmrc: {}, | ||
_env: {HTTP_PROXY: 'http://domain5.com'} | ||
const agent = getAgentWith({ | ||
npmrc: {}, | ||
env: {HTTP_PROXY: 'http://domain5.com'} | ||
}); | ||
t.is(agent.proxy.href, 'http://domain5.com/'); | ||
}); | ||
|
||
test.serial('getHttpsProxyAgent gets http_proxy from env', async t => { | ||
const agent = getAgent({ | ||
_npmrc: {}, | ||
_env: {http_proxy: 'http://domain6.com'} | ||
const agent = getAgentWith({ | ||
npmrc: {}, | ||
env: {http_proxy: 'http://domain6.com'} | ||
}); | ||
t.is(agent.proxy.href, 'http://domain6.com/'); | ||
}); | ||
|
||
test.serial('getHttpsProxyAgent returns nothing if no proxy set', async t => { | ||
const agent = getAgent({ | ||
_npmrc: {}, | ||
_env: {} | ||
const agent = getAgentWith({ | ||
npmrc: {}, | ||
env: {} | ||
}); | ||
t.is(agent, undefined); | ||
}); | ||
}); |