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: remove prerequests on request failed events #27674

Merged
merged 3 commits into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
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