Skip to content

Commit

Permalink
chore: remove prerequests on request failed events (#27674)
Browse files Browse the repository at this point in the history
* chore: remove prerequests on request failed events

* fix test
  • Loading branch information
ryanthemanuel authored Aug 28, 2023
1 parent 485d91d commit d75dab1
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/server/lib/automation/automation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class Automation {
private cookies: Cookies
private screenshot: { capture: (data: any, automate: any) => any }

constructor (cyNamespace?: string, cookieNamespace?: string, screenshotsFolder?: string | false, public onBrowserPreRequest?: OnBrowserPreRequest, public onRequestEvent?: OnRequestEvent, public onRequestServedFromCache?: (requestId: string) => void) {
constructor (cyNamespace?: string, cookieNamespace?: string, screenshotsFolder?: string | false, public onBrowserPreRequest?: OnBrowserPreRequest, public onRequestEvent?: OnRequestEvent, public onRequestServedFromCache?: (requestId: string) => void, public onRequestFailed?: (requestId: string) => void) {
this.requests = {}

// set the middleware
Expand Down
5 changes: 5 additions & 0 deletions packages/server/lib/browsers/cdp_automation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ export class CdpAutomation implements CDPClient {
onFn('Network.requestWillBeSent', this.onNetworkRequestWillBeSent)
onFn('Network.responseReceived', this.onResponseReceived)
onFn('Network.requestServedFromCache', this.onRequestServedFromCache)
onFn('Network.loadingFailed', this.onRequestFailed)

this.on = onFn
this.off = offFn
Expand Down Expand Up @@ -245,6 +246,10 @@ export class CdpAutomation implements CDPClient {
this.automation.onRequestServedFromCache?.(params.requestId)
}

private onRequestFailed = (params: Protocol.Network.LoadingFailedEvent) => {
this.automation.onRequestFailed?.(params.requestId)
}

private onResponseReceived = (params: Protocol.Network.ResponseReceivedEvent) => {
const browserResponseReceived: BrowserResponseReceived = {
requestId: params.requestId,
Expand Down
10 changes: 7 additions & 3 deletions packages/server/lib/project-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,8 @@ export class ProjectBase extends EE {
}

startWebsockets (options: Omit<OpenProjectLaunchOptions, 'args'>, { socketIoCookie, namespace, screenshotsFolder, report, reporter, reporterOptions, projectRoot }: StartWebsocketOptions) {
// if we've passed down reporter
// then record these via mocha reporter
// if we've passed down reporter
// then record these via mocha reporter
const reporterInstance = this.initializeReporter({
report,
reporter,
Expand All @@ -334,7 +334,11 @@ export class ProjectBase extends EE {
this.server.removeBrowserPreRequest(requestId)
}

this._automation = new Automation(namespace, socketIoCookie, screenshotsFolder, onBrowserPreRequest, onRequestEvent, onRequestServedFromCache)
const onRequestFailed = (requestId: string) => {
this.server.removeBrowserPreRequest(requestId)
}

this._automation = new Automation(namespace, socketIoCookie, screenshotsFolder, onBrowserPreRequest, onRequestEvent, onRequestServedFromCache, onRequestFailed)

const ios = this.server.startWebsockets(this.automation, this.cfg, {
onReloadBrowser: options.onReloadBrowser,
Expand Down
15 changes: 15 additions & 0 deletions packages/server/test/unit/browsers/cdp_automation_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ context('lib/browsers/cdp_automation', () => {
onBrowserPreRequest: sinon.stub(),
onRequestEvent: sinon.stub(),
onRequestServedFromCache: sinon.stub(),
onRequestFailed: sinon.stub(),
}

cdpAutomation = await CdpAutomation.create(this.sendDebuggerCommand, this.onFn, this.offFn, this.sendCloseTargetCommand, this.automation)
Expand Down Expand Up @@ -196,6 +197,20 @@ context('lib/browsers/cdp_automation', () => {
})
})

describe('.onRequestFailed', function () {
it('triggers onRequestFailed', function () {
const browserRequestFailed = {
requestId: '0',
}

this.onFn
.withArgs('Network.loadingFailed')
.yield(browserRequestFailed)

expect(this.automation.onRequestFailed).to.have.been.calledWith(browserRequestFailed.requestId)
})
})

describe('get:cookies', () => {
beforeEach(function () {
this.sendDebuggerCommand.withArgs('Network.getAllCookies')
Expand Down

5 comments on commit d75dab1

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on d75dab1 Aug 28, 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-d75dab107e3903da47b94794b40c55e8bf6e7ab7/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on d75dab1 Aug 28, 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-d75dab107e3903da47b94794b40c55e8bf6e7ab7/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on d75dab1 Aug 28, 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-d75dab107e3903da47b94794b40c55e8bf6e7ab7/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on d75dab1 Aug 28, 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-d75dab107e3903da47b94794b40c55e8bf6e7ab7/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on d75dab1 Aug 28, 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-d75dab107e3903da47b94794b40c55e8bf6e7ab7/cypress.tgz

Please sign in to comment.