Skip to content

Commit

Permalink
add some logging, force the function
Browse files Browse the repository at this point in the history
  • Loading branch information
raquelmsmith committed Aug 26, 2024
1 parent e5a33c1 commit 1017808
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions cypress/e2e/billing.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ describe('Billing', () => {
cy.contains('.LemonModal .LemonButton', 'Unsubscribe').click()

cy.window().then((win) => {
win.console.warn('_CYPRESS_POSTHOG_CAPTURES', (win as any)._cypress_posthog_captures)
const events = (win as any)._cypress_posthog_captures
const matchingEvents = events.filter((event) => event.event === 'survey sent')
expect(matchingEvents.length).to.equal(1)
Expand Down
1 change: 1 addition & 0 deletions cypress/support/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Cypress.on('window:before:load', (win) => {
cy.spy(win.console, 'error')
cy.spy(win.console, 'warn')

win.console.warn('SETTING _CYPRESS_POSTHOG_CAPTURES')
win._cypress_posthog_captures = []
})

Expand Down
5 changes: 2 additions & 3 deletions frontend/src/loadPostHogJS.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const configWithSentry = (config: Partial<PostHogConfig>): Partial<PostHogConfig
}

export function loadPostHogJS(): void {
;(window as any)._cypress_posthog_captures = []
if (window.JS_POSTHOG_API_KEY) {
posthog.init(
window.JS_POSTHOG_API_KEY,
Expand Down Expand Up @@ -46,9 +47,7 @@ export function loadPostHogJS(): void {
person_profiles: 'always',

// Helper to capture events for assertions in Cypress
_onCapture: (window as any)._cypress_posthog_captures
? (_, event) => (window as any)._cypress_posthog_captures.push(event)
: undefined,
_onCapture: (_, event) => (window as any)._cypress_posthog_captures.push(event),
})
)

Expand Down

0 comments on commit 1017808

Please sign in to comment.