Skip to content

Commit

Permalink
feat: swap websocket transport with cdp add binding/evaluate (#27592)
Browse files Browse the repository at this point in the history
Co-authored-by: Brian Mann <brian.mann86@gmail.com>
  • Loading branch information
ryanthemanuel and brian-mann authored Aug 26, 2023
1 parent 5fe9473 commit 228a117
Show file tree
Hide file tree
Showing 102 changed files with 2,286 additions and 1,033 deletions.
57 changes: 0 additions & 57 deletions packages/app/cypress/e2e/cypress-in-cypress-component.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,63 +178,6 @@ describe('Cypress In Cypress CT', { viewportWidth: 1500, defaultCommandTimeout:
expect(ctx.actions.project.initializeActiveProject).to.be.called
})
})

it('moves away from runner and back, disconnects websocket and reconnects it correctly', () => {
cy.openProject('cypress-in-cypress')
cy.startAppServer('component')

cy.visitApp()
cy.contains('TestComponent.spec').click()
cy.waitForSpecToFinish()
cy.get('[data-model-state="passed"]').should('contain', 'renders the test component')
cy.get('.passed > .num').should('contain', 1)
cy.get('.failed > .num').should('contain', '--')

cy.findByTestId('sidebar-link-runs-page').click()
cy.get('[data-cy="app-header-bar"]').findByText('Runs').should('be.visible')

cy.findByTestId('sidebar-link-specs-page').click()
cy.get('[data-cy="app-header-bar"]').findByText('Specs').should('be.visible')

cy.contains('TestComponent.spec').click()
cy.waitForSpecToFinish()
cy.get('[data-model-state="passed"]').should('contain', 'renders the test component')

cy.window().then((win) => {
const connected = () => win.ws?.connected

win.ws?.close()

cy.wrap({
connected,
}).invoke('connected').should('be.false')

win.ws?.connect()

cy.wrap({
connected,
}).invoke('connected').should('be.true')
})

cy.withCtx(async (ctx, o) => {
await ctx.actions.file.writeFileInProject(o.path, `
import React from 'react'
import { mount } from 'cypress/react'
describe('TestComponent', () => {
it('renders the new test component', () => {
mount(<div>Component Test</div>)
cy.contains('Component Test').should('be.visible')
})
})
`)
}, { path: getPathForPlatform('src/TestComponent.spec.jsx') })

cy.get('[data-model-state="passed"]').should('contain', 'renders the new test component')
cy.get('.passed > .num').should('contain', 1)
cy.get('.failed > .num').should('contain', '--')
})
})

