Skip to content

Commit 91201d8

Browse files
committed
chore: fix cloud specs
1 parent e9f5df0 commit 91201d8

File tree

2 files changed

+8
-14
lines changed

2 files changed

+8
-14
lines changed

packages/server/test/unit/cloud/api/api_spec.js

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ const encryption = require('../../../../lib/cloud/encryption')
1111

1212
const {
1313
agent,
14-
CombinedAgent,
1514
} = require('@packages/network')
1615
const pkg = require('@packages/root')
1716
const api = require('../../../../lib/cloud/api').default
@@ -141,10 +140,7 @@ describe('lib/cloud/api', () => {
141140

142141
context('.rp', () => {
143142
beforeEach(() => {
144-
// Because @packages/network is a bundled ES6 class with https://github.com/cypress-io/cypress/pull/32633
145-
// we can no longer mock the addRequest method on the agent singleton instance directly
146-
// Until we are able to convert this test to Vitest/TypeScript, we need to spy on the prototype
147-
sinon.spy(CombinedAgent.prototype, 'addRequest')
143+
sinon.spy(agent, 'addRequest')
148144

149145
return nock.enableNetConnect()
150146
}) // nock will prevent requests from reaching the agent
@@ -155,9 +151,9 @@ describe('lib/cloud/api', () => {
155151
return api.ping()
156152
.thenThrow()
157153
.catch(() => {
158-
expect(CombinedAgent.prototype.addRequest).to.be.calledOnce
154+
expect(agent.addRequest).to.be.calledOnce
159155

160-
expect(CombinedAgent.prototype.addRequest).to.be.calledWithMatch(sinon.match.any, {
156+
expect(agent.addRequest).to.be.calledWithMatch(sinon.match.any, {
161157
href: 'http://localhost:1234/ping',
162158
})
163159
})
@@ -169,9 +165,9 @@ describe('lib/cloud/api', () => {
169165
return api.ping()
170166
.thenThrow()
171167
.catch(() => {
172-
expect(CombinedAgent.prototype.addRequest).to.be.calledOnce
168+
expect(agent.addRequest).to.be.calledOnce
173169

174-
expect(CombinedAgent.prototype.addRequest).to.be.calledWithMatch(sinon.match.any, {
170+
expect(agent.addRequest).to.be.calledWithMatch(sinon.match.any, {
175171
rejectUnauthorized: true,
176172
})
177173
})
@@ -189,9 +185,9 @@ describe('lib/cloud/api', () => {
189185
return api.ping()
190186
.thenThrow()
191187
.catch(() => {
192-
expect(CombinedAgent.prototype.addRequest).to.be.calledOnce
188+
expect(agent.addRequest).to.be.calledOnce
193189

194-
expect(CombinedAgent.prototype.addRequest).to.be.calledWithMatch(sinon.match.any, {
190+
expect(agent.addRequest).to.be.calledWithMatch(sinon.match.any, {
195191
href: 'http://localhost:1234/ping',
196192
})
197193
})

packages/server/test/unit/cloud/api/cloud_request_spec.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import sinon from 'sinon'
22
import sinonChai from 'sinon-chai'
33
import chai, { expect } from 'chai'
4-
// NOTE: having to import directly from the lib folder as we cannot test ES6 classes effectively with sinon.
5-
// Since this is a test, this is OK, but testing directly from lib in other modules is not a best practice.
6-
import agent, { strictAgent } from '@packages/network/lib/agent'
4+
import { agent, strictAgent } from '@packages/network'
75
import axios, { CreateAxiosDefaults, AxiosInstance } from 'axios'
86
import debugLib from 'debug'
97
import stripAnsi from 'strip-ansi'

0 commit comments

Comments
 (0)