Add function to return proxy agent dispatcher for compatibility with latest octokit

This commit is contained in:
Tatyana Kostromskaya
2023-10-05 16:20:26 +02:00
parent 0d63834474
commit 0faced6a0b
5 changed files with 190 additions and 58 deletions

View File

@@ -3,6 +3,7 @@
import * as http from 'http'
import * as httpm from '../lib/'
import * as pm from '../lib/proxy'
import { ProxyAgent } from "undici";
// eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports
const proxy = require('proxy')
@@ -13,7 +14,7 @@ const _proxyUrl = 'http://127.0.0.1:8080'
describe('proxy', () => {
beforeAll(async () => {
// Start proxy server
_proxyServer = proxy()
_proxyServer = proxy.createProxy()
await new Promise<void>(resolve => {
const port = Number(_proxyUrl.split(':')[2])
_proxyServer.listen(port, () => resolve())
@@ -294,6 +295,15 @@ describe('proxy', () => {
expect(agent.proxyOptions.port).toBe('8080')
expect(agent.proxyOptions.proxyAuth).toBe('user:password')
})
it('ProxyAgent is returned when proxy setting are provided', async () => {
process.env['https_proxy'] = 'http://127.0.0.1:8080'
const httpClient = new httpm.HttpClient()
const agent = httpClient.getAgentDispatcher('https://some-url')
// eslint-disable-next-line no-console
console.log(agent)
expect(agent instanceof ProxyAgent).toBe(true)
})
})
function _clearVars(): void {