Skip to content

Commit 228a117

Browse files
feat: swap websocket transport with cdp add binding/evaluate (#27592)
Co-authored-by: Brian Mann <brian.mann86@gmail.com>
1 parent 5fe9473 commit 228a117

File tree

102 files changed

+2286
-1033
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+2286
-1033
lines changed

packages/app/cypress/e2e/cypress-in-cypress-component.cy.ts

-57
Original file line numberDiff line numberDiff line change
@@ -178,63 +178,6 @@ describe('Cypress In Cypress CT', { viewportWidth: 1500, defaultCommandTimeout:
178178
expect(ctx.actions.project.initializeActiveProject).to.be.called
179179
})
180180
})
181-
182-
it('moves away from runner and back, disconnects websocket and reconnects it correctly', () => {
183-
cy.openProject('cypress-in-cypress')
184-
cy.startAppServer('component')
185-
186-
cy.visitApp()
187-
cy.contains('TestComponent.spec').click()
188-
cy.waitForSpecToFinish()
189-
cy.get('[data-model-state="passed"]').should('contain', 'renders the test component')
190-
cy.get('.passed > .num').should('contain', 1)
191-
cy.get('.failed > .num').should('contain', '--')
192-
193-
cy.findByTestId('sidebar-link-runs-page').click()
194-
cy.get('[data-cy="app-header-bar"]').findByText('Runs').should('be.visible')
195-
196-
cy.findByTestId('sidebar-link-specs-page').click()
197-
cy.get('[data-cy="app-header-bar"]').findByText('Specs').should('be.visible')
198-
199-
cy.contains('TestComponent.spec').click()
200-
cy.waitForSpecToFinish()
201-
cy.get('[data-model-state="passed"]').should('contain', 'renders the test component')
202-
203-
cy.window().then((win) => {
204-
const connected = () => win.ws?.connected
205-
206-
win.ws?.close()
207-
208-
cy.wrap({
209-
connected,
210-
}).invoke('connected').should('be.false')
211-
212-
win.ws?.connect()
213-
214-
cy.wrap({
215-
connected,
216-
}).invoke('connected').should('be.true')
217-
})
218-
219-
cy.withCtx(async (ctx, o) => {
220-
await ctx.actions.file.writeFileInProject(o.path, `
221-
import React from 'react'
222-
import { mount } from 'cypress/react'
223-
224-
describe('TestComponent', () => {
225-
it('renders the new test component', () => {
226-
mount(<div>Component Test</div>)
227-
228-
cy.contains('Component Test').should('be.visible')
229-
})
230-
})
231-
`)
232-
}, { path: getPathForPlatform('src/TestComponent.spec.jsx') })
233-
234-
cy.get('[data-model-state="passed"]').should('contain', 'renders the new test component')
235-
cy.get('.passed > .num').should('contain', 1)
236-
cy.get('.failed > .num').should('contain', '--')
237-
})
238181
})
239182

