Skip to content

Commit

Permalink
chore: adding support for page:loading event (#26779)
Browse files Browse the repository at this point in the history
  • Loading branch information
mschile authored May 18, 2023
1 parent 4a15e83 commit 569197c
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/app/src/runner/events/capture-protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,10 @@ export const addCaptureProtocolListeners = (Cypress: Cypress.Cypress) => {

Cypress.backend('protocol:url:changed', { url, timestamp })
})

Cypress.on('page:loading', (loading) => {
const timestamp = performance.timeOrigin + performance.now()

Cypress.backend('protocol:page:loading', { loading, timestamp })
})
}
2 changes: 2 additions & 0 deletions packages/driver/types/internal-types-lite.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ declare namespace Cypress {
(action: 'before:screenshot', fn: (config: {}, fn: () => void) => void)
(action: 'after:screenshot', config: {})
(action: 'command:failed', fn: (command: CommandQueue, error: Error) => void): Cypress
(action: 'page:loading', fn: (loading: boolean) => void)
}

interface Backend {
Expand All @@ -28,6 +29,7 @@ declare namespace Cypress {
(task: 'protocol:test:before:run:async', attributes: any): Promise<void>
(task: 'protocol:test:after:run', attributes: any): Promise<void>
(task: 'protocol:url:changed', input: any): Promise<void>
(task: 'protocol:page:loading', input: any): Promise<void>
}

interface cy {
Expand Down
4 changes: 4 additions & 0 deletions packages/server/lib/cloud/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ export class ProtocolManager implements ProtocolManagerShape {
this.invokeSync('urlChanged', input)
}

pageLoading (input: any): void {
this.invokeSync('pageLoading', input)
}

async uploadCaptureArtifact (uploadUrl: string) {
const dbPath = this._dbPath

Expand Down
2 changes: 2 additions & 0 deletions packages/server/lib/socket-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,8 @@ export class SocketBase {
return this.protocolManager?.viewportChanged(args[0])
case 'protocol:url:changed':
return this.protocolManager?.urlChanged(args[0])
case 'protocol:page:loading':
return this.protocolManager?.pageLoading(args[0])
case 'telemetry':
return (telemetry.exporter() as OTLPTraceExporterCloud)?.send(args[0], () => {}, (err) => {
debug('error exporting telemetry data from browser %s', err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export class AppCaptureProtocol implements ProtocolManagerShape {
commandLogChanged = (log) => {}
viewportChanged = (input) => {}
urlChanged = (input) => {}
pageLoading = (input) => {}
sendErrors (errors) {
return Promise.resolve()
}
Expand Down
13 changes: 13 additions & 0 deletions packages/server/test/unit/cloud/protocol_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,4 +235,17 @@ describe('lib/cloud/protocol', () => {

expect(protocol.urlChanged).to.be.calledWith(input)
})

it('should be able to handle the page loading', () => {
sinon.stub(protocol, 'pageLoading')

const input = {
loading: true,
timestamp: 1234,
}

protocolManager.pageLoading(input)

expect(protocol.pageLoading).to.be.calledWith(input)
})
})
1 change: 1 addition & 0 deletions packages/types/src/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface AppCaptureProtocolCommon {
afterTest(test: Record<string, any>): void
afterSpec (): Promise<void>
connectToBrowser (cdpClient: CDPClient): Promise<void>
pageLoading (input: any): void
}

export interface AppCaptureProtocolInterface extends AppCaptureProtocolCommon {
Expand Down
1 change: 1 addition & 0 deletions system-tests/lib/protocolStub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export class AppCaptureProtocol implements ProtocolManagerShape {
commandLogChanged = (log) => {}
viewportChanged = (input) => {}
urlChanged = (input) => {}
pageLoading = (input) => {}
sendErrors (errors) {
return Promise.resolve()
}
Expand Down

5 comments on commit 569197c

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 569197c May 18, 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/12.13.0/linux-arm64/feat/protocol-569197c4fbbd6bce16b008a829b6c38e29cf89b0/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 569197c May 18, 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/12.13.0/linux-x64/feat/protocol-569197c4fbbd6bce16b008a829b6c38e29cf89b0/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 569197c May 18, 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/12.13.0/darwin-arm64/feat/protocol-569197c4fbbd6bce16b008a829b6c38e29cf89b0/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 569197c May 18, 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/12.13.0/darwin-x64/feat/protocol-569197c4fbbd6bce16b008a829b6c38e29cf89b0/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 569197c May 18, 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/12.13.0/win32-x64/feat/protocol-569197c4fbbd6bce16b008a829b6c38e29cf89b0/cypress.tgz

Please sign in to comment.