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

feat: Use remote config #26777

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
14 changes: 5 additions & 9 deletions cypress/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,13 @@

The Cypress tests run with a PostHog instance that has no feature flags set up.

To test feature flags you can intercept the call to the `decide` endpoint
To test feature flags you can intercept the call to the `decide` endpoint using this helper

```javascript
// sometimes the system under test calls `/decide`
// and sometimes it calls https://app.posthog.com/decide
cy.intercept('**/decide/*', (req) =>
req.reply(
decideResponse({
// add feature flags here, for e.g.
// 'feature-flag-key': true,
})
)
)
setupFeatureFlags({
// add feature flags here, for e.g.
'feature-flag-key': true,
})
```
12 changes: 4 additions & 8 deletions cypress/e2e/alerts.cy.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import { decideResponse } from '../fixtures/api/decide'
import { createInsight, createInsightWithBreakdown } from '../productAnalytics'
import { setupFeatureFlags } from '../support/decide'

describe('Alerts', () => {
beforeEach(() => {
cy.intercept('**/decide/*', (req) =>
req.reply(
decideResponse({
alerts: true,
})
)
)
setupFeatureFlags({
alerts: true,
})
createInsight('insight')
})

Expand Down
13 changes: 5 additions & 8 deletions cypress/e2e/experiments.cy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { decideResponse } from '../fixtures/api/decide'
import { setupFeatureFlags } from '../support/decide'

describe('Experiments', () => {
let randomNum
Expand Down Expand Up @@ -47,13 +47,10 @@ describe('Experiments', () => {
})

const createExperimentInNewUi = (): void => {
cy.intercept('**/decide/*', (req) =>
req.reply(
decideResponse({
'new-experiments-ui': true,
})
)
)
setupFeatureFlags({
'new-experiments-ui': true,
})

cy.visit('/experiments')

// Name, flag key, description
Expand Down
12 changes: 4 additions & 8 deletions cypress/e2e/exports.cy.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
import { urls } from 'scenes/urls'

import { decideResponse } from '../fixtures/api/decide'
import { setupFeatureFlags } from '../support/decide'

// NOTE: As the API data is randomly generated, we are only really testing here that the overall output is correct
// The actual graph is not under test
describe('Exporting Insights', () => {
beforeEach(() => {
cy.intercept('https://us.i.posthog.com/decide/*', (req) =>
req.reply(
decideResponse({
'export-dashboard-insights': true,
})
)
)
setupFeatureFlags({
'export-dashboard-insights': true,
})
cy.visit(urls.insightNew())
// apply filter
cy.get('[data-attr$=add-filter-group]').click()
Expand Down
4 changes: 2 additions & 2 deletions cypress/e2e/featureFlags.cy.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { decideResponse } from '../fixtures/api/decide'
import { setupFeatureFlags } from '../support/decide'

describe('Feature Flags', () => {
let name

beforeEach(() => {
cy.intercept('**/decide/*', (req) => req.reply(decideResponse({})))
setupFeatureFlags({})

cy.intercept('/api/projects/*/property_definitions?type=person*', {
fixture: 'api/feature-flags/property_definition',
Expand Down
13 changes: 4 additions & 9 deletions cypress/e2e/onboarding.cy.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
import { decideResponse } from '../fixtures/api/decide'
import { setupFeatureFlags } from '../support/decide'

describe('Onboarding', () => {
beforeEach(() => {
cy.intercept('/api/billing/', { fixture: 'api/billing/billing-unsubscribed.json' })

cy.intercept('**/decide/*', (req) =>
req.reply(
decideResponse({
'product-intro-pages': 'test',
})
)
)
setupFeatureFlags({
'product-intro-pages': 'test',
})
})

it('Navigate between /products to /onboarding to a product intro page', () => {
Expand Down Expand Up @@ -39,7 +34,7 @@
cy.get('[data-attr=skip-onboarding]').should('not.exist')
})

// it('Step through PA onboarding', () => {

Check warning on line 37 in cypress/e2e/onboarding.cy.ts

View workflow job for this annotation

GitHub Actions / Code quality checks

Some tests seem to be commented
// cy.visit('/products')

// // Get started on product analytics onboarding
Expand Down Expand Up @@ -100,7 +95,7 @@
// cy.url().should('contain', 'project/1/insights')
// })

// it('Step through SR onboarding', () => {

Check warning on line 98 in cypress/e2e/onboarding.cy.ts

View workflow job for this annotation

GitHub Actions / Code quality checks

Some tests seem to be commented
// cy.visit('/products')
// cy.get('[data-attr=session_replay-onboarding-card]').click()

Expand All @@ -127,7 +122,7 @@
// cy.get('[data-attr=start-onboarding-sdk]').should('not.exist')
// })

// it('Step through FF onboarding', () => {

Check warning on line 125 in cypress/e2e/onboarding.cy.ts

View workflow job for this annotation

GitHub Actions / Code quality checks

Some tests seem to be commented
// cy.visit('/onboarding/feature_flags?step=product_intro')
// cy.get('[data-attr=start-onboarding-sdk]').first().click()
// cy.get('[data-attr=sdk-continue]').click()
Expand Down
12 changes: 4 additions & 8 deletions cypress/e2e/signup.cy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { decideResponse } from '../fixtures/api/decide'
import { setupFeatureFlags } from '../support/decide'

const VALID_PASSWORD = 'hedgE-hog-123%'

Expand Down Expand Up @@ -171,13 +171,9 @@ describe('Signup', () => {
})

it('Shows redirect notice if redirecting for maintenance', () => {
cy.intercept('**/decide/*', (req) =>
req.reply(
decideResponse({
'redirect-signups-to-instance': 'us',
})
)
)
setupFeatureFlags({
'redirect-signups-to-instance': 'us',
})

cy.visit('/logout')
cy.location('pathname').should('include', '/login')
Expand Down
1 change: 1 addition & 0 deletions cypress/fixtures/api/decide.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export function decideResponse(featureFlags) {
},
isAuthenticated: true,
supportedCompression: ['gzip', 'gzip-js', 'lz64'],
hasFeatureFlags: Object.keys(featureFlags).length > 0,
featureFlags,
sessionRecording: {
endpoint: '/s/',
Expand Down
28 changes: 28 additions & 0 deletions cypress/support/decide.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { decideResponse } from '../fixtures/api/decide'

export const setupFeatureFlags = (overrides: Record<string, any> = {}): void => {
// Tricky - the new RemoteConfig endpoint is optimised to not load decide if there are no feature flags in the DB.
// We need to intercept both the RemoteConfig and the decide endpoint to ensure that the feature flags are always loaded.

cy.intercept('**/array/*/config', (req) =>
req.reply(
decideResponse({
...overrides,
})
)
)

cy.intercept('**/array/*/config.js', (req) =>
req.continue((res) => {
res.send(res.body)
})
)

cy.intercept('**/decide/*', (req) =>
req.reply(
decideResponse({
...overrides,
})
)
)
}
11 changes: 2 additions & 9 deletions cypress/support/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'cypress-axe'

import { urls } from 'scenes/urls'

import { decideResponse } from '../fixtures/api/decide'
import { setupFeatureFlags } from './decide'

try {
// eslint-disable-next-line @typescript-eslint/no-var-requires
Expand Down Expand Up @@ -86,14 +86,7 @@ beforeEach(() => {
Cypress.env('POSTHOG_PROPERTY_GITHUB_ACTION_RUN_URL', process.env.GITHUB_ACTION_RUN_URL)
cy.useSubscriptionStatus('subscribed')

cy.intercept('**/decide/*', (req) =>
req.reply(
decideResponse({
// Feature flag to be treated as rolled out in E2E tests, e.g.:
// 'toolbar-launch-side-action': true,
})
)
)
setupFeatureFlags({})

// un-intercepted sometimes this doesn't work and the page gets stuck on the SpinnerOverlay
cy.intercept(/app.posthog.com\/api\/projects\/@current\/feature_flags\/my_flags.*/, (req) => req.reply([]))
Expand Down
1 change: 1 addition & 0 deletions frontend/src/loadPostHogJS.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export function loadPostHogJS(): void {
capture_copied_text: true,
},
person_profiles: 'always',
__preview_remote_config: true,

// Helper to capture events for assertions in Cypress
_onCapture: (window as any)._cypress_posthog_captures
Expand Down
Loading