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: fix error tests listener registration #1291

Merged
merged 1 commit into from
Jul 8, 2024
Merged
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
11 changes: 6 additions & 5 deletions cypress/e2e/error-tracking.cy.ts
Original file line number Diff line number Diff line change
@@ -2,17 +2,18 @@ import { start } from '../support/setup'

describe('Exception autocapture', () => {
beforeEach(() => {
cy.on('uncaught:exception', () => {
// otherwise the exception we throw on purpose causes the test to fail
return false
})

start({
decideResponseOverrides: {
autocaptureExceptions: true,
},
url: './playground/cypress',
})

cy.on('uncaught:exception', () => {
// otherwise the exception we throw on purpose causes the test to fail
return false
})
cy.wait('@exception-autocapture-script')
})

it('captures exceptions', () => {
4 changes: 2 additions & 2 deletions cypress/support/e2e.ts
Original file line number Diff line number Diff line change
@@ -32,7 +32,7 @@ beforeEach(() => {

cy.readFile('dist/recorder.js').then((body) => {
cy.intercept('/static/recorder.js*', { body }).as('recorder')
cy.intercept('/static/recorder-v2.js*', { body }).as('recorder')
cy.intercept('/static/recorder-v2.js*', { body }).as('recorderv2')
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should remove this tbh but fly-by rename so it doesn't clash

})

cy.readFile('dist/recorder.js.map').then((body) => {
@@ -48,7 +48,7 @@ beforeEach(() => {
})

cy.readFile('dist/exception-autocapture.js').then((body) => {
cy.intercept('/static/exception-autocapture.js*', { body })
cy.intercept('/static/exception-autocapture.js*', { body }).as('exception-autocapture-script')
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better safe than sorry

})

cy.readFile('dist/exception-autocapture.js.map').then((body) => {
8 changes: 7 additions & 1 deletion cypress/support/setup.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { DecideResponse, PostHogConfig } from '../../src/types'

import { EventEmitter } from 'events'

export const start = ({
waitForDecide = true,
initPosthog = true,
@@ -19,14 +21,18 @@ export const start = ({
decideResponseOverrides?: Partial<DecideResponse>
url?: string
}) => {
// sometimes we have too many listeners in this test environment
// that breaks the event emitter listeners in error tracking tests
// we don't see the error in production, so it's fine to increase the limit here
EventEmitter.prototype._maxListeners = 100

const decideResponse = {
editorParams: {},
featureFlags: ['session-recording-player'],
supportedCompression: ['gzip-js'],
excludedDomains: [],
autocaptureExceptions: false,
...decideResponseOverrides,
config: { ...decideResponseOverrides.config },
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nobody sends this, and DecideResponse doesn't have a config prop so 🔪

}
cy.intercept('POST', '/decide/*', decideResponse).as('decide')