(plan = 1, opts = {})
| 159 | }) |
| 160 | |
| 161 | const createEnvHttpProxyAgentWithMocks = (plan = 1, opts = {}) => { |
| 162 | const factory = (origin) => { |
| 163 | const mockAgent = new MockAgent() |
| 164 | const mockPool = mockAgent.get(origin) |
| 165 | let i = 0 |
| 166 | while (i < plan) { |
| 167 | mockPool.intercept({ path: /.*/ }).reply(200, 'OK') |
| 168 | i++ |
| 169 | } |
| 170 | return mockPool |
| 171 | } |
| 172 | process.env.http_proxy = 'http://localhost:8080' |
| 173 | process.env.https_proxy = 'http://localhost:8443' |
| 174 | const dispatcher = new EnvHttpProxyAgent({ ...opts, factory }) |
| 175 | const agentSymbols = [kNoProxyAgent, kHttpProxyAgent, kHttpsProxyAgent] |
| 176 | agentSymbols.forEach((agentSymbol) => { |
| 177 | const originalDispatch = dispatcher[agentSymbol].dispatch |
| 178 | dispatcher[agentSymbol].dispatch = function () { |
| 179 | dispatcher[agentSymbol].dispatch.called = true |
| 180 | return originalDispatch.apply(this, arguments) |
| 181 | } |
| 182 | dispatcher[agentSymbol].dispatch.called = false |
| 183 | }) |
| 184 | const usesProxyAgent = async (agent, url) => { |
| 185 | await fetch(url, { dispatcher }) |
| 186 | const result = agentSymbols.every((agentSymbol) => agent === agentSymbol |
| 187 | ? dispatcher[agentSymbol].dispatch.called === true |
| 188 | : dispatcher[agentSymbol].dispatch.called === false) |
| 189 | |
| 190 | agentSymbols.forEach((agentSymbol) => { |
| 191 | dispatcher[agentSymbol].dispatch.called = false |
| 192 | }) |
| 193 | return result |
| 194 | } |
| 195 | const doesNotProxy = usesProxyAgent.bind(this, kNoProxyAgent) |
| 196 | return { |
| 197 | dispatcher, |
| 198 | doesNotProxy, |
| 199 | usesProxyAgent |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | test('uses the appropriate proxy for the protocol', async (t) => { |
| 204 | t = tspl(t, { plan: 2 }) |
no test coverage detected
searching dependent graphs…