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(multi-domain): adding websocket support for backend and automation requests #19843

Merged
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// @ts-ignore / session support is needed for visiting about:blank between tests
// FIXME: hangs
context.skip('multi-domain cookies', { experimentalSessionSupport: true, experimentalMultiDomain: true }, () => {
context('multi-domain cookies', { experimentalSessionSupport: true, experimentalMultiDomain: true }, () => {
beforeEach(() => {
cy.visit('/fixtures/multi-domain.html')
cy.get('a[data-cy="multi-domain-secondary-link"]').click()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@ context('multi-domain files', { experimentalSessionSupport: true, experimentalMu
beforeEach(() => {
cy.visit('/fixtures/multi-domain.html')
cy.get('a[data-cy="multi-domain-secondary-link"]').click()
cy.stub(Cypress, 'backend').callThrough()
})

// FIXME: CypressError: `cy.fixture()` timed out waiting `undefinedms` to receive a fixture. No fixture was ever sent by the server.
// at eval (webpack:///../driver/src/cy/commands/fixtures.ts?:89:85)
it.skip('.fixture()', () => {
it('.fixture()', () => {
cy.switchToDomain('foobar.com', () => {
cy.fixture('example.json').then((json) => {
expect(json).to.be.an('object')
Expand All @@ -17,9 +14,7 @@ context('multi-domain files', { experimentalSessionSupport: true, experimentalMu
})
})

// FIXME: CypressError: `cy.readFile("cypress/fixtures/multi-domain.json")` timed out after waiting `undefinedms`.
// at eval (webpack:///../driver/src/cy/commands/files.ts?:59:89)
it.skip('.readFile()', () => {
it('.readFile()', () => {
cy.switchToDomain('foobar.com', () => {
cy.readFile('cypress/fixtures/example.json').then((json) => {
expect(json).to.be.an('object')
Expand All @@ -28,10 +23,10 @@ context('multi-domain files', { experimentalSessionSupport: true, experimentalMu
})
})

// FIXME: Cypress.backend.resolves is not a function
// Works when not using switchToDomain
// FIXME: stub on Cypress.backend is causing an infinite loop
Copy link
Contributor

Choose a reason for hiding this comment

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

The primary driver writeFile tests call through to the real implementation of Cypress.backend, so I guess they actually write the file. I think that's fine because we do intend the driver tests to often be e2e or integration tests.

It might not necessary to stub Cypress.backend here at all. I think we do it in the other tests primarily to test out when it fails and rejects, but just testing the happy path here is fine for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It does call through in the beforeEach but in the actual it block, it calls .resolves() to mock the writeFile(). I doubt we want to actually write a file unless it was to a temp directory or maybe write to an existing file and check the modified date?

it.skip('.writeFile()', () => {
cy.switchToDomain('foobar.com', () => {
cy.stub(Cypress, 'backend')
// @ts-ignore
Cypress.backend.resolves({
contents: JSON.stringify({ foo: 'bar' }),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ context('multi-domain misc', { experimentalSessionSupport: true, experimentalMul
})
})

// FIXME: CypressError: `cy.exec('echo foobar')` timed out after waiting `undefinedms`.
// at eval (webpack:///../driver/src/cy/commands/exec.ts?:89:85)
it.skip('.exec()', () => {
it('.exec()', () => {
cy.switchToDomain('foobar.com', () => {
cy.exec('echo foobar').its('stdout').should('contain', 'foobar')
})
Expand Down Expand Up @@ -81,10 +79,7 @@ context('multi-domain misc', { experimentalSessionSupport: true, experimentalMul
})
})

// FIXME: CypressError: `cy.task('return:arg')` timed out after waiting `undefinedms`.
// at eval(webpack:///../driver/src/cy/commands/task.ts?:72:78)
// From previous event: at task(webpack:///../driver/src/cy/commands/task.ts?:71:15)
it.skip('.task()', () => {
it('.task()', () => {
Copy link
Member

Choose a reason for hiding this comment

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

its nice to see all these tests getting enabled 🎉

cy.switchToDomain('foobar.com', () => {
cy.task('return:arg', 'works').should('eq', 'works')
})
Expand Down
8 changes: 8 additions & 0 deletions packages/driver/src/multi-domain/cypress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { SpecBridgeDomainCommunicator } from './communicator'
import { handleDomainFn } from './domain_fn'
import { handleCommands } from './commands'
import { handleLogs } from './logs'
import { handleSocketEvents } from './socket'

const specBridgeCommunicator = new SpecBridgeDomainCommunicator()

Expand All @@ -31,6 +32,12 @@ const setup = () => {
path: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
version: '90.0.4430.212',
},
defaultCommandTimeout: 4000,
execTimeout: 60000,
taskTimeout: 60000,
pageLoadTimeout: 60000,
requestTimeout: 5000,
responseTimeout: 30000,
}) as Cypress.Cypress

// @ts-ignore
Expand All @@ -55,6 +62,7 @@ const setup = () => {
handleDomainFn(cy, specBridgeCommunicator)
handleCommands(Cypress, cy, specBridgeCommunicator)
handleLogs(Cypress, specBridgeCommunicator)
handleSocketEvents(Cypress)

cy.onBeforeAppWindowLoad = onBeforeAppWindowLoad(Cypress, cy)

Expand Down
19 changes: 19 additions & 0 deletions packages/driver/src/multi-domain/socket.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { client } from '@packages/socket'

const webSocket = client({
path: '/__socket.io',
transports: ['websocket'],
}).connect()

const onBackendRequest = (...args) => {
webSocket.emit('backend:request', ...args)
}

const onAutomationRequest = (...args) => {
webSocket.emit('automation:request', ...args)
}

export const handleSocketEvents = (Cypress) => {
Cypress.on('backend:request', onBackendRequest)
Cypress.on('automation:request', onAutomationRequest)
}
2 changes: 2 additions & 0 deletions packages/driver/types/internal-types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ declare namespace Cypress {
(action: 'internal:window:load', fn: (details: InternalWindowLoadDetails) => void)
(action: 'net:stubbing:event', frame: any)
(action: 'request:event', data: any)
(action: 'backend:request', fn: (...any) => void)
(action: 'automation:request', fn: (...any) => void)
}

interface cy {
Expand Down