0
0
mirror of https://github.com/PostHog/posthog.git synced 2024-12-01 04:12:23 +01:00
posthog/playwright/e2e-vrt
Michael Matloka d02fac3332
style(3000): Implement PostHog 3000 navbar behind a feature flag (#14486)
* Add PostHog 3000 colors and button styles

* Update vars.ts

* Add PostHog 3000-style navigation behind a flag

* Fix `Tooltip` eating `onMouse{Enter,Leave}`

* Add story for PostHog 3000 navigation

* Update UI snapshots for `chromium` (1)

* Update UI snapshots for `webkit` (2)

* Update UI snapshots for `chromium` (2)

* Update UI snapshots for `webkit` (2)

* Update UI snapshots for `chromium` (2)

* Add sidebar

* Fix missing `useEffect` deps

* Remove "x" from "tsx" in logic file

* Add dark mode

* Improve color vars and transitions

* Properly handle loading and empty states in accordion

* Fix some background colors for dark mode

* Make homepage more 3000

* Remove dark mode for now

* Update UI snapshots for `chromium` (1)

* Update UI snapshots for `chromium` (2)

* Update UI snapshots for `chromium` (1)

* Update UI snapshots for `chromium` (1)

* Update UI snapshots for `chromium` (2)

* Move `posthog-3000` class handling a level higher to `App`

* Restore snapshots from `master`

* Fix snapshot flakiness

* Update UI snapshots for `chromium` (2)

* Update UI snapshots for `chromium` (1)

* Better align sidebar items

* Update UI snapshots for `chromium` (1)

* Spin out `SidebarAccordion.tsx` and use Kea subscriptions

---------

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
2023-03-13 15:22:09 +01:00
..
components test(frontend): Automatically test Storybook stories with snapshots (#13839) 2023-01-27 15:51:35 +01:00
layout style(navigation): Fix sidebar overlay height and backdrop (#13764) 2023-01-18 13:52:30 +01:00
lemon-ui style(3000): Implement PostHog 3000 navbar behind a feature flag (#14486) 2023-03-13 15:22:09 +01:00
scenes-app fix(frontend): popover scrollbar css (#14519) 2023-03-07 16:56:17 +00:00
README.md test(frontend): Automatically test Storybook stories with snapshots (#13839) 2023-01-27 15:51:35 +01:00

Visual Regression Tests

We're using Playwright to run visual regression tests against Storybook. To create reference images that are consistent between development and CI we run Playwright in an Ubuntu Docker container.

Workflow

Writing or updating a test

  1. Use fixtures

    tbd

  2. Perform the actions to get to the state

    • Get inspiration from one of the existing tests. Lemon Button and Insights scene are good examples.

    • Use Playwright's codegen feature to record user interactions interactively e.g. pnpm playwright codegen "http://localhost:6006/iframe.html?args=&id=scenes-app-insights--trends-line&viewMode=story".

    • Use Playwright's debug mode to inspect an existing test in a headed browser e.g. pnpm playwright test --debug e2e-vrt/scenes-app/mytest.spec.ts:17:5. Sprinkle in await page.pause() in your test to stop at specific lines.

  3. Add screenshot expectations:

    • Capture the whole page (we rarely use this):

      await expect(page).toHaveScreenshot({ fullPage: true })
      
    • Capture content within a container element:

      const locator = page.locator('#root')
      await expect(locator).toHaveScreenshot()
      
    • Suggested Storybook container elements:

      • #root for components and
      • .main-app-content for scenes
  4. Generate the reference images (you need to have Storybook running locally, i.e. on the Docker host machine):

    docker compose -f docker-compose.playwright.yml run -it --build -e STORYBOOK_URL=http://host.docker.internal:6006 playwright pnpm test:visual-regression
    

    If your docker compose version is lower than 2.13, you won't be able to use the --build flag. Instead, first run docker compose -f docker-compose.playwright.yml build playwright, and then the above run command - without the --build arg.

    Open the generated report locally with pnpm dlx playwright show-report to see test results (they are mounted local in docker volume)

Renaming or deleting tests

When deleting or renaming a test, (re-)move the respective reference images as well or delete rm -rf playwright/**/*.png and re-create (see above) them.

Troubleshooting

The CI run on GitHub fails for any reason

Troubleshoot by viewing the Playwright report: Click on "Details" next to the failing workflow, click on "Summary" and download the artifact file. Extract this file and navigate to it in a terminal to then run pnpm dlx playwright show-report.

Your locally generated images, don't verify CI checks

GitHub is running tests against a temporary merge commit (to ensure tests still pass after being merged), meaning any changes currently in master will be present in the images generated in the CI run. If you suspect this is the case, merge master into your branch and push again.