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

fix: cleanup cross-origin logs between tests #28465

Closed
wants to merge 8 commits into from
8 changes: 8 additions & 0 deletions cli/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
<!-- See the ../guides/writing-the-cypress-changelog.md for details on writing the changelog. -->
## 13.6.1

_Released 12/19/2023 (PENDING)_

**Bugfixes:**

- Clean up the cy.origin() logs references between tests to reduce memory consumption. Fixed in [#28465](https://github.com/cypress-io/cypress/issues/28465).
emilyrohrbough marked this conversation as resolved.
Show resolved Hide resolved

## 13.6.1

_Released 12/5/2023_

**Bugfixes:**
Expand Down
12 changes: 5 additions & 7 deletions packages/app/src/runner/event-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ let crossOriginOnMessageRef = ({ data, source }: MessageEvent<{
}>) => {
return undefined
}
let crossOriginLogs: {[key: string]: Cypress.Log} = {}
let hasMochaRunEnded: boolean = false

interface AddGlobalListenerOptions {
Expand Down Expand Up @@ -737,16 +736,17 @@ export class EventManager {

// Create a new local log representation of the cross origin log.
// It will be attached to the current command.
// We also keep a reference to it to update it in the future.
crossOriginLogs[attrs.id] = Cypress.log(attrs)
Cypress.log(attrs)
})

Cypress.primaryOriginCommunicator.on('log:changed', (attrs) => {
// Retrieve the referenced log and update it.
const log = crossOriginLogs[attrs.id]
const logs = Cypress.cy.queue.logs({ id: attrs.id })

if (logs.length) {
// this will trigger a log changed event for the log itself.
log?.set(attrs)
logs[0]?.set(attrs)
}
})

// This message comes from the AUT, not the spec bridge. This is called in
Expand Down Expand Up @@ -858,8 +858,6 @@ export class EventManager {
Cypress.stop()
// Clean up the primary communicator to prevent possible memory leaks / dangling references before the Cypress instance is destroyed.
Cypress.primaryOriginCommunicator.removeAllListeners()
// clean up the cross origin logs in memory to prevent dangling references as the log objects themselves at this point will no longer be needed.
crossOriginLogs = {}

this.studioStore.setInactive()
}
Expand Down
Loading