Skip to content
Snippets Groups Projects
Commit 418b28b2 authored by Michael Kriese's avatar Michael Kriese Committed by Rhys Arkins
Browse files

refactor(typescript): convert proxy to typescript (#4878)

parent defac5d8
No related branches found
No related tags found
No related merge requests found
const { createGlobalProxyAgent } = require('global-agent');
module.exports = {
bootstrap,
};
import {
createGlobalProxyAgent,
ProxyAgentConfigurationType,
} from 'global-agent';
const envVars = ['HTTP_PROXY', 'HTTPS_PROXY', 'NO_PROXY'];
function bootstrap() {
export function bootstrap(): ProxyAgentConfigurationType {
envVars.forEach(envVar => {
/* istanbul ignore if: env is case-insensitive on windows */
if (
typeof process.env[envVar] === 'undefined' &&
typeof process.env[envVar.toLowerCase()] !== 'undefined'
......
declare module 'global-agent' {
export interface ProxyAgentConfigurationInputType {
environmentVariableNamespace?: string;
forceGlobalAgent?: boolean;
socketConnectionTimeout?: number;
}
export interface ProxyAgentConfigurationType {
readonly HTTP_PROXY: string;
readonly HTTPS_PROXY: string;
readonly NO_PROXY: string;
}
export function createGlobalProxyAgent(
opts: ProxyAgentConfigurationInputType
): ProxyAgentConfigurationType;
}
......@@ -5,6 +5,13 @@ describe('proxy', () => {
const httpsProxy = 'http://example.org/https-proxy';
const noProxy = 'http://example.org/no-proxy';
beforeAll(() => {
delete process.env.HTTP_PROXY;
delete process.env.HTTPS_PROXY;
delete process.env.NO_PROXY;
delete process.env.no_proxy;
});
it('respects HTTP_PROXY', () => {
process.env.HTTP_PROXY = httpProxy;
const result = bootstrap();
......@@ -15,8 +22,8 @@ describe('proxy', () => {
const result = bootstrap();
expect(result.HTTPS_PROXY).toEqual(httpsProxy);
});
it('respects NO_PROXY', () => {
process.env.NO_PROXY = noProxy;
it('respects no_proxy', () => {
process.env.no_proxy = noProxy;
const result = bootstrap();
expect(result.NO_PROXY).toEqual(noProxy);
});
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment