|
2 | 2 |
|
3 | 3 | const { tspl } = require('@matteo.collina/tspl') |
4 | 4 | const { test, describe, after, beforeEach } = require('node:test') |
5 | | -const sinon = require('sinon') |
6 | 5 | const { EnvHttpProxyAgent, ProxyAgent, Agent, fetch, MockAgent } = require('..') |
7 | 6 | const { kNoProxyAgent, kHttpProxyAgent, kHttpsProxyAgent, kClosed, kDestroyed, kProxy } = require('../lib/core/symbols') |
8 | 7 |
|
@@ -174,15 +173,23 @@ const createEnvHttpProxyAgentWithMocks = (plan = 1, opts = {}) => { |
174 | 173 | process.env.https_proxy = 'http://localhost:8443' |
175 | 174 | const dispatcher = new EnvHttpProxyAgent({ ...opts, factory }) |
176 | 175 | const agentSymbols = [kNoProxyAgent, kHttpProxyAgent, kHttpsProxyAgent] |
177 | | - agentSymbols.forEach((agent) => { |
178 | | - sinon.spy(dispatcher[agent], 'dispatch') |
| 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 |
179 | 183 | }) |
180 | 184 | const usesProxyAgent = async (agent, url) => { |
181 | 185 | await fetch(url, { dispatcher }) |
182 | 186 | const result = agentSymbols.every((agentSymbol) => agent === agentSymbol |
183 | | - ? dispatcher[agentSymbol].dispatch.called |
184 | | - : dispatcher[agentSymbol].dispatch.notCalled) |
185 | | - agentSymbols.forEach((agent) => { dispatcher[agent].dispatch.resetHistory() }) |
| 187 | + ? dispatcher[agentSymbol].dispatch.called === true |
| 188 | + : dispatcher[agentSymbol].dispatch.called === false) |
| 189 | + |
| 190 | + agentSymbols.forEach((agentSymbol) => { |
| 191 | + dispatcher[agentSymbol].dispatch.called = false |
| 192 | + }) |
186 | 193 | return result |
187 | 194 | } |
188 | 195 | const doesNotProxy = usesProxyAgent.bind(this, kNoProxyAgent) |
|
0 commit comments