Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove sinon as dev dependency #3171

Merged
merged 1 commit into from
Apr 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,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",
Expand Down
19 changes: 13 additions & 6 deletions test/env-http-proxy-agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down Expand Up @@ -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)
Expand Down
Loading