From d2e619cd5843dea19d242304fb92d347ab83c856 Mon Sep 17 00:00:00 2001 From: Paul D'Ambra Date: Mon, 8 Jul 2024 11:07:56 +0100 Subject: [PATCH] chore: fix error tests listener registration --- cypress/e2e/error-tracking.cy.ts | 11 ++++++----- cypress/support/e2e.ts | 4 ++-- cypress/support/setup.ts | 8 +++++++- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/cypress/e2e/error-tracking.cy.ts b/cypress/e2e/error-tracking.cy.ts index 9ec4b930e..36ed5f092 100644 --- a/cypress/e2e/error-tracking.cy.ts +++ b/cypress/e2e/error-tracking.cy.ts @@ -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', () => { diff --git a/cypress/support/e2e.ts b/cypress/support/e2e.ts index 51db24bb8..429a80322 100644 --- a/cypress/support/e2e.ts +++ b/cypress/support/e2e.ts @@ -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) => { @@ -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) => { diff --git a/cypress/support/setup.ts b/cypress/support/setup.ts index dcd4aaafb..2e31e880c 100644 --- a/cypress/support/setup.ts +++ b/cypress/support/setup.ts @@ -1,5 +1,7 @@ import { DecideResponse, PostHogConfig } from '../../src/types' +import { EventEmitter } from 'events' + export const start = ({ waitForDecide = true, initPosthog = true, @@ -19,6 +21,11 @@ export const start = ({ decideResponseOverrides?: Partial 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'], @@ -26,7 +33,6 @@ export const start = ({ excludedDomains: [], autocaptureExceptions: false, ...decideResponseOverrides, - config: { ...decideResponseOverrides.config }, } cy.intercept('POST', '/decide/*', decideResponse).as('decide')