:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
chore(tests): move browser-independent playwright coverage down to jest (#80641)
Paul D'Ambrabf796fa38b69
diff --git a/frontend/src/scenes/PreflightCheck/PreflightCheck.test.tsx b/frontend/src/scenes/PreflightCheck/PreflightCheck.test.tsxnew file mode 100644index 000000000000..6b6e2f7ba29a--- /dev/null+++ b/frontend/src/scenes/PreflightCheck/PreflightCheck.test.tsx@@ -0,0 +1,132 @@+import '@testing-library/jest-dom'++import { cleanup, render, screen, waitFor } from '@testing-library/react'+import userEvent from '@testing-library/user-event'+import { Provider } from 'kea'+import { router } from 'kea-router'++import { urls } from 'scenes/urls'++import { useMocks } from '~/mocks/jest'+import { initKeaTests } from '~/test/init'++import { PreflightCheck } from './PreflightCheck'++const preflightSuccessResponse = {+ django: true,+ redis: true,+ plugins: true,+ celery: true,+ clickhouse: true,+ kafka: true,+ db: true,+ initiated: true,+ cloud: false,+ demo: false,+ realm: 'hosted-clickhouse',+ region: null,+ available_social_auth_providers: { github: false, gitlab: false, 'google-oauth2': false },+ can_create_org: true,+ email_service_available: true,+ slack_service: { available: false, client_id: null },+ object_storage: true,+}++describe('PreflightCheck', () => {+ beforeEach(() => {+ initKeaTests()+ })++ afterEach(() => {+ cleanup()+ })++ function useSetupMocks(preflightOverrides: Record<string, unknown> = {}): void {+ useMocks({+ get: {+ '/_preflight': { ...preflightSuccessResponse, ...preflightOverrides },+ },+ })+ }++ function renderPreflight(): void {+ render(+ <Provider>+ <PreflightCheck />+ </Provider>+ )+ }++ function statusTexts(): string[] {+ return screen.getAllByTestId('status-text').map((el) => el.textContent ?? '')+ }++ function countStatus(status: string): number {+ return statusTexts().filter((text) => text === status).length+ }++ // jsdom serves over http, so the TLS check is the one expected warning in live mode+ // (and the one "optional" in experimentation mode).+ it.each([+ {+ description: 'all services healthy allows continuing',+ overrides: {},+ expectedValidated: 9,+ expectedWarning: 1,+ expectedError: 0,+ canContinue: true,+ },+ {+ description: 'a required service being down blocks continuing',+ overrides: { celery: false },+ expectedValidated: 8,+ expectedWarning: 1,+ expectedError: 1,+ canContinue: false,+ },+ ])(+ 'live mode: $description',+ async ({ overrides, expectedValidated, expectedWarning, expectedError, canContinue }) => {+ useSetupMocks(overrides)+ renderPreflight()++ await userEvent.click(await screen.findByTestId('preflight-live'))++ await waitFor(() => {+ expect(countStatus('Validated')).toBe(expectedValidated)+ })+ expect(countStatus('Warning')).toBe(expectedWarning)+ expect(countStatus('Error')).toBe(expectedError)+ expect(screen.getByText('Set up before ingesting real user data')).toBeInTheDocument()++ if (canContinue) {+ expect(screen.getByTestId('preflight-complete')).toBeInTheDocument()+ expect(+ screen.queryByText('All required checks must pass before you can continue')+ ).not.toBeInTheDocument()+ } else {+ expect(screen.queryByTestId('preflight-complete')).not.toBeInTheDocument()+ expect(screen.getByText('All required checks must pass before you can continue')).toBeInTheDocument()+ }+ }+ )++ it('experimentation mode: TLS is optional and completing routes to signup', async () => {+ useSetupMocks()+ renderPreflight()++ await userEvent.click(await screen.findByTestId('preflight-experimentation'))++ await waitFor(() => {+ expect(countStatus('Optional')).toBe(1)+ })+ expect(screen.getByTestId('preflight-refresh')).toBeInTheDocument()+ expect(screen.getByText('Not required for experimentation mode')).toBeInTheDocument()++ await userEvent.click(screen.getByTestId('preflight-complete'))++ await waitFor(() => {+ expect(router.values.location.pathname).toBe(urls.signup())+ })+ })+})diff --git a/frontend/src/scenes/authentication/signup/signupForm/SignupForm.test.tsx b/frontend/src/scenes/authentication/signup/signupForm/SignupForm.test.tsxnew file mode 100644index 000000000000..c3b66b32bdc0--- /dev/null+++ b/frontend/src/scenes/authentication/signup/signupForm/SignupForm.test.tsx@@ -0,0 +1,123 @@+import '@testing-library/jest-dom'++import { cleanup, render, screen, waitFor } from '@testing-library/react'+import userEvent from '@testing-library/user-event'+import { Provider } from 'kea'+import { router } from 'kea-router'++import { useMocks } from '~/mocks/jest'+import { initKeaTests } from '~/test/init'++import { SignupForm } from './SignupForm'++describe('SignupForm', () => {+ let signupRequestBody: Record<string, any> | null++ beforeEach(() => {+ signupRequestBody = null+ useMocks({+ get: {+ // The form only renders for a logged-out user+ '/api/users/@me/': () => [401, { detail: 'Not authenticated' }],+ },+ post: {+ '/api/signup/precheck': () => [200, { email_exists: false, pending_invite: null }],+ // 400 rather than 201 so the submit handler never assigns `location.href`,+ // which jsdom does not implement. The request body is captured before the response.+ '/api/signup/': async (info) => {+ signupRequestBody = (await info.request.clone().json()) as Record<string, any>+ return [400, { type: 'validation_error', code: 'error', detail: 'Mocked failure', attr: null }]+ },+ },+ })+ // initKeaTests bootstraps a logged-in user unless current_user is pre-set; the+ // form only renders logged-out+ window.POSTHOG_APP_CONTEXT = { current_user: null } as any+ initKeaTests()+ router.actions.push('/signup')+ render(+ <Provider>+ <SignupForm />+ </Provider>+ )+ })++ afterEach(() => {+ cleanup()+ })++ async function submitEmail(email: string): Promise<void> {+ if (email) {+ await userEvent.type(screen.getByTestId('signup-email'), email)+ }+ await userEvent.click(screen.getByTestId('signup-start'))+ }++ async function submitPassword(password: string): Promise<void> {+ await userEvent.type(await screen.findByTestId('password'), password)+ await userEvent.click(screen.getByTestId('signup-auth-continue'))+ }++ async function fillOnboardingAndSubmit({+ name,+ organizationName,+ }: {+ name: string+ organizationName?: string+ }): Promise<void> {+ await userEvent.type(await screen.findByTestId('signup-name'), name)+ if (organizationName) {+ await userEvent.type(screen.getByTestId('signup-organization-name'), organizationName)+ }+ await userEvent.click(screen.getByTestId('signup-role-at-organization'))+ await userEvent.click(await screen.findByText('Engineering'))+ await userEvent.click(screen.getByTestId('signup-submit'))+ }++ it('submitting without an email shows the error and stays on the email panel', async () => {+ await submitEmail('')++ expect(await screen.findByText('Please enter your email to continue')).toBeVisible()+ expect(screen.getByTestId('signup-email')).toBeInTheDocument()+ })++ it('a too-short password shows the min-length error; a valid one advances to onboarding', async () => {+ await submitEmail('[email protected]')++ await submitPassword('123')+ expect(await screen.findByText('Must be at least 8 characters long')).toBeVisible()+ expect(screen.queryByTestId('signup-name')).not.toBeInTheDocument()++ await userEvent.clear(screen.getByTestId('password'))+ await submitPassword('Str0ng-Test-Pass!')+ expect(await screen.findByTestId('signup-name')).toBeInTheDocument()+ expect(screen.queryByText('Must be at least 8 characters long')).not.toBeInTheDocument()+ })++ it('a padded full name reaches the signup payload trimmed and split into first and last name', async () => {+ await submitEmail('[email protected]')+ await submitPassword('Str0ng-Test-Pass!')+ // A leading space used to slip through client validation and produce first_name: ""+ await fillOnboardingAndSubmit({ name: ' Alice Bob', organizationName: 'Hogflix SpinOff' })++ await waitFor(() => {+ expect(signupRequestBody).not.toBeNull()+ })+ expect(signupRequestBody?.first_name).toBe('Alice')+ expect(signupRequestBody?.last_name).toBe('Bob')+ expect(signupRequestBody?.organization_name).toBe('Hogflix SpinOff')+ })++ it('a single-word name sends first_name only and omits the blank organization name', async () => {+ await submitEmail('[email protected]')+ await submitPassword('Str0ng-Test-Pass!')+ await fillOnboardingAndSubmit({ name: 'Alice' })++ await waitFor(() => {+ expect(signupRequestBody).not.toBeNull()+ })+ expect(signupRequestBody?.first_name).toBe('Alice')+ expect(signupRequestBody).not.toHaveProperty('last_name')+ expect(signupRequestBody).not.toHaveProperty('organization_name')+ })+})diff --git a/playwright/e2e/preflight.spec.ts b/playwright/e2e/preflight.spec.tsdeleted file mode 100644index 8fdfaa40156a..000000000000--- a/playwright/e2e/preflight.spec.ts+++ /dev/null@@ -1,89 +0,0 @@-import { expect, test } from '../utils/workspace-test-base'--const preflightSuccessResponse = {- django: true,- redis: true,- plugins: true,- celery: true,- clickhouse: true,- kafka: true,- db: true,- initiated: true,- cloud: false,- demo: false,- realm: 'hosted-clickhouse',- region: null,- available_social_auth_providers: { github: false, gitlab: false, 'google-oauth2': false },- can_create_org: true,- email_service_available: true,- slack_service: { available: false, client_id: null },- object_storage: true,-}--test.describe('Preflight', () => {- test('Preflight experimentation', async ({ page }) => {- await page.route(/_preflight/, async (route) => {- await route.fulfill({ json: preflightSuccessResponse })- })-- // Clear session cookies instead of logout for preflight tests- await page.context().clearCookies()- await page.goto('/preflight')-- await page.locator('[data-attr=preflight-experimentation]').click()-- await expect(page.locator('[data-attr=preflight-refresh]')).toBeVisible()- // expand rows- await page.locator('.Preflight__check-summary .LemonButton').click()- await expect(page.locator('.PreflightItem [data-attr=caption]')).toContainText(- 'Not required for experimentation mode'- )- await expect(page.locator('[data-attr=preflight-complete]')).toBeVisible()- await page.locator('[data-attr=preflight-complete]').click()- await expect(page).toHaveURL(/.*\/signup/)- })-- test('Preflight live mode', async ({ page }) => {- await page.route(/_preflight/, async (route) => {- await route.fulfill({ json: preflightSuccessResponse })- })-- // Clear session cookies instead of logout for preflight tests- await page.context().clearCookies()- await page.goto('/preflight')-- await page.locator('[data-attr=preflight-live]').click()- await expect(page.locator('.PreflightItem')).toHaveCount(10)- await expect(page.locator('[data-attr="status-text"]:has-text("Validated")')).toHaveCount(9)- await expect(page.locator('[data-attr="status-text"]:has-text("Warning")')).toHaveCount(1)- await expect(page.locator('.PreflightItem [data-attr=caption]')).toContainText(- 'Set up before ingesting real user data'- )- await expect(page.locator('[data-attr=preflight-complete]')).toBeVisible()- })-- test('Preflight can have errors too', async ({ page }) => {- await page.route(/_preflight/, async (route) => {- await route.fulfill({ json: { ...preflightSuccessResponse, celery: false } })- })-- // Clear session cookies instead of logout for preflight tests- await page.context().clearCookies()- await page.goto('/preflight')-- await page.locator('[data-attr=preflight-live]').click()- await expect(page.locator('.PreflightItem')).toHaveCount(10)- await expect(page.locator('[data-attr="status-text"]:has-text("Validated")')).toHaveCount(8)- await expect(page.locator('[data-attr="status-text"]:has-text("Warning")')).toHaveCount(1)- await expect(page.locator('[data-attr="status-text"]:has-text("Error")')).toHaveCount(1)- await expect(page.locator('.PreflightItem [data-attr=caption]')).toContainText(- 'Set up before ingesting real user data'- )- await expect(page.locator('[data-attr=preflight-complete]')).not.toBeVisible()- await expect(- page.locator(- '.Preflight__cannot-continue:has-text("All required checks must pass before you can continue")'- )- ).toHaveCount(1)- })-})diff --git a/playwright/e2e/signup.spec.ts b/playwright/e2e/signup.spec.tsindex df10aa5f68ec..36677ee9dfdc 100644--- a/playwright/e2e/signup.spec.ts+++ b/playwright/e2e/signup.spec.ts@@ -59,31 +59,6 @@ test.describe('Signup', () => {await submitEmailAndExpectExistingAccount(page, '[email protected]')})- test('Cannot signup without required attributes', async ({ page }) => {- await page.locator('[data-attr=signup-start]').click()-- await expect(page.getByText('Please enter your email to continue')).toBeVisible()- })-- test('Cannot signup with invalid attributes', async ({ page }) => {- await page.locator('[data-attr=signup-start]').click()- await expect(page.getByText('Please enter your email to continue')).toBeVisible()-- const email = `new_user+${Math.floor(Math.random() * 10000)}@posthog.com`- await page.locator('[data-attr=signup-email]').fill(email)- await expect(page.locator('[data-attr=signup-email]')).toHaveValue(email)- await page.locator('[data-attr=signup-start]').click()-- await expect(page.locator('[data-attr=signup-auth-continue]')).toBeVisible()- await page.locator('[data-attr=password]').fill('123')- await page.locator('[data-attr=signup-auth-continue]').click()- await expect(page.getByText('Must be at least 8 characters long')).toBeVisible()-- await page.locator('[data-attr=password]').fill('123 abc def')- await page.locator('[data-attr=signup-auth-continue]').click()- await expect(page.getByText('Must be at least 8 characters long')).not.toBeVisible()- })-test('Can create user account with first name, last name and organization name', async ({ page }) => {let signupRequestBody: string | null = null@@ -111,31 +86,6 @@ test.describe('Signup', () => {await expect(page).toHaveURL(/\/verify_email\/[a-zA-Z0-9_.-]*/)})- test('Trims surrounding whitespace in the name so first_name is never blank', async ({ page }) => {- let signupRequestBody: string | null = null-- await page.route('/api/signup/', async (route) => {- signupRequestBody = route.request().postData()- await route.continue()- })-- const email = `new_user+${Math.floor(Math.random() * 10000)}@posthog.com`- await startSignupFlow(page, email, VALID_PASSWORD)- // A leading space used to slip through client validation and produce first_name: ""- await page.locator('[data-attr=signup-name]').fill(' Alice Bob')- await expect(page.locator('[data-attr=signup-name]')).toHaveValue(' Alice Bob')- await page.locator('[data-attr=signup-role-at-organization]').click()- await page.locator('.Popover li').filter({ hasText: 'Engineering' }).click()- await expect(page.locator('[data-attr=signup-role-at-organization]')).toContainText('Engineering')- await page.locator('[data-attr=signup-submit]').click()-- const parsedBody = JSON.parse(signupRequestBody!)- expect(parsedBody.first_name).toEqual('Alice')- expect(parsedBody.last_name).toEqual('Bob')-- await expect(page).toHaveURL(/\/verify_email\/[a-zA-Z0-9_.-]*/)- })-test('Can submit the signup form multiple times if there is a generic email set', async ({ page }) => {let signupRequestBody: string | null = nullconst email = `new_user+generic_error_test_${Math.floor(Math.random() * 10000)}@posthog.com`@@ -188,35 +138,6 @@ test.describe('Signup', () => {await expect(page).toHaveURL(/\/verify_email\/[a-zA-Z0-9_.-]*/)})- test('Can create user account with just a first name', async ({ page }) => {- let signupRequestBody: string | null = null-- await page.route('/api/signup/', async (route) => {- signupRequestBody = route.request().postData()- await route.continue()- })-- const email = `new_user+${Math.floor(Math.random() * 10000)}@posthog.com`- await startSignupFlow(page, email, VALID_PASSWORD)- await page.locator('[data-attr=signup-name]').fill('Alice')- await expect(page.locator('[data-attr=signup-name]')).toHaveValue('Alice')- await page.locator('[data-attr=signup-role-at-organization]').click()- await page.locator('.Popover li').filter({ hasText: 'Engineering' }).click()- await expect(page.locator('[data-attr=signup-role-at-organization]')).toContainText('Engineering')-- // Wait for the signup request to complete- const signupPromise = page.waitForResponse('/api/signup/')- await page.locator('[data-attr=signup-submit]').click()- await signupPromise-- const parsedBody = JSON.parse(signupRequestBody!)- expect(parsedBody.first_name).toEqual('Alice')- expect(parsedBody.last_name).toBeUndefined()- expect(parsedBody.organization_name).toBeUndefined()-- await expect(page).toHaveURL(/\/verify_email\/[a-zA-Z0-9_.-]*/)- })-test('Can fill out all the fields on social login', async ({ page }) => {await page.context().clearCookies()await page.goto('/')diff --git a/tools/playwright_area_map.json b/tools/playwright_area_map.jsonindex b1d82fd17fe5..9757e9f079c8 100644--- a/tools/playwright_area_map.json+++ b/tools/playwright_area_map.json@@ -149,7 +149,6 @@},"full_suite_only": ["playwright/e2e/oauth-mcp-consent.spec.ts",- "playwright/e2e/preflight.spec.ts","playwright/e2e/system-status.spec.ts","playwright/e2e/ingestion-capture.spec.ts"]