Skip to content

Commit

Permalink
misc: pass spec to beforeSpec to support better reporting on client s…
Browse files Browse the repository at this point in the history
…ide protocol errors (#30316)

* feat: pass spec to beforeSpec to support better reporting on client side protocol errors

* Update packages/types/src/protocol.ts

Co-authored-by: Matt Schile <mschile@cypress.io>

* update changelog

---------

Co-authored-by: Matt Schile <mschile@cypress.io>
  • Loading branch information
ryanthemanuel and mschile authored Sep 30, 2024
1 parent 6af6960 commit 8cff956
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
1 change: 1 addition & 0 deletions cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ _Released 10/1/2024 (PENDING)_
**Misc:**

- Cypress now consumes [geckodriver](https://firefox-source-docs.mozilla.org/testing/geckodriver/index.html) to help automate the Firefox browser instead of [marionette-client](https://github.com/cypress-io/marionette-client). Addresses [#30217](https://github.com/cypress-io/cypress/issues/30217).
- Pass spec information to protocol's `beforeSpec` to improve troubleshooting when reporting on errors. Addressed in [#30316](https://github.com/cypress-io/cypress/pull/30316).

## 13.15.0

Expand Down
8 changes: 4 additions & 4 deletions packages/server/lib/cloud/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import env from '../util/env'
import { putProtocolArtifact } from './api/put_protocol_artifact'

import type { Readable } from 'stream'
import type { ProtocolManagerShape, AppCaptureProtocolInterface, CDPClient, ProtocolError, CaptureArtifact, ProtocolErrorReport, ProtocolCaptureMethod, ProtocolManagerOptions, ResponseStreamOptions, ResponseEndedWithEmptyBodyOptions, ResponseStreamTimedOutOptions, AfterSpecDurations } from '@packages/types'
import type { ProtocolManagerShape, AppCaptureProtocolInterface, CDPClient, ProtocolError, CaptureArtifact, ProtocolErrorReport, ProtocolCaptureMethod, ProtocolManagerOptions, ResponseStreamOptions, ResponseEndedWithEmptyBodyOptions, ResponseStreamTimedOutOptions, AfterSpecDurations, SpecWithRelativeRoot } from '@packages/types'

const routes = require('./routes')

Expand Down Expand Up @@ -133,7 +133,7 @@ export class ProtocolManager implements ProtocolManagerShape {
this.invokeSync('addRunnables', { isEssential: true }, runnables)
}

beforeSpec (spec: { instanceId: string }) {
beforeSpec (spec: SpecWithRelativeRoot & { instanceId: string }) {
this._afterSpecDurations = undefined

if (!this._protocol) {
Expand All @@ -157,7 +157,7 @@ export class ProtocolManager implements ProtocolManagerShape {
}
}

private _beforeSpec (spec: { instanceId: string }) {
private _beforeSpec (spec: SpecWithRelativeRoot & { instanceId: string }) {
this._instanceId = spec.instanceId
const cypressProtocolDirectory = path.join(os.tmpdir(), 'cypress', 'protocol')
const archivePath = path.join(cypressProtocolDirectory, `${spec.instanceId}.tar`)
Expand All @@ -172,7 +172,7 @@ export class ProtocolManager implements ProtocolManagerShape {

this._db = db
this._archivePath = archivePath
this.invokeSync('beforeSpec', { isEssential: true }, { workingDirectory: cypressProtocolDirectory, archivePath, dbPath, db })
this.invokeSync('beforeSpec', { isEssential: true }, { workingDirectory: cypressProtocolDirectory, archivePath, dbPath, db, spec })
}

async afterSpec () {
Expand Down
16 changes: 14 additions & 2 deletions packages/server/test/unit/cloud/protocol_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,20 @@ describe('lib/cloud/protocol', () => {
},
]

protocolManager.beforeSpec({
const spec = {
instanceId: 'instanceId',
})
absolute: '/path/to/spec',
relative: 'spec',
relativeToCommonRoot: 'common/root',
specFileExtension: '.ts',
fileExtension: '.ts',
specType: 'integration' as Cypress.CypressSpecType,
baseName: 'spec',
name: 'spec',
fileName: 'spec.ts',
}

protocolManager.beforeSpec(spec)

expect((protocolManager as any)._errors).to.be.empty

Expand All @@ -101,6 +112,7 @@ describe('lib/cloud/protocol', () => {
archivePath: path.join(os.tmpdir(), 'cypress', 'protocol', 'instanceId.tar'),
dbPath: path.join(os.tmpdir(), 'cypress', 'protocol', 'instanceId.db'),
db: mockDb,
spec,
})

expect(mockDatabase).to.be.calledWith(path.join(os.tmpdir(), 'cypress', 'protocol', 'instanceId.db'), {
Expand Down
5 changes: 3 additions & 2 deletions packages/types/src/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type ProtocolMapping from 'devtools-protocol/types/protocol-mapping'
import type { IncomingHttpHeaders } from 'http'
import type { Readable } from 'stream'
import type { ProxyTimings } from './proxy'
import type { SpecWithRelativeRoot } from './spec'

type Commands = ProtocolMapping.Commands
type Command<T extends keyof Commands> = Commands[T]
Expand Down Expand Up @@ -38,7 +39,7 @@ export interface AppCaptureProtocolCommon {

export interface AppCaptureProtocolInterface extends AppCaptureProtocolCommon {
getDbMetadata (): { offset: number, size: number } | undefined
beforeSpec ({ workingDirectory, archivePath, dbPath, db }: { workingDirectory: string, archivePath: string, dbPath: string, db: Database }): void
beforeSpec ({ spec, workingDirectory, archivePath, dbPath, db }: { spec: SpecWithRelativeRoot & { instanceId: string }, workingDirectory: string, archivePath: string, dbPath: string, db: Database }): void
uploadStallSamplingInterval: () => number
}

Expand Down Expand Up @@ -117,7 +118,7 @@ export interface ProtocolManagerShape extends AppCaptureProtocolCommon {
protocolEnabled: boolean
networkEnableOptions?: { maxTotalBufferSize: number, maxResourceBufferSize: number, maxPostDataSize: number }
setupProtocol(script: string, options: ProtocolManagerOptions): Promise<void>
beforeSpec (spec: { instanceId: string }): void
beforeSpec (spec: SpecWithRelativeRoot & { instanceId: string }): void
afterSpec (): Promise<{ durations: AfterSpecDurations } | undefined>
reportNonFatalErrors (clientMetadata: any): Promise<void>
uploadCaptureArtifact(artifact: CaptureArtifact): Promise<UploadCaptureArtifactResult | void>
Expand Down

7 comments on commit 8cff956

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 8cff956 Sep 30, 2024

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.15.1/linux-arm64/develop-8cff95661ac4890009d0ee1a174aeae8d17d0dec/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 8cff956 Sep 30, 2024

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.15.1/linux-x64/develop-8cff95661ac4890009d0ee1a174aeae8d17d0dec/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 8cff956 Oct 1, 2024

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.15.1/darwin-x64/develop-8cff95661ac4890009d0ee1a174aeae8d17d0dec/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 8cff956 Oct 1, 2024

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.15.1/linux-arm64/develop-8cff95661ac4890009d0ee1a174aeae8d17d0dec/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 8cff956 Oct 1, 2024

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.15.1/linux-x64/develop-8cff95661ac4890009d0ee1a174aeae8d17d0dec/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 8cff956 Oct 1, 2024

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.15.1/darwin-arm64/develop-8cff95661ac4890009d0ee1a174aeae8d17d0dec/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 8cff956 Oct 1, 2024

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.15.1/darwin-x64/develop-8cff95661ac4890009d0ee1a174aeae8d17d0dec/cypress.tgz

Please sign in to comment.