240183
context('custom config', () => {

packages/app/cypress/e2e/cypress-in-cypress-e2e.cy.ts

-49
Original file line numberDiff line numberDiff line change
@@ -231,55 +231,6 @@ describe('Cypress In Cypress E2E', { viewportWidth: 1500, defaultCommandTimeout:
231231
cy.get('[data-model-state="passed"]').should('contain', 'expected true to be true')
232232
})
233233

234-
it('moves away from runner and back, disconnects websocket and reconnects it correctly', () => {
235-
cy.visitApp()
236-
cy.contains('dom-content.spec').click()
237-
cy.waitForSpecToFinish()
238-
cy.get('[data-model-state="passed"]').should('contain', 'renders the test content')
239-
cy.get('.passed > .num').should('contain', 1)
240-
cy.get('.failed > .num').should('contain', '--')
241-
242-
cy.findByTestId('sidebar-link-runs-page').click()
243-
cy.get('[data-cy="app-header-bar"]').findByText('Runs').should('be.visible')
244-
245-
cy.findByTestId('sidebar-link-specs-page').click()
246-
cy.get('[data-cy="app-header-bar"]').findByText('Specs').should('be.visible')
247-
248-
cy.contains('dom-content.spec').click()
249-
cy.waitForSpecToFinish()
250-
cy.get('[data-model-state="passed"]').should('contain', 'renders the test content')
251-
252-
cy.window().then((win) => {
253-
const connected = () => win.ws?.connected
254-
255-
win.ws?.close()
256-
257-
cy.wrap({
258-
connected,
259-
}).invoke('connected').should('be.false')
260-
261-
win.ws?.connect()
262-
263-
cy.wrap({
264-
connected,
265-
}).invoke('connected').should('be.true')
266-
})
267-
268-
cy.withCtx(async (ctx, o) => {
269-
await ctx.actions.file.writeFileInProject(o.path, `
270-
describe('Dom Content', () => {
271-
it('renders the new test content', () => {
272-
cy.visit('cypress/e2e/dom-content.html')
273-
})
274-
})
275-
`)
276-
}, { path: getPathForPlatform('cypress/e2e/dom-content.spec.js') })
277-
278-
cy.get('[data-model-state="passed"]').should('contain', 'renders the new test content')
279-
cy.get('.passed > .num').should('contain', 1)
280-
cy.get('.failed > .num').should('contain', '--')
281-
})
282-
283234
describe('accessibility', () => {
284235
it('has no axe violations in specs list panel', () => {
285236
cy.visitApp()

packages/app/cypress/e2e/cypress-in-cypress.cy.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ describe('Cypress in Cypress', { viewportWidth: 1500, defaultCommandTimeout: 100
2727
cy.waitForSpecToFinish()
2828

2929
cy.withCtx((ctx) => {
30-
ctx.coreData.servers.appSocketServer?.emit('automation:disconnected')
30+
ctx.coreData.servers.cdpSocketServer?.emit('automation:disconnected')
3131
})
3232

3333
cy.contains('h3', 'The Cypress extension has disconnected')
@@ -403,7 +403,7 @@ describe('Cypress in Cypress', { viewportWidth: 1500, defaultCommandTimeout: 100
403403
cy.withCtx(async (ctx) => {
404404
const currentProject = ctx.currentProject?.replaceAll('\\', '/')
405405
const specPath = `${currentProject}/cypress/e2e/dom-content.spec.js`
406-
const url = `http://127.0.0.1:${ctx.gqlServerPort}/__launchpad/graphql?`
406+
const url = `http://127.0.0.1:${ctx.coreData.servers.gqlServerPort}/__launchpad/graphql?`
407407
const payload = `{"query":"mutation{\\nrunSpec(specPath:\\"${specPath}\\"){\\n__typename\\n... on RunSpecResponse{\\ntestingType\\nbrowser{\\nid\\nname\\n}\\nspec{\\nid\\nname\\n}\\n}\\n}\\n}","variables":null}`
408408

409409
ctx.coreData.app.browserStatus = 'open'

packages/app/cypress/e2e/runs.cy.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import defaultMessages from '@packages/frontend-shared/src/locales/en-US.json'
2+
23
import type { SinonStub } from 'sinon'
34

45
function moveToRunsPage (): void {
@@ -616,26 +617,26 @@ describe('App: Runs', { viewportWidth: 1200 }, () => {
616617
it('displays a copy button and copies correct command in Component Testing', () => {
617618
scaffoldTestingTypeAndVisitRunsPage('component')
618619
cy.withCtx(async (ctx, o) => {
619-
o.sinon.stub(ctx.electronApi, 'copyTextToClipboard')
620+
o.sinon.stub(ctx.config.electronApi, 'copyTextToClipboard')
620621
})
621622

622623
cy.get('[data-cy="copy-button"]').click()
623624
cy.contains('Copied!')
624625
cy.withRetryableCtx((ctx) => {
625-
expect(ctx.electronApi.copyTextToClipboard as SinonStub).to.have.been.calledWith('npx cypress run --component --record --key 2aaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa')
626+
expect(ctx.config.electronApi.copyTextToClipboard as SinonStub).to.have.been.calledWith('npx cypress run --component --record --key 2aaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa')
626627
})
627628
})
628629

629630
it('displays a copy button and copies correct command in E2E', () => {
630631
scaffoldTestingTypeAndVisitRunsPage('e2e')
631632
cy.withCtx(async (ctx, o) => {
632-
o.sinon.stub(ctx.electronApi, 'copyTextToClipboard')
633+
o.sinon.stub(ctx.config.electronApi, 'copyTextToClipboard')
633634
})
634635

635636
cy.get('[data-cy="copy-button"]').click()
636637
cy.contains('Copied!')
637638
cy.withRetryableCtx((ctx) => {
638-
expect(ctx.electronApi.copyTextToClipboard as SinonStub).to.have.been.calledWith('npx cypress run --record --key 2aaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa')
639+
expect(ctx.config.electronApi.copyTextToClipboard as SinonStub).to.have.been.calledWith('npx cypress run --record --key 2aaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa')
639640
})
640641
})
641642
})

packages/app/cypress/e2e/settings.cy.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ describe('App: Settings', () => {
2828
describe('Cloud Settings', () => {
2929
it('shows the projectId section when there is a projectId and shows override from CLI', () => {
3030
cy.withCtx(async (ctx, o) => {
31-
o.sinon.stub(ctx.electronApi, 'copyTextToClipboard')
31+
o.sinon.stub(ctx.config.electronApi, 'copyTextToClipboard')
3232
})
3333

3434
cy.startAppServer('e2e')
@@ -40,7 +40,7 @@ describe('App: Settings', () => {
4040
cy.findByText('Copy').click()
4141
cy.findByText('Copied!').should('be.visible')
4242
cy.withRetryableCtx((ctx) => {
43-
expect(ctx.electronApi.copyTextToClipboard as SinonStub).to.have.been.calledWith('fromCli')
43+
expect(ctx.config.electronApi.copyTextToClipboard as SinonStub).to.have.been.calledWith('fromCli')
4444
})
4545
})
4646

packages/app/cypress/e2e/subscriptions/createCloudOrgModal-subscription.cy.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import defaultMessages from '@packages/frontend-shared/src/locales/en-US.json'
2+
23
import type { SinonStub } from 'sinon'
34

45
describe('CreateCloudOrgModalSubscription', { viewportWidth: 1200 }, () => {
@@ -51,7 +52,7 @@ describe('CreateCloudOrgModalSubscription', { viewportWidth: 1200 }, () => {
5152
})
5253

5354
cy.withCtx(async (ctx) => {
54-
await ctx.util.fetch(`http://127.0.0.1:${ctx.gqlServerPort}/cloud-notification?operationName=orgCreated`)
55+
await ctx.util.fetch(`http://127.0.0.1:${ctx.coreData.servers.gqlServerPort}/cloud-notification?operationName=orgCreated`)
5556
})
5657

5758
cy.findByText(defaultMessages.runs.connect.modal.selectProject.manageOrgs)

packages/app/index.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/// <reference path="../driver/types/internal-types-lite.d.ts" />
22

3-
import type { Socket } from '@packages/socket/lib/browser'
3+
import type { SocketShape } from '@packages/socket/lib/types'
44
import type MobX from 'mobx'
55
import type { EventManager } from './src/runner/event-manager'
66

@@ -21,7 +21,7 @@ export {}
2121
*/
2222
declare global {
2323
interface Window {
24-
ws?: Socket
24+
ws?: SocketShape
2525
getEventManager: () => EventManager
2626
UnifiedRunner: {
2727
/**

packages/app/src/runner/event-manager.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type { LocalBusEmitsMap, LocalBusEventMap, DriverToLocalBus, SocketToDriv
77
import type { RunState, CachedTestState, AutomationElementId, FileDetails, ReporterStartInfo, ReporterRunState } from '@packages/types'
88

99
import { logger } from './logger'
10-
import type { Socket } from '@packages/socket/lib/browser'
10+
import type { SocketShape } from '@packages/socket/lib/types'
1111
import { automation, useRunnerUiStore, useSpecStore } from '../store'
1212
import { useScreenshotStore } from '../store/screenshot-store'
1313
import { useStudioStore } from '../store/studio-store'
@@ -57,7 +57,7 @@ export class EventManager {
5757
selectorPlaygroundModel: any
5858
cypressInCypressMochaEvents: CypressInCypressMochaEvent[] = []
5959
// Used for testing the experimentalSingleTabRunMode experiment. Ensures AUT is correctly destroyed between specs.
60-
ws: Socket
60+
ws: SocketShape
6161
specStore: ReturnType<typeof useSpecStore>
6262
studioStore: ReturnType<typeof useStudioStore>
6363

@@ -68,7 +68,7 @@ export class EventManager {
6868
private Mobx: typeof MobX,
6969
// selectorPlaygroundModel singleton
7070
selectorPlaygroundModel: any,
71-
ws: Socket,
71+
ws: SocketShape,
7272
) {
7373
this.selectorPlaygroundModel = selectorPlaygroundModel
7474
this.ws = ws
@@ -134,7 +134,7 @@ export class EventManager {
134134
telemetry.setRootContext(context)
135135
})
136136

137-
this.ws.on('automation:push:message', (msg, data = {}) => {
137+
this.ws.on('automation:push:message', (msg, data: any = {}) => {
138138
if (!Cypress) return
139139

140140
switch (msg) {

packages/data-context/src/DataActions.ts

+6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
BrowserActions,
1111
DevActions,
1212
AuthActions,
13+
ServersActions,
1314
CohortsActions,
1415
CodegenActions,
1516
CloudProjectActions,
@@ -78,6 +79,11 @@ export class DataActions {
7879
return new BrowserActions(this.ctx)
7980
}
8081

82+
@cached
83+
get servers () {
84+
return new ServersActions(this.ctx)
85+
}
86+
8187
@cached
8288
get versions () {
8389
return new VersionsActions(this.ctx)

0 commit comments

Comments
 (0)