diff --git a/.github/workflows/ci-e2e.yml b/.github/workflows/ci-e2e.yml index 407bf7dc627..998842d482c 100644 --- a/.github/workflows/ci-e2e.yml +++ b/.github/workflows/ci-e2e.yml @@ -183,7 +183,6 @@ jobs: DISABLE_SECURE_SSL_REDIRECT=1 SECURE_COOKIES=0 OPT_OUT_CAPTURE=0 - SELF_CAPTURE=1 E2E_TESTING=1 SKIP_SERVICE_VERSION_REQUIREMENTS=1 EMAIL_HOST=email.test.posthog.net diff --git a/bin/e2e-test-runner b/bin/e2e-test-runner index 8196c62d49c..6a88c241727 100755 --- a/bin/e2e-test-runner +++ b/bin/e2e-test-runner @@ -49,7 +49,6 @@ done export DEBUG=1 export NO_RESTART_LOOP=1 export CYPRESS_BASE_URL=http://localhost:8080 -export OPT_OUT_CAPTURE="${OPT_OUT_CAPTURE:=1}" export SECURE_COOKIES=0 export SKIP_SERVICE_VERSION_REQUIREMENTS=1 export KAFKA_HOSTS=kafka:9092 diff --git a/cypress/README.md b/cypress/README.md index 9203f7aa709..0930a0ad7bc 100644 --- a/cypress/README.md +++ b/cypress/README.md @@ -7,7 +7,7 @@ To test feature flags you can intercept the call to the `decide` endpoint ```javascript // sometimes the system under test calls `/decide` // and sometimes it calls https://app.posthog.com/decide -cy.intercept('https://app.posthog.com/decide/*', (req) => +cy.intercept('**/decide/*', (req) => req.reply( decideResponse({ // add feature flags here, for e.g. diff --git a/cypress/e2e/billingv2.cy.ts b/cypress/e2e/billingv2.cy.ts index a591fb35084..13b819a4413 100644 --- a/cypress/e2e/billingv2.cy.ts +++ b/cypress/e2e/billingv2.cy.ts @@ -1,5 +1,3 @@ -import * as fflate from 'fflate' - const UNSUBSCRIBE_SURVEY_ID = '018b6e13-590c-0000-decb-c727a2b3f462' describe('Billing', () => { @@ -7,8 +5,6 @@ describe('Billing', () => { cy.intercept('/api/billing-v2/', { fixture: 'api/billing-v2/billing-v2.json' }) cy.visit('/organization/billing') - - cy.intercept('POST', '**/e/?compression=gzip-js*').as('capture') }) it('Show and submit unsubscribe survey', () => { @@ -22,19 +18,16 @@ describe('Billing', () => { cy.get('[data-attr=unsubscribe-reason-survey-textarea]').type('Product analytics') cy.contains('.LemonModal .LemonButton', 'Unsubscribe').click() - cy.wait('@capture').then(({ request }) => { - const data = new Uint8Array(request.body) - const decoded = fflate.strFromU8(fflate.decompressSync(data)) - const decodedJSON = JSON.parse(decoded) - - // These should be a 'survey sent' event somewhere in the decodedJSON - const matchingEvents = decodedJSON.filter((event) => event.event === 'survey sent') + cy.window().then((win) => { + const events = (win as any)._cypress_posthog_captures + const matchingEvents = events.filter((event) => event.event === 'survey sent') expect(matchingEvents.length).to.equal(1) const matchingEvent = matchingEvents[0] expect(matchingEvent.properties.$survey_id).to.equal(UNSUBSCRIBE_SURVEY_ID) expect(matchingEvent.properties.$survey_response).to.equal('Product analytics') expect(matchingEvent.properties.$survey_response_1).to.equal('product_analytics') }) + cy.get('.LemonModal').should('not.exist') cy.wait(['@unsubscribeProductAnalytics']) }) diff --git a/cypress/e2e/events.cy.ts b/cypress/e2e/events.cy.ts index 8d5d8476913..d8fea265698 100644 --- a/cypress/e2e/events.cy.ts +++ b/cypress/e2e/events.cy.ts @@ -7,19 +7,19 @@ const interceptPropertyDefinitions = (): void => { fixture: 'api/event/property_definitions', }) - cy.intercept('/api/projects/1/property_definitions?is_feature_flag=false&search=&*', { + cy.intercept('/api/projects/*/property_definitions?is_feature_flag=false&search=&*', { fixture: 'api/event/property_definitions', }) - cy.intercept('/api/projects/1/property_definitions?is_feature_flag=false&search=%24time*', { + cy.intercept('/api/projects/*/property_definitions?is_feature_flag=false&search=%24time*', { fixture: 'api/event/only_time_property_definition', }) - cy.intercept('/api/projects/1/property_definitions?is_feature_flag=false&search=%24browser*', { + cy.intercept('/api/projects/*/property_definitions?is_feature_flag=false&search=%24browser*', { fixture: 'api/event/only_browser_version_property_definition', }) - cy.intercept('/api/projects/1/property_definitions?is_feature_flag=true*', { + cy.intercept('/api/projects/*/property_definitions?is_feature_flag=true*', { fixture: 'api/event/feature_flag_property_definition', }) } diff --git a/cypress/e2e/experiments.cy.ts b/cypress/e2e/experiments.cy.ts index 5c168ffa0c3..77f42c50ccb 100644 --- a/cypress/e2e/experiments.cy.ts +++ b/cypress/e2e/experiments.cy.ts @@ -8,11 +8,11 @@ describe('Experiments', () => { fixture: 'api/experiments/user', }) - cy.intercept('/api/projects/1/experiments?limit=1000', { + cy.intercept('/api/projects/*/experiments?limit=1000', { fixture: 'api/experiments/experiments', }) - cy.intercept('/api/projects/1/experiments/1234/', { + cy.intercept('/api/projects/*/experiments/1234/', { fixture: 'api/experiments/new-experiment', }) diff --git a/cypress/e2e/featureFlags.cy.ts b/cypress/e2e/featureFlags.cy.ts index 8d8ded8174e..a60f391f933 100644 --- a/cypress/e2e/featureFlags.cy.ts +++ b/cypress/e2e/featureFlags.cy.ts @@ -4,7 +4,7 @@ describe('Feature Flags', () => { let name beforeEach(() => { - cy.intercept('https://us.i.posthog.com/decide/*', (req) => + cy.intercept('**/decide/*', (req) => req.reply( decideResponse({ 'new-feature-flag-operators': true, @@ -12,7 +12,7 @@ describe('Feature Flags', () => { ) ) - cy.intercept('/api/projects/1/property_definitions?type=person*', { + cy.intercept('/api/projects/*/property_definitions?type=person*', { fixture: 'api/feature-flags/property_definition', }) cy.intercept('/api/person/values/*', { diff --git a/cypress/e2e/onboarding.cy.ts b/cypress/e2e/onboarding.cy.ts index 46d1859bec1..c6e44e3d593 100644 --- a/cypress/e2e/onboarding.cy.ts +++ b/cypress/e2e/onboarding.cy.ts @@ -3,7 +3,7 @@ import { decideResponse } from '../fixtures/api/decide' describe('Onboarding', () => { beforeEach(() => { - cy.intercept('https://us.i.posthog.com/decide/*', (req) => + cy.intercept('**/decide/*', (req) => req.reply( decideResponse({ 'product-intro-pages': 'test', diff --git a/cypress/e2e/signup.cy.ts b/cypress/e2e/signup.cy.ts index a74ef52aa05..4ef40360003 100644 --- a/cypress/e2e/signup.cy.ts +++ b/cypress/e2e/signup.cy.ts @@ -74,8 +74,8 @@ describe('Signup', () => { cy.get('.Toastify [data-attr="error-toast"]').contains('Inactive social login session.') }) - it('Shows redirect notice if redirecting for maintenance', () => { - cy.intercept('https://us.i.posthog.com/decide/*', (req) => + it.only('Shows redirect notice if redirecting for maintenance', () => { + cy.intercept('**/decide/*', (req) => req.reply( decideResponse({ 'redirect-signups-to-instance': 'us', diff --git a/cypress/support/e2e.ts b/cypress/support/e2e.ts index 17ee12fe277..6785e5bd69f 100644 --- a/cypress/support/e2e.ts +++ b/cypress/support/e2e.ts @@ -16,6 +16,8 @@ const E2E_TESTING = Cypress.env('E2E_TESTING') Cypress.on('window:before:load', (win) => { cy.spy(win.console, 'error') cy.spy(win.console, 'warn') + + win._cypress_posthog_captures = [] }) beforeEach(() => { @@ -24,7 +26,7 @@ beforeEach(() => { Cypress.env('POSTHOG_PROPERTY_GITHUB_ACTION_RUN_URL', process.env.GITHUB_ACTION_RUN_URL) cy.useSubscriptionStatus('subscribed') - cy.intercept('https://us.i.posthog.com/decide/*', (req) => + cy.intercept('**/decide/*', (req) => req.reply( decideResponse({ // set feature flags here e.g. diff --git a/frontend/__snapshots__/layout-feature-previews--basic--dark.png b/frontend/__snapshots__/layout-feature-previews--basic--dark.png index e042f46f843..73414f8d228 100644 Binary files a/frontend/__snapshots__/layout-feature-previews--basic--dark.png and b/frontend/__snapshots__/layout-feature-previews--basic--dark.png differ diff --git a/frontend/__snapshots__/layout-feature-previews--basic--light.png b/frontend/__snapshots__/layout-feature-previews--basic--light.png index 724740a8b65..8018b3d2db8 100644 Binary files a/frontend/__snapshots__/layout-feature-previews--basic--light.png and b/frontend/__snapshots__/layout-feature-previews--basic--light.png differ diff --git a/frontend/__snapshots__/layout-feature-previews--with-constrained-feature--dark.png b/frontend/__snapshots__/layout-feature-previews--with-constrained-feature--dark.png index e042f46f843..716a7b2c1b5 100644 Binary files a/frontend/__snapshots__/layout-feature-previews--with-constrained-feature--dark.png and b/frontend/__snapshots__/layout-feature-previews--with-constrained-feature--dark.png differ diff --git a/frontend/__snapshots__/layout-feature-previews--with-constrained-feature--light.png b/frontend/__snapshots__/layout-feature-previews--with-constrained-feature--light.png index 724740a8b65..cd87de477e6 100644 Binary files a/frontend/__snapshots__/layout-feature-previews--with-constrained-feature--light.png and b/frontend/__snapshots__/layout-feature-previews--with-constrained-feature--light.png differ diff --git a/frontend/__snapshots__/posthog-3000-sidebar--dashboards--dark.png b/frontend/__snapshots__/posthog-3000-sidebar--dashboards--dark.png index 4364c14ce2a..7f417ca6f1d 100644 Binary files a/frontend/__snapshots__/posthog-3000-sidebar--dashboards--dark.png and b/frontend/__snapshots__/posthog-3000-sidebar--dashboards--dark.png differ diff --git a/frontend/__snapshots__/posthog-3000-sidebar--dashboards--light.png b/frontend/__snapshots__/posthog-3000-sidebar--dashboards--light.png index 4364c14ce2a..04c5d123699 100644 Binary files a/frontend/__snapshots__/posthog-3000-sidebar--dashboards--light.png and b/frontend/__snapshots__/posthog-3000-sidebar--dashboards--light.png differ diff --git a/frontend/__snapshots__/scenes-app-data-management--database--dark.png b/frontend/__snapshots__/scenes-app-data-management--database--dark.png index f5004f760a9..31141dbd976 100644 Binary files a/frontend/__snapshots__/scenes-app-data-management--database--dark.png and b/frontend/__snapshots__/scenes-app-data-management--database--dark.png differ diff --git a/frontend/__snapshots__/scenes-app-data-management--database--light.png b/frontend/__snapshots__/scenes-app-data-management--database--light.png index 934acd4c3fe..660db61a9d6 100644 Binary files a/frontend/__snapshots__/scenes-app-data-management--database--light.png and b/frontend/__snapshots__/scenes-app-data-management--database--light.png differ diff --git a/frontend/src/layout/FeaturePreviews/FeaturePreviews.stories.tsx b/frontend/src/layout/FeaturePreviews/FeaturePreviews.stories.tsx index 9946888196d..965b2d62054 100644 --- a/frontend/src/layout/FeaturePreviews/FeaturePreviews.stories.tsx +++ b/frontend/src/layout/FeaturePreviews/FeaturePreviews.stories.tsx @@ -27,7 +27,7 @@ CONSTRAINED_PREVIEWS.add('constrained-test-2' as FeatureFlagKey) const Template: StoryFn = ({ earlyAccessFeatures, enabledFeatureFlags }) => { useStorybookMocks({ get: { - 'https://app.posthog.com/api/early_access_features/': { earlyAccessFeatures }, + 'https://us.i.posthog.com/api/early_access_features/': { earlyAccessFeatures }, }, }) setFeatureFlags(enabledFeatureFlags) diff --git a/frontend/src/loadPostHogJS.tsx b/frontend/src/loadPostHogJS.tsx index 66a1d1ec009..aaa3902d9c9 100644 --- a/frontend/src/loadPostHogJS.tsx +++ b/frontend/src/loadPostHogJS.tsx @@ -42,10 +42,15 @@ export function loadPostHogJS(): void { autocapture: { capture_copied_text: true, }, + // 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, }) ) const Cypress = (window as any).Cypress + if (Cypress) { Object.entries(Cypress.env()).forEach(([key, value]) => { if (key.startsWith('POSTHOG_PROPERTY_')) { diff --git a/frontend/src/mocks/handlers.ts b/frontend/src/mocks/handlers.ts index b10c8700631..3b4d5c2577a 100644 --- a/frontend/src/mocks/handlers.ts +++ b/frontend/src/mocks/handlers.ts @@ -100,7 +100,7 @@ export const defaultMocks: Mocks = { // We don't want to show the "new version available" banner in tests 'https://api.github.com/repos/posthog/posthog-js/tags': () => [200, []], 'https://www.gravatar.com/avatar/:gravatar_id': () => [404, ''], - 'https://app.posthog.com/api/early_access_features': { + 'https://us.i.posthog.com/api/early_access_features': { earlyAccessFeatures: [], }, '/api/billing-v2/': { @@ -108,11 +108,11 @@ export const defaultMocks: Mocks = { }, }, post: { - 'https://app.posthog.com/e/': (): MockSignature => [200, 'ok'], + 'https://us.i.posthog.com/e/': (): MockSignature => [200, 'ok'], '/e/': (): MockSignature => [200, 'ok'], - 'https://app.posthog.com/decide/': (): MockSignature => [200, 'ok'], + 'https://us.i.posthog.com/decide/': (): MockSignature => [200, 'ok'], '/decide/': (): MockSignature => [200, 'ok'], - 'https://app.posthog.com/engage/': (): MockSignature => [200, 'ok'], + 'https://us.i.posthog.com/engage/': (): MockSignature => [200, 'ok'], '/api/projects/:team_id/insights/:insight_id/viewed/': (): MockSignature => [201, null], }, } diff --git a/package.json b/package.json index a4d3a59b64d..da374d17fbe 100644 --- a/package.json +++ b/package.json @@ -142,7 +142,7 @@ "pmtiles": "^2.11.0", "postcss": "^8.4.31", "postcss-preset-env": "^9.3.0", - "posthog-js": "1.111.1", + "posthog-js": "1.112.1", "posthog-js-lite": "2.5.0", "prettier": "^2.8.8", "prop-types": "^15.7.2", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 994a5559b1f..b35d4d214b3 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1,4 +1,4 @@ -lockfileVersion: '6.0' +lockfileVersion: '6.1' settings: autoInstallPeers: true @@ -245,8 +245,8 @@ dependencies: specifier: ^9.3.0 version: 9.3.0(postcss@8.4.31) posthog-js: - specifier: 1.111.1 - version: 1.111.1 + specifier: 1.112.1 + version: 1.112.1 posthog-js-lite: specifier: 2.5.0 version: 2.5.0 @@ -335,7 +335,7 @@ dependencies: optionalDependencies: fsevents: specifier: ^2.3.2 - version: 2.3.3 + version: 2.3.2 devDependencies: '@babel/core': @@ -12745,7 +12745,6 @@ packages: engines: {node: ^8.16.0 || ^10.6.0 || >=11.0.0} os: [darwin] requiresBuild: true - dev: true optional: true /fsevents@2.3.3: @@ -17386,8 +17385,8 @@ packages: resolution: {integrity: sha512-Urvlp0Vu9h3td0BVFWt0QXFJDoOZcaAD83XM9d91NKMKTVPZtfU0ysoxstIf5mw/ce9ZfuMgpWPaagrZI4rmSg==} dev: false - /posthog-js@1.111.1: - resolution: {integrity: sha512-glBx1uYFNzC7WXcB2V+FAPqTwumXMC+RhB0C2MzSGkyBjVB53ZnvSJnoEbwCo8eHzTIdlt+jWL6DtXf4SOu3OA==} + /posthog-js@1.112.1: + resolution: {integrity: sha512-BWYMLCu5bnSeahOyVkGgMvsiJSPqD/OEgwOJn8xi8U/i4pYwgeRfgMgkArexD7JVe9FAAdOmKw+995H0pJUDQw==} dependencies: fflate: 0.4.8 preact: 10.19.6 diff --git a/posthog/templates/head.html b/posthog/templates/head.html index f0ac06dea5a..76fe600107e 100644 --- a/posthog/templates/head.html +++ b/posthog/templates/head.html @@ -20,6 +20,7 @@