context('custom config', () => {
Expand Down
49 changes: 0 additions & 49 deletions packages/app/cypress/e2e/cypress-in-cypress-e2e.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,55 +231,6 @@ describe('Cypress In Cypress E2E', { viewportWidth: 1500, defaultCommandTimeout:
cy.get('[data-model-state="passed"]').should('contain', 'expected true to be true')
})

it('moves away from runner and back, disconnects websocket and reconnects it correctly', () => {
cy.visitApp()
cy.contains('dom-content.spec').click()
cy.waitForSpecToFinish()
cy.get('[data-model-state="passed"]').should('contain', 'renders the test content')
cy.get('.passed > .num').should('contain', 1)
cy.get('.failed > .num').should('contain', '--')

cy.findByTestId('sidebar-link-runs-page').click()
cy.get('[data-cy="app-header-bar"]').findByText('Runs').should('be.visible')

cy.findByTestId('sidebar-link-specs-page').click()
cy.get('[data-cy="app-header-bar"]').findByText('Specs').should('be.visible')

cy.contains('dom-content.spec').click()
cy.waitForSpecToFinish()
cy.get('[data-model-state="passed"]').should('contain', 'renders the test content')

cy.window().then((win) => {
const connected = () => win.ws?.connected

win.ws?.close()

cy.wrap({
connected,
}).invoke('connected').should('be.false')

win.ws?.connect()

cy.wrap({
connected,
}).invoke('connected').should('be.true')
})

cy.withCtx(async (ctx, o) => {
await ctx.actions.file.writeFileInProject(o.path, `
describe('Dom Content', () => {
it('renders the new test content', () => {
cy.visit('cypress/e2e/dom-content.html')
})
})
`)
}, { path: getPathForPlatform('cypress/e2e/dom-content.spec.js') })

cy.get('[data-model-state="passed"]').should('contain', 'renders the new test content')
cy.get('.passed > .num').should('contain', 1)
cy.get('.failed > .num').should('contain', '--')
})

describe('accessibility', () => {
it('has no axe violations in specs list panel', () => {
cy.visitApp()
Expand Down
4 changes: 2 additions & 2 deletions packages/app/cypress/e2e/cypress-in-cypress.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('Cypress in Cypress', { viewportWidth: 1500, defaultCommandTimeout: 100
cy.waitForSpecToFinish()

cy.withCtx((ctx) => {
ctx.coreData.servers.appSocketServer?.emit('automation:disconnected')
ctx.coreData.servers.cdpSocketServer?.emit('automation:disconnected')
})

cy.contains('h3', 'The Cypress extension has disconnected')
Expand Down Expand Up @@ -403,7 +403,7 @@ describe('Cypress in Cypress', { viewportWidth: 1500, defaultCommandTimeout: 100
cy.withCtx(async (ctx) => {
const currentProject = ctx.currentProject?.replaceAll('\\', '/')
const specPath = `${currentProject}/cypress/e2e/dom-content.spec.js`
const url = `http://127.0.0.1:${ctx.gqlServerPort}/__launchpad/graphql?`
const url = `http://127.0.0.1:${ctx.coreData.servers.gqlServerPort}/__launchpad/graphql?`
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}`

ctx.coreData.app.browserStatus = 'open'
Expand Down
9 changes: 5 additions & 4 deletions packages/app/cypress/e2e/runs.cy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import defaultMessages from '@packages/frontend-shared/src/locales/en-US.json'

import type { SinonStub } from 'sinon'

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

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

it('displays a copy button and copies correct command in E2E', () => {
scaffoldTestingTypeAndVisitRunsPage('e2e')
cy.withCtx(async (ctx, o) => {
o.sinon.stub(ctx.electronApi, 'copyTextToClipboard')
o.sinon.stub(ctx.config.electronApi, 'copyTextToClipboard')
})

cy.get('[data-cy="copy-button"]').click()
cy.contains('Copied!')
cy.withRetryableCtx((ctx) => {
expect(ctx.electronApi.copyTextToClipboard as SinonStub).to.have.been.calledWith('npx cypress run --record --key 2aaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa')
expect(ctx.config.electronApi.copyTextToClipboard as SinonStub).to.have.been.calledWith('npx cypress run --record --key 2aaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa')
})
})
})
Expand Down
4 changes: 2 additions & 2 deletions packages/app/cypress/e2e/settings.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('App: Settings', () => {
describe('Cloud Settings', () => {
it('shows the projectId section when there is a projectId and shows override from CLI', () => {
cy.withCtx(async (ctx, o) => {
o.sinon.stub(ctx.electronApi, 'copyTextToClipboard')
o.sinon.stub(ctx.config.electronApi, 'copyTextToClipboard')
})

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import defaultMessages from '@packages/frontend-shared/src/locales/en-US.json'

import type { SinonStub } from 'sinon'

describe('CreateCloudOrgModalSubscription', { viewportWidth: 1200 }, () => {
Expand Down Expand Up @@ -51,7 +52,7 @@ describe('CreateCloudOrgModalSubscription', { viewportWidth: 1200 }, () => {
})

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

cy.findByText(defaultMessages.runs.connect.modal.selectProject.manageOrgs)
Expand Down
4 changes: 2 additions & 2 deletions packages/app/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/// <reference path="../driver/types/internal-types-lite.d.ts" />

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

Expand All @@ -21,7 +21,7 @@ export {}
*/
declare global {
interface Window {
ws?: Socket
ws?: SocketShape
getEventManager: () => EventManager
UnifiedRunner: {
/**
Expand Down
8 changes: 4 additions & 4 deletions packages/app/src/runner/event-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type { LocalBusEmitsMap, LocalBusEventMap, DriverToLocalBus, SocketToDriv
import type { RunState, CachedTestState, AutomationElementId, FileDetails, ReporterStartInfo, ReporterRunState } from '@packages/types'

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

Expand All @@ -68,7 +68,7 @@ export class EventManager {
private Mobx: typeof MobX,
// selectorPlaygroundModel singleton
selectorPlaygroundModel: any,
ws: Socket,
ws: SocketShape,
) {
this.selectorPlaygroundModel = selectorPlaygroundModel
this.ws = ws
Expand Down Expand Up @@ -134,7 +134,7 @@ export class EventManager {
telemetry.setRootContext(context)
})

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

switch (msg) {
Expand Down
6 changes: 6 additions & 0 deletions packages/data-context/src/DataActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
BrowserActions,
DevActions,
AuthActions,
ServersActions,
CohortsActions,
CodegenActions,
CloudProjectActions,
Expand Down Expand Up @@ -78,6 +79,11 @@ export class DataActions {
return new BrowserActions(this.ctx)
}

@cached
get servers () {
return new ServersActions(this.ctx)
}

@cached
get versions () {
return new VersionsActions(this.ctx)
Expand Down
Loading

5 comments on commit 228a117

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 228a117 Aug 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux x64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.0.0/linux-x64/release/13.0.0-228a117e827682a75eb9aafebe3c6fe5f9f0be20/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 228a117 Aug 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the darwin arm64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.0.0/darwin-arm64/release/13.0.0-228a117e827682a75eb9aafebe3c6fe5f9f0be20/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 228a117 Aug 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux arm64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.0.0/linux-arm64/release/13.0.0-228a117e827682a75eb9aafebe3c6fe5f9f0be20/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 228a117 Aug 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the darwin x64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.0.0/darwin-x64/release/13.0.0-228a117e827682a75eb9aafebe3c6fe5f9f0be20/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 228a117 Aug 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the win32 x64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.0.0/win32-x64/release/13.0.0-228a117e827682a75eb9aafebe3c6fe5f9f0be20/cypress.tgz

Please sign in to comment.