Skip to content

Commit

Permalink
chore: fix error tests listener registration
Browse files Browse the repository at this point in the history
  • Loading branch information
pauldambra committed Jul 8, 2024
1 parent 94522fe commit d2e619c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
11 changes: 6 additions & 5 deletions cypress/e2e/error-tracking.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
4 changes: 2 additions & 2 deletions cypress/support/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})

cy.readFile('dist/recorder.js.map').then((body) => {
Expand All @@ -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')
})

cy.readFile('dist/exception-autocapture.js.map').then((body) => {
Expand Down
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,
Expand All @@ -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 },
}
cy.intercept('POST', '/decide/*', decideResponse).as('decide')

Expand Down

0 comments on commit d2e619c

Please sign in to comment.