From 24f7ee66f01a1398ad15895fe0609a7adc47153e Mon Sep 17 00:00:00 2001 From: Aras Abbasi Date: Sat, 27 Apr 2024 09:39:01 +0200 Subject: [PATCH] deps: remove sinon (#3171) --- package.json | 1 - test/env-http-proxy-agent.js | 19 +++++++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index fcbd63b12ae..be03f23267f 100644 --- a/package.json +++ b/package.json @@ -119,7 +119,6 @@ "node-forge": "^1.3.1", "pre-commit": "^1.2.2", "proxy": "^2.1.1", - "sinon": "^17.0.1", "snazzy": "^9.0.0", "standard": "^17.0.0", "tsd": "^0.31.0", diff --git a/test/env-http-proxy-agent.js b/test/env-http-proxy-agent.js index 4949df9f5f8..1a707fad538 100644 --- a/test/env-http-proxy-agent.js +++ b/test/env-http-proxy-agent.js @@ -2,7 +2,6 @@ const { tspl } = require('@matteo.collina/tspl') const { test, describe, after, beforeEach } = require('node:test') -const sinon = require('sinon') const { EnvHttpProxyAgent, ProxyAgent, Agent, fetch, MockAgent } = require('..') const { kNoProxyAgent, kHttpProxyAgent, kHttpsProxyAgent, kClosed, kDestroyed, kProxy } = require('../lib/core/symbols') @@ -174,15 +173,23 @@ const createEnvHttpProxyAgentWithMocks = (plan = 1, opts = {}) => { process.env.https_proxy = 'http://localhost:8443' const dispatcher = new EnvHttpProxyAgent({ ...opts, factory }) const agentSymbols = [kNoProxyAgent, kHttpProxyAgent, kHttpsProxyAgent] - agentSymbols.forEach((agent) => { - sinon.spy(dispatcher[agent], 'dispatch') + agentSymbols.forEach((agentSymbol) => { + const originalDispatch = dispatcher[agentSymbol].dispatch + dispatcher[agentSymbol].dispatch = function () { + dispatcher[agentSymbol].dispatch.called = true + return originalDispatch.apply(this, arguments) + } + dispatcher[agentSymbol].dispatch.called = false }) const usesProxyAgent = async (agent, url) => { await fetch(url, { dispatcher }) const result = agentSymbols.every((agentSymbol) => agent === agentSymbol - ? dispatcher[agentSymbol].dispatch.called - : dispatcher[agentSymbol].dispatch.notCalled) - agentSymbols.forEach((agent) => { dispatcher[agent].dispatch.resetHistory() }) + ? dispatcher[agentSymbol].dispatch.called === true + : dispatcher[agentSymbol].dispatch.called === false) + + agentSymbols.forEach((agentSymbol) => { + dispatcher[agentSymbol].dispatch.called = false + }) return result } const doesNotProxy = usesProxyAgent.bind(this, kNoProxyAgent)