0
0
mirror of https://github.com/PostHog/posthog.git synced 2024-11-25 11:17:50 +01:00
posthog/.storybook/test-runner.ts

273 lines
11 KiB
TypeScript
Raw Normal View History

import { toMatchImageSnapshot } from 'jest-image-snapshot'
import { getStoryContext, TestRunnerConfig, TestContext } from '@storybook/test-runner'
import type { Locator, Page, LocatorScreenshotOptions } from '@playwright/test'
import type { Mocks } from '~/mocks/utils'
import { StoryContext } from '@storybook/csf'
const DEFAULT_VIEWPORT = { width: 1280, height: 720 }
// 'firefox' is technically supported too, but as of June 2023 it has memory usage issues that make is unusable
type SupportedBrowserName = 'chromium' | 'webkit'
test(vrt): Don't clip scene snapshots (#19677) * test(vrt): Don't clip scene snapshots * Upgrade Playwright to 1.33 * Replace `excludeNavigationFromSnapshot` with `includeNavigationInSnapshot` * Tune locator * Fix `EmptyStates` flakiness * Fix `main` fallback * Try a different way of selecting `main` with fallback * Remove last `excludeNavigationFromSnapshot` * Use `.Navigation3000__scene` instead of `body` * Restore `overflow: visible` on navigation in tests * Fix top bar overlapping * More anti-clipping * Actually fix clipping * Fix `layout` parameter * Fix `.classList.add()` use * Remove empty `testOptions` * Tweak `waitForSelector` * Extend loader timeout * Update Surveys.stories.tsx * Update `UserPaths`'s `waitForSelector` * Print test errors * Revert "Print test errors" This reverts commit 71d305f8d3de872467e2a47504eb602fba2c77a3. * Capture whole scene in failure screenshot * Fix `CommandBar` snapshotting * Actually fix `CommandBar` snapshotting * Also fix modals * Force remount on snapshot retry * Actually fix modal, sidebar, and paths snapshotting * Fix observed flakiness * Remove legacy theme from visual tests * Update UI snapshots for `webkit` (2) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (2) * Fix sizing of `Toolbar` stories * Fix typing * Don't render zero-width funnel bar * Attempt to fix more flakiness * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (2) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (1) * Tweak selectors * Just hide the damn bar * Don't render grid layout without `gridWrapperWidth` * Use container query instead of React hook in `LemonBanner` * Update SavedInsights.stories.tsx * Explicitly size `LemonBanner` * Update Surveys.stories.tsx * Update UI snapshots for `chromium` (1) * Include navigation in side panel snapshots * Update UI snapshots for `chromium` (1) * Dispatch resize * Force settings sections in snapshots * Re-resize * Stabilize settings * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (2) * Update UI snapshots for `chromium` (2) --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
2024-03-18 10:51:46 +01:00
type SnapshotTheme = 'light' | 'dark'
// Extend Storybook interface `Parameters` with Chromatic parameters
declare module '@storybook/types' {
interface Parameters {
options?: any
test(vrt): Don't clip scene snapshots (#19677) * test(vrt): Don't clip scene snapshots * Upgrade Playwright to 1.33 * Replace `excludeNavigationFromSnapshot` with `includeNavigationInSnapshot` * Tune locator * Fix `EmptyStates` flakiness * Fix `main` fallback * Try a different way of selecting `main` with fallback * Remove last `excludeNavigationFromSnapshot` * Use `.Navigation3000__scene` instead of `body` * Restore `overflow: visible` on navigation in tests * Fix top bar overlapping * More anti-clipping * Actually fix clipping * Fix `layout` parameter * Fix `.classList.add()` use * Remove empty `testOptions` * Tweak `waitForSelector` * Extend loader timeout * Update Surveys.stories.tsx * Update `UserPaths`'s `waitForSelector` * Print test errors * Revert "Print test errors" This reverts commit 71d305f8d3de872467e2a47504eb602fba2c77a3. * Capture whole scene in failure screenshot * Fix `CommandBar` snapshotting * Actually fix `CommandBar` snapshotting * Also fix modals * Force remount on snapshot retry * Actually fix modal, sidebar, and paths snapshotting * Fix observed flakiness * Remove legacy theme from visual tests * Update UI snapshots for `webkit` (2) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (2) * Fix sizing of `Toolbar` stories * Fix typing * Don't render zero-width funnel bar * Attempt to fix more flakiness * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (2) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (1) * Tweak selectors * Just hide the damn bar * Don't render grid layout without `gridWrapperWidth` * Use container query instead of React hook in `LemonBanner` * Update SavedInsights.stories.tsx * Explicitly size `LemonBanner` * Update Surveys.stories.tsx * Update UI snapshots for `chromium` (1) * Include navigation in side panel snapshots * Update UI snapshots for `chromium` (1) * Dispatch resize * Force settings sections in snapshots * Re-resize * Stabilize settings * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (2) * Update UI snapshots for `chromium` (2) --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
2024-03-18 10:51:46 +01:00
/** @default 'padded' */
layout?: 'padded' | 'fullscreen' | 'centered'
testOptions?: {
/**
test(frontend): Improve reliability of visual regression tests (#14422) * test(frontend): Ensure 100% reliability of visual regression tests * Update UI snapshots for `chromium` (2) * Update UI snapshots for `chromium` (2) * Use OptiPNG in CI * Update UI snapshots for `chromium` (1) * Don't rely on pre-commit hook for image compression * Allow waiting for selector instead of constant delay * Update UI snapshots for `webkit` (2) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (2) * Update UI snapshots for `webkit` (2) * Add extra insight rendering conditions * Set strict timeouts for visual regression test jobs * Optimize OptiPNG step * Fix histogram selector * Update UI snapshots for `chromium` (2) * Update UI snapshots for `chromium` (2) * Ensure non-blank canvas * Fix blank canvas detection and auto-detect `waitForLoadersToDisappear` * Use `Spinner` for loading state in `MonacoEditor` * Make timeout limits less strict * Update UI snapshots for `chromium` (2) * Improve blank canvas detection further * Update UI snapshots for `webkit` (2) * Update UI snapshots for `chromium` (2) * Update UI snapshots for `chromium` (2) * Update UI snapshots for `webkit` (2) * Update UI snapshots for `webkit` (2) * Update UI snapshots for `chromium` (2) * Tune selectors * Update UI snapshots for `chromium` (2) * 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) * Try a different way of ensuring graphs are rendered * Update UI snapshots for `webkit` (2) * Increase `waitForLoadersToDisappear` initial UI wait * Update UI snapshots for `webkit` (2) * Make it easier to see what file wasn't pushed * Update UI snapshots for `chromium` (2) * Update UI snapshots for `chromium` (2) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (1) * Fix `timeout-minutes` * Update UI snapshots for `chromium` (2) * Update UI snapshots for `webkit` (2) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (1) * Add extra wait for canvases * Update UI snapshots for `chromium` (2) * Update UI snapshots for `chromium` (2) --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
2023-03-02 22:11:03 +01:00
* Whether we should wait for all loading indicators to disappear before taking a snapshot.
* @default true
*/
waitForLoadersToDisappear?: boolean
test(vrt): Don't clip scene snapshots (#19677) * test(vrt): Don't clip scene snapshots * Upgrade Playwright to 1.33 * Replace `excludeNavigationFromSnapshot` with `includeNavigationInSnapshot` * Tune locator * Fix `EmptyStates` flakiness * Fix `main` fallback * Try a different way of selecting `main` with fallback * Remove last `excludeNavigationFromSnapshot` * Use `.Navigation3000__scene` instead of `body` * Restore `overflow: visible` on navigation in tests * Fix top bar overlapping * More anti-clipping * Actually fix clipping * Fix `layout` parameter * Fix `.classList.add()` use * Remove empty `testOptions` * Tweak `waitForSelector` * Extend loader timeout * Update Surveys.stories.tsx * Update `UserPaths`'s `waitForSelector` * Print test errors * Revert "Print test errors" This reverts commit 71d305f8d3de872467e2a47504eb602fba2c77a3. * Capture whole scene in failure screenshot * Fix `CommandBar` snapshotting * Actually fix `CommandBar` snapshotting * Also fix modals * Force remount on snapshot retry * Actually fix modal, sidebar, and paths snapshotting * Fix observed flakiness * Remove legacy theme from visual tests * Update UI snapshots for `webkit` (2) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (2) * Fix sizing of `Toolbar` stories * Fix typing * Don't render zero-width funnel bar * Attempt to fix more flakiness * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (2) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (1) * Tweak selectors * Just hide the damn bar * Don't render grid layout without `gridWrapperWidth` * Use container query instead of React hook in `LemonBanner` * Update SavedInsights.stories.tsx * Explicitly size `LemonBanner` * Update Surveys.stories.tsx * Update UI snapshots for `chromium` (1) * Include navigation in side panel snapshots * Update UI snapshots for `chromium` (1) * Dispatch resize * Force settings sections in snapshots * Re-resize * Stabilize settings * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (2) * Update UI snapshots for `chromium` (2) --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
2024-03-18 10:51:46 +01:00
/** If set, we'll wait for the given selector (or all selectors, if multiple) to be satisfied. */
waitForSelector?: string | string[]
/**
test(vrt): Don't clip scene snapshots (#19677) * test(vrt): Don't clip scene snapshots * Upgrade Playwright to 1.33 * Replace `excludeNavigationFromSnapshot` with `includeNavigationInSnapshot` * Tune locator * Fix `EmptyStates` flakiness * Fix `main` fallback * Try a different way of selecting `main` with fallback * Remove last `excludeNavigationFromSnapshot` * Use `.Navigation3000__scene` instead of `body` * Restore `overflow: visible` on navigation in tests * Fix top bar overlapping * More anti-clipping * Actually fix clipping * Fix `layout` parameter * Fix `.classList.add()` use * Remove empty `testOptions` * Tweak `waitForSelector` * Extend loader timeout * Update Surveys.stories.tsx * Update `UserPaths`'s `waitForSelector` * Print test errors * Revert "Print test errors" This reverts commit 71d305f8d3de872467e2a47504eb602fba2c77a3. * Capture whole scene in failure screenshot * Fix `CommandBar` snapshotting * Actually fix `CommandBar` snapshotting * Also fix modals * Force remount on snapshot retry * Actually fix modal, sidebar, and paths snapshotting * Fix observed flakiness * Remove legacy theme from visual tests * Update UI snapshots for `webkit` (2) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (2) * Fix sizing of `Toolbar` stories * Fix typing * Don't render zero-width funnel bar * Attempt to fix more flakiness * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (2) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (1) * Tweak selectors * Just hide the damn bar * Don't render grid layout without `gridWrapperWidth` * Use container query instead of React hook in `LemonBanner` * Update SavedInsights.stories.tsx * Explicitly size `LemonBanner` * Update Surveys.stories.tsx * Update UI snapshots for `chromium` (1) * Include navigation in side panel snapshots * Update UI snapshots for `chromium` (1) * Dispatch resize * Force settings sections in snapshots * Re-resize * Stabilize settings * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (2) * Update UI snapshots for `chromium` (2) --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
2024-03-18 10:51:46 +01:00
* Whether navigation should be included in the snapshot. Only applies to `layout: 'fullscreen'` stories.
* @default false
*/
test(vrt): Don't clip scene snapshots (#19677) * test(vrt): Don't clip scene snapshots * Upgrade Playwright to 1.33 * Replace `excludeNavigationFromSnapshot` with `includeNavigationInSnapshot` * Tune locator * Fix `EmptyStates` flakiness * Fix `main` fallback * Try a different way of selecting `main` with fallback * Remove last `excludeNavigationFromSnapshot` * Use `.Navigation3000__scene` instead of `body` * Restore `overflow: visible` on navigation in tests * Fix top bar overlapping * More anti-clipping * Actually fix clipping * Fix `layout` parameter * Fix `.classList.add()` use * Remove empty `testOptions` * Tweak `waitForSelector` * Extend loader timeout * Update Surveys.stories.tsx * Update `UserPaths`'s `waitForSelector` * Print test errors * Revert "Print test errors" This reverts commit 71d305f8d3de872467e2a47504eb602fba2c77a3. * Capture whole scene in failure screenshot * Fix `CommandBar` snapshotting * Actually fix `CommandBar` snapshotting * Also fix modals * Force remount on snapshot retry * Actually fix modal, sidebar, and paths snapshotting * Fix observed flakiness * Remove legacy theme from visual tests * Update UI snapshots for `webkit` (2) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (2) * Fix sizing of `Toolbar` stories * Fix typing * Don't render zero-width funnel bar * Attempt to fix more flakiness * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (2) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (1) * Tweak selectors * Just hide the damn bar * Don't render grid layout without `gridWrapperWidth` * Use container query instead of React hook in `LemonBanner` * Update SavedInsights.stories.tsx * Explicitly size `LemonBanner` * Update Surveys.stories.tsx * Update UI snapshots for `chromium` (1) * Include navigation in side panel snapshots * Update UI snapshots for `chromium` (1) * Dispatch resize * Force settings sections in snapshots * Re-resize * Stabilize settings * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (2) * Update UI snapshots for `chromium` (2) --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
2024-03-18 10:51:46 +01:00
includeNavigationInSnapshot?: boolean
/**
* The test will always run for all the browers, but snapshots are only taken in Chromium by default.
* Override this to take snapshots in other browsers too.
*
* @default ['chromium']
*/
snapshotBrowsers?: SupportedBrowserName[]
/** If taking a component snapshot, you can narrow it down by specifying the selector. */
snapshotTargetSelector?: string
/** specify an alternative viewport size */
viewport?: { width: number; height: number }
}
msw?: {
mocks?: Mocks
}
[name: string]: any
}
interface Globals {
theme: SnapshotTheme
}
}
test(vrt): Don't clip scene snapshots (#19677) * test(vrt): Don't clip scene snapshots * Upgrade Playwright to 1.33 * Replace `excludeNavigationFromSnapshot` with `includeNavigationInSnapshot` * Tune locator * Fix `EmptyStates` flakiness * Fix `main` fallback * Try a different way of selecting `main` with fallback * Remove last `excludeNavigationFromSnapshot` * Use `.Navigation3000__scene` instead of `body` * Restore `overflow: visible` on navigation in tests * Fix top bar overlapping * More anti-clipping * Actually fix clipping * Fix `layout` parameter * Fix `.classList.add()` use * Remove empty `testOptions` * Tweak `waitForSelector` * Extend loader timeout * Update Surveys.stories.tsx * Update `UserPaths`'s `waitForSelector` * Print test errors * Revert "Print test errors" This reverts commit 71d305f8d3de872467e2a47504eb602fba2c77a3. * Capture whole scene in failure screenshot * Fix `CommandBar` snapshotting * Actually fix `CommandBar` snapshotting * Also fix modals * Force remount on snapshot retry * Actually fix modal, sidebar, and paths snapshotting * Fix observed flakiness * Remove legacy theme from visual tests * Update UI snapshots for `webkit` (2) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (2) * Fix sizing of `Toolbar` stories * Fix typing * Don't render zero-width funnel bar * Attempt to fix more flakiness * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (2) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (1) * Tweak selectors * Just hide the damn bar * Don't render grid layout without `gridWrapperWidth` * Use container query instead of React hook in `LemonBanner` * Update SavedInsights.stories.tsx * Explicitly size `LemonBanner` * Update Surveys.stories.tsx * Update UI snapshots for `chromium` (1) * Include navigation in side panel snapshots * Update UI snapshots for `chromium` (1) * Dispatch resize * Force settings sections in snapshots * Re-resize * Stabilize settings * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (2) * Update UI snapshots for `chromium` (2) --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
2024-03-18 10:51:46 +01:00
const RETRY_TIMES = 2
const LOADER_SELECTORS = [
'.Spinner',
'.LemonSkeleton',
'.LemonTableLoader',
test(vrt): Don't clip scene snapshots (#19677) * test(vrt): Don't clip scene snapshots * Upgrade Playwright to 1.33 * Replace `excludeNavigationFromSnapshot` with `includeNavigationInSnapshot` * Tune locator * Fix `EmptyStates` flakiness * Fix `main` fallback * Try a different way of selecting `main` with fallback * Remove last `excludeNavigationFromSnapshot` * Use `.Navigation3000__scene` instead of `body` * Restore `overflow: visible` on navigation in tests * Fix top bar overlapping * More anti-clipping * Actually fix clipping * Fix `layout` parameter * Fix `.classList.add()` use * Remove empty `testOptions` * Tweak `waitForSelector` * Extend loader timeout * Update Surveys.stories.tsx * Update `UserPaths`'s `waitForSelector` * Print test errors * Revert "Print test errors" This reverts commit 71d305f8d3de872467e2a47504eb602fba2c77a3. * Capture whole scene in failure screenshot * Fix `CommandBar` snapshotting * Actually fix `CommandBar` snapshotting * Also fix modals * Force remount on snapshot retry * Actually fix modal, sidebar, and paths snapshotting * Fix observed flakiness * Remove legacy theme from visual tests * Update UI snapshots for `webkit` (2) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (2) * Fix sizing of `Toolbar` stories * Fix typing * Don't render zero-width funnel bar * Attempt to fix more flakiness * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (2) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (1) * Tweak selectors * Just hide the damn bar * Don't render grid layout without `gridWrapperWidth` * Use container query instead of React hook in `LemonBanner` * Update SavedInsights.stories.tsx * Explicitly size `LemonBanner` * Update Surveys.stories.tsx * Update UI snapshots for `chromium` (1) * Include navigation in side panel snapshots * Update UI snapshots for `chromium` (1) * Dispatch resize * Force settings sections in snapshots * Re-resize * Stabilize settings * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (2) * Update UI snapshots for `chromium` (2) --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
2024-03-18 10:51:46 +01:00
'.Toastify__toast',
'[aria-busy="true"]',
'.SessionRecordingPlayer--buffering',
'.Lettermark--unknown',
]
const customSnapshotsDir = `${process.cwd()}/frontend/__snapshots__`
const JEST_TIMEOUT_MS = 15000
const PLAYWRIGHT_TIMEOUT_MS = 10000 // Must be shorter than JEST_TIMEOUT_MS
test(vrt): Don't clip scene snapshots (#19677) * test(vrt): Don't clip scene snapshots * Upgrade Playwright to 1.33 * Replace `excludeNavigationFromSnapshot` with `includeNavigationInSnapshot` * Tune locator * Fix `EmptyStates` flakiness * Fix `main` fallback * Try a different way of selecting `main` with fallback * Remove last `excludeNavigationFromSnapshot` * Use `.Navigation3000__scene` instead of `body` * Restore `overflow: visible` on navigation in tests * Fix top bar overlapping * More anti-clipping * Actually fix clipping * Fix `layout` parameter * Fix `.classList.add()` use * Remove empty `testOptions` * Tweak `waitForSelector` * Extend loader timeout * Update Surveys.stories.tsx * Update `UserPaths`'s `waitForSelector` * Print test errors * Revert "Print test errors" This reverts commit 71d305f8d3de872467e2a47504eb602fba2c77a3. * Capture whole scene in failure screenshot * Fix `CommandBar` snapshotting * Actually fix `CommandBar` snapshotting * Also fix modals * Force remount on snapshot retry * Actually fix modal, sidebar, and paths snapshotting * Fix observed flakiness * Remove legacy theme from visual tests * Update UI snapshots for `webkit` (2) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (2) * Fix sizing of `Toolbar` stories * Fix typing * Don't render zero-width funnel bar * Attempt to fix more flakiness * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (2) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (1) * Tweak selectors * Just hide the damn bar * Don't render grid layout without `gridWrapperWidth` * Use container query instead of React hook in `LemonBanner` * Update SavedInsights.stories.tsx * Explicitly size `LemonBanner` * Update Surveys.stories.tsx * Update UI snapshots for `chromium` (1) * Include navigation in side panel snapshots * Update UI snapshots for `chromium` (1) * Dispatch resize * Force settings sections in snapshots * Re-resize * Stabilize settings * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (2) * Update UI snapshots for `chromium` (2) --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
2024-03-18 10:51:46 +01:00
const ATTEMPT_COUNT_PER_ID: Record<string, number> = {}
module.exports = {
setup() {
expect.extend({ toMatchImageSnapshot })
jest.retryTimes(RETRY_TIMES, { logErrorsBeforeRetry: true })
jest.setTimeout(JEST_TIMEOUT_MS)
},
async preVisit(page, context) {
const storyContext = await getStoryContext(page, context)
const viewport = storyContext.parameters?.testOptions?.viewport || DEFAULT_VIEWPORT
await page.setViewportSize(viewport)
},
2023-11-22 16:24:37 +01:00
async postVisit(page, context) {
test(vrt): Don't clip scene snapshots (#19677) * test(vrt): Don't clip scene snapshots * Upgrade Playwright to 1.33 * Replace `excludeNavigationFromSnapshot` with `includeNavigationInSnapshot` * Tune locator * Fix `EmptyStates` flakiness * Fix `main` fallback * Try a different way of selecting `main` with fallback * Remove last `excludeNavigationFromSnapshot` * Use `.Navigation3000__scene` instead of `body` * Restore `overflow: visible` on navigation in tests * Fix top bar overlapping * More anti-clipping * Actually fix clipping * Fix `layout` parameter * Fix `.classList.add()` use * Remove empty `testOptions` * Tweak `waitForSelector` * Extend loader timeout * Update Surveys.stories.tsx * Update `UserPaths`'s `waitForSelector` * Print test errors * Revert "Print test errors" This reverts commit 71d305f8d3de872467e2a47504eb602fba2c77a3. * Capture whole scene in failure screenshot * Fix `CommandBar` snapshotting * Actually fix `CommandBar` snapshotting * Also fix modals * Force remount on snapshot retry * Actually fix modal, sidebar, and paths snapshotting * Fix observed flakiness * Remove legacy theme from visual tests * Update UI snapshots for `webkit` (2) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (2) * Fix sizing of `Toolbar` stories * Fix typing * Don't render zero-width funnel bar * Attempt to fix more flakiness * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (2) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (1) * Tweak selectors * Just hide the damn bar * Don't render grid layout without `gridWrapperWidth` * Use container query instead of React hook in `LemonBanner` * Update SavedInsights.stories.tsx * Explicitly size `LemonBanner` * Update Surveys.stories.tsx * Update UI snapshots for `chromium` (1) * Include navigation in side panel snapshots * Update UI snapshots for `chromium` (1) * Dispatch resize * Force settings sections in snapshots * Re-resize * Stabilize settings * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (2) * Update UI snapshots for `chromium` (2) --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
2024-03-18 10:51:46 +01:00
ATTEMPT_COUNT_PER_ID[context.id] = (ATTEMPT_COUNT_PER_ID[context.id] || 0) + 1
const storyContext = await getStoryContext(page, context)
const viewport = storyContext.parameters?.testOptions?.viewport || DEFAULT_VIEWPORT
test(vrt): Don't clip scene snapshots (#19677) * test(vrt): Don't clip scene snapshots * Upgrade Playwright to 1.33 * Replace `excludeNavigationFromSnapshot` with `includeNavigationInSnapshot` * Tune locator * Fix `EmptyStates` flakiness * Fix `main` fallback * Try a different way of selecting `main` with fallback * Remove last `excludeNavigationFromSnapshot` * Use `.Navigation3000__scene` instead of `body` * Restore `overflow: visible` on navigation in tests * Fix top bar overlapping * More anti-clipping * Actually fix clipping * Fix `layout` parameter * Fix `.classList.add()` use * Remove empty `testOptions` * Tweak `waitForSelector` * Extend loader timeout * Update Surveys.stories.tsx * Update `UserPaths`'s `waitForSelector` * Print test errors * Revert "Print test errors" This reverts commit 71d305f8d3de872467e2a47504eb602fba2c77a3. * Capture whole scene in failure screenshot * Fix `CommandBar` snapshotting * Actually fix `CommandBar` snapshotting * Also fix modals * Force remount on snapshot retry * Actually fix modal, sidebar, and paths snapshotting * Fix observed flakiness * Remove legacy theme from visual tests * Update UI snapshots for `webkit` (2) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (2) * Fix sizing of `Toolbar` stories * Fix typing * Don't render zero-width funnel bar * Attempt to fix more flakiness * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (2) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (1) * Tweak selectors * Just hide the damn bar * Don't render grid layout without `gridWrapperWidth` * Use container query instead of React hook in `LemonBanner` * Update SavedInsights.stories.tsx * Explicitly size `LemonBanner` * Update Surveys.stories.tsx * Update UI snapshots for `chromium` (1) * Include navigation in side panel snapshots * Update UI snapshots for `chromium` (1) * Dispatch resize * Force settings sections in snapshots * Re-resize * Stabilize settings * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (2) * Update UI snapshots for `chromium` (2) --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
2024-03-18 10:51:46 +01:00
await page.evaluate(
([retry, id]) => console.log(`[${id}] Attempt ${retry}`),
[ATTEMPT_COUNT_PER_ID[context.id], context.id]
)
if (ATTEMPT_COUNT_PER_ID[context.id] > 1) {
// When retrying, resize the viewport and then resize again to default,
// just in case the retry is due to a useResizeObserver fail
await page.setViewportSize({ width: 1920, height: 1080 })
await page.setViewportSize(viewport)
test(vrt): Don't clip scene snapshots (#19677) * test(vrt): Don't clip scene snapshots * Upgrade Playwright to 1.33 * Replace `excludeNavigationFromSnapshot` with `includeNavigationInSnapshot` * Tune locator * Fix `EmptyStates` flakiness * Fix `main` fallback * Try a different way of selecting `main` with fallback * Remove last `excludeNavigationFromSnapshot` * Use `.Navigation3000__scene` instead of `body` * Restore `overflow: visible` on navigation in tests * Fix top bar overlapping * More anti-clipping * Actually fix clipping * Fix `layout` parameter * Fix `.classList.add()` use * Remove empty `testOptions` * Tweak `waitForSelector` * Extend loader timeout * Update Surveys.stories.tsx * Update `UserPaths`'s `waitForSelector` * Print test errors * Revert "Print test errors" This reverts commit 71d305f8d3de872467e2a47504eb602fba2c77a3. * Capture whole scene in failure screenshot * Fix `CommandBar` snapshotting * Actually fix `CommandBar` snapshotting * Also fix modals * Force remount on snapshot retry * Actually fix modal, sidebar, and paths snapshotting * Fix observed flakiness * Remove legacy theme from visual tests * Update UI snapshots for `webkit` (2) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (2) * Fix sizing of `Toolbar` stories * Fix typing * Don't render zero-width funnel bar * Attempt to fix more flakiness * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (2) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (1) * Tweak selectors * Just hide the damn bar * Don't render grid layout without `gridWrapperWidth` * Use container query instead of React hook in `LemonBanner` * Update SavedInsights.stories.tsx * Explicitly size `LemonBanner` * Update Surveys.stories.tsx * Update UI snapshots for `chromium` (1) * Include navigation in side panel snapshots * Update UI snapshots for `chromium` (1) * Dispatch resize * Force settings sections in snapshots * Re-resize * Stabilize settings * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (2) * Update UI snapshots for `chromium` (2) --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
2024-03-18 10:51:46 +01:00
}
test(frontend): Improve reliability of visual regression tests (#14422) * test(frontend): Ensure 100% reliability of visual regression tests * Update UI snapshots for `chromium` (2) * Update UI snapshots for `chromium` (2) * Use OptiPNG in CI * Update UI snapshots for `chromium` (1) * Don't rely on pre-commit hook for image compression * Allow waiting for selector instead of constant delay * Update UI snapshots for `webkit` (2) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (2) * Update UI snapshots for `webkit` (2) * Add extra insight rendering conditions * Set strict timeouts for visual regression test jobs * Optimize OptiPNG step * Fix histogram selector * Update UI snapshots for `chromium` (2) * Update UI snapshots for `chromium` (2) * Ensure non-blank canvas * Fix blank canvas detection and auto-detect `waitForLoadersToDisappear` * Use `Spinner` for loading state in `MonacoEditor` * Make timeout limits less strict * Update UI snapshots for `chromium` (2) * Improve blank canvas detection further * Update UI snapshots for `webkit` (2) * Update UI snapshots for `chromium` (2) * Update UI snapshots for `chromium` (2) * Update UI snapshots for `webkit` (2) * Update UI snapshots for `webkit` (2) * Update UI snapshots for `chromium` (2) * Tune selectors * Update UI snapshots for `chromium` (2) * 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) * Try a different way of ensuring graphs are rendered * Update UI snapshots for `webkit` (2) * Increase `waitForLoadersToDisappear` initial UI wait * Update UI snapshots for `webkit` (2) * Make it easier to see what file wasn't pushed * Update UI snapshots for `chromium` (2) * Update UI snapshots for `chromium` (2) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (1) * Fix `timeout-minutes` * Update UI snapshots for `chromium` (2) * Update UI snapshots for `webkit` (2) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (1) * Add extra wait for canvases * Update UI snapshots for `chromium` (2) * Update UI snapshots for `chromium` (2) --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
2023-03-02 22:11:03 +01:00
const browserContext = page.context()
2023-11-22 16:24:37 +01:00
const { snapshotBrowsers = ['chromium'] } = storyContext.parameters?.testOptions ?? {}
browserContext.setDefaultTimeout(PLAYWRIGHT_TIMEOUT_MS)
2023-11-22 16:24:37 +01:00
const currentBrowser = browserContext.browser()!.browserType().name() as SupportedBrowserName
if (snapshotBrowsers.includes(currentBrowser)) {
await expectStoryToMatchSnapshot(page, context, storyContext, currentBrowser)
}
2023-11-22 16:24:37 +01:00
},
tags: {
skip: ['test-skip'], // NOTE: This is overridden by the CI action storybook-chromatic.yml to include browser specific skipping
},
} as TestRunnerConfig
async function expectStoryToMatchSnapshot(
page: Page,
context: TestContext,
storyContext: StoryContext,
browser: SupportedBrowserName
): Promise<void> {
test(frontend): Improve reliability of visual regression tests (#14422) * test(frontend): Ensure 100% reliability of visual regression tests * Update UI snapshots for `chromium` (2) * Update UI snapshots for `chromium` (2) * Use OptiPNG in CI * Update UI snapshots for `chromium` (1) * Don't rely on pre-commit hook for image compression * Allow waiting for selector instead of constant delay * Update UI snapshots for `webkit` (2) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (2) * Update UI snapshots for `webkit` (2) * Add extra insight rendering conditions * Set strict timeouts for visual regression test jobs * Optimize OptiPNG step * Fix histogram selector * Update UI snapshots for `chromium` (2) * Update UI snapshots for `chromium` (2) * Ensure non-blank canvas * Fix blank canvas detection and auto-detect `waitForLoadersToDisappear` * Use `Spinner` for loading state in `MonacoEditor` * Make timeout limits less strict * Update UI snapshots for `chromium` (2) * Improve blank canvas detection further * Update UI snapshots for `webkit` (2) * Update UI snapshots for `chromium` (2) * Update UI snapshots for `chromium` (2) * Update UI snapshots for `webkit` (2) * Update UI snapshots for `webkit` (2) * Update UI snapshots for `chromium` (2) * Tune selectors * Update UI snapshots for `chromium` (2) * 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) * Try a different way of ensuring graphs are rendered * Update UI snapshots for `webkit` (2) * Increase `waitForLoadersToDisappear` initial UI wait * Update UI snapshots for `webkit` (2) * Make it easier to see what file wasn't pushed * Update UI snapshots for `chromium` (2) * Update UI snapshots for `chromium` (2) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (1) * Fix `timeout-minutes` * Update UI snapshots for `chromium` (2) * Update UI snapshots for `webkit` (2) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (1) * Add extra wait for canvases * Update UI snapshots for `chromium` (2) * Update UI snapshots for `chromium` (2) --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
2023-03-02 22:11:03 +01:00
const {
waitForLoadersToDisappear = true,
waitForSelector,
test(vrt): Don't clip scene snapshots (#19677) * test(vrt): Don't clip scene snapshots * Upgrade Playwright to 1.33 * Replace `excludeNavigationFromSnapshot` with `includeNavigationInSnapshot` * Tune locator * Fix `EmptyStates` flakiness * Fix `main` fallback * Try a different way of selecting `main` with fallback * Remove last `excludeNavigationFromSnapshot` * Use `.Navigation3000__scene` instead of `body` * Restore `overflow: visible` on navigation in tests * Fix top bar overlapping * More anti-clipping * Actually fix clipping * Fix `layout` parameter * Fix `.classList.add()` use * Remove empty `testOptions` * Tweak `waitForSelector` * Extend loader timeout * Update Surveys.stories.tsx * Update `UserPaths`'s `waitForSelector` * Print test errors * Revert "Print test errors" This reverts commit 71d305f8d3de872467e2a47504eb602fba2c77a3. * Capture whole scene in failure screenshot * Fix `CommandBar` snapshotting * Actually fix `CommandBar` snapshotting * Also fix modals * Force remount on snapshot retry * Actually fix modal, sidebar, and paths snapshotting * Fix observed flakiness * Remove legacy theme from visual tests * Update UI snapshots for `webkit` (2) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (2) * Fix sizing of `Toolbar` stories * Fix typing * Don't render zero-width funnel bar * Attempt to fix more flakiness * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (2) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (1) * Tweak selectors * Just hide the damn bar * Don't render grid layout without `gridWrapperWidth` * Use container query instead of React hook in `LemonBanner` * Update SavedInsights.stories.tsx * Explicitly size `LemonBanner` * Update Surveys.stories.tsx * Update UI snapshots for `chromium` (1) * Include navigation in side panel snapshots * Update UI snapshots for `chromium` (1) * Dispatch resize * Force settings sections in snapshots * Re-resize * Stabilize settings * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (2) * Update UI snapshots for `chromium` (2) --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
2024-03-18 10:51:46 +01:00
includeNavigationInSnapshot = false,
test(frontend): Improve reliability of visual regression tests (#14422) * test(frontend): Ensure 100% reliability of visual regression tests * Update UI snapshots for `chromium` (2) * Update UI snapshots for `chromium` (2) * Use OptiPNG in CI * Update UI snapshots for `chromium` (1) * Don't rely on pre-commit hook for image compression * Allow waiting for selector instead of constant delay * Update UI snapshots for `webkit` (2) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (2) * Update UI snapshots for `webkit` (2) * Add extra insight rendering conditions * Set strict timeouts for visual regression test jobs * Optimize OptiPNG step * Fix histogram selector * Update UI snapshots for `chromium` (2) * Update UI snapshots for `chromium` (2) * Ensure non-blank canvas * Fix blank canvas detection and auto-detect `waitForLoadersToDisappear` * Use `Spinner` for loading state in `MonacoEditor` * Make timeout limits less strict * Update UI snapshots for `chromium` (2) * Improve blank canvas detection further * Update UI snapshots for `webkit` (2) * Update UI snapshots for `chromium` (2) * Update UI snapshots for `chromium` (2) * Update UI snapshots for `webkit` (2) * Update UI snapshots for `webkit` (2) * Update UI snapshots for `chromium` (2) * Tune selectors * Update UI snapshots for `chromium` (2) * 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) * Try a different way of ensuring graphs are rendered * Update UI snapshots for `webkit` (2) * Increase `waitForLoadersToDisappear` initial UI wait * Update UI snapshots for `webkit` (2) * Make it easier to see what file wasn't pushed * Update UI snapshots for `chromium` (2) * Update UI snapshots for `chromium` (2) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (1) * Fix `timeout-minutes` * Update UI snapshots for `chromium` (2) * Update UI snapshots for `webkit` (2) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (1) * Add extra wait for canvases * Update UI snapshots for `chromium` (2) * Update UI snapshots for `chromium` (2) --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
2023-03-02 22:11:03 +01:00
} = storyContext.parameters?.testOptions ?? {}
let check: (
page: Page,
context: TestContext,
browser: SupportedBrowserName,
theme: SnapshotTheme,
targetSelector?: string
) => Promise<void>
if (storyContext.parameters?.layout === 'fullscreen') {
test(vrt): Don't clip scene snapshots (#19677) * test(vrt): Don't clip scene snapshots * Upgrade Playwright to 1.33 * Replace `excludeNavigationFromSnapshot` with `includeNavigationInSnapshot` * Tune locator * Fix `EmptyStates` flakiness * Fix `main` fallback * Try a different way of selecting `main` with fallback * Remove last `excludeNavigationFromSnapshot` * Use `.Navigation3000__scene` instead of `body` * Restore `overflow: visible` on navigation in tests * Fix top bar overlapping * More anti-clipping * Actually fix clipping * Fix `layout` parameter * Fix `.classList.add()` use * Remove empty `testOptions` * Tweak `waitForSelector` * Extend loader timeout * Update Surveys.stories.tsx * Update `UserPaths`'s `waitForSelector` * Print test errors * Revert "Print test errors" This reverts commit 71d305f8d3de872467e2a47504eb602fba2c77a3. * Capture whole scene in failure screenshot * Fix `CommandBar` snapshotting * Actually fix `CommandBar` snapshotting * Also fix modals * Force remount on snapshot retry * Actually fix modal, sidebar, and paths snapshotting * Fix observed flakiness * Remove legacy theme from visual tests * Update UI snapshots for `webkit` (2) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (2) * Fix sizing of `Toolbar` stories * Fix typing * Don't render zero-width funnel bar * Attempt to fix more flakiness * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (2) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (1) * Tweak selectors * Just hide the damn bar * Don't render grid layout without `gridWrapperWidth` * Use container query instead of React hook in `LemonBanner` * Update SavedInsights.stories.tsx * Explicitly size `LemonBanner` * Update Surveys.stories.tsx * Update UI snapshots for `chromium` (1) * Include navigation in side panel snapshots * Update UI snapshots for `chromium` (1) * Dispatch resize * Force settings sections in snapshots * Re-resize * Stabilize settings * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (2) * Update UI snapshots for `chromium` (2) --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
2024-03-18 10:51:46 +01:00
if (includeNavigationInSnapshot) {
check = expectStoryToMatchViewportSnapshot
} else {
test(vrt): Don't clip scene snapshots (#19677) * test(vrt): Don't clip scene snapshots * Upgrade Playwright to 1.33 * Replace `excludeNavigationFromSnapshot` with `includeNavigationInSnapshot` * Tune locator * Fix `EmptyStates` flakiness * Fix `main` fallback * Try a different way of selecting `main` with fallback * Remove last `excludeNavigationFromSnapshot` * Use `.Navigation3000__scene` instead of `body` * Restore `overflow: visible` on navigation in tests * Fix top bar overlapping * More anti-clipping * Actually fix clipping * Fix `layout` parameter * Fix `.classList.add()` use * Remove empty `testOptions` * Tweak `waitForSelector` * Extend loader timeout * Update Surveys.stories.tsx * Update `UserPaths`'s `waitForSelector` * Print test errors * Revert "Print test errors" This reverts commit 71d305f8d3de872467e2a47504eb602fba2c77a3. * Capture whole scene in failure screenshot * Fix `CommandBar` snapshotting * Actually fix `CommandBar` snapshotting * Also fix modals * Force remount on snapshot retry * Actually fix modal, sidebar, and paths snapshotting * Fix observed flakiness * Remove legacy theme from visual tests * Update UI snapshots for `webkit` (2) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (2) * Fix sizing of `Toolbar` stories * Fix typing * Don't render zero-width funnel bar * Attempt to fix more flakiness * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (2) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (1) * Tweak selectors * Just hide the damn bar * Don't render grid layout without `gridWrapperWidth` * Use container query instead of React hook in `LemonBanner` * Update SavedInsights.stories.tsx * Explicitly size `LemonBanner` * Update Surveys.stories.tsx * Update UI snapshots for `chromium` (1) * Include navigation in side panel snapshots * Update UI snapshots for `chromium` (1) * Dispatch resize * Force settings sections in snapshots * Re-resize * Stabilize settings * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (2) * Update UI snapshots for `chromium` (2) --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
2024-03-18 10:51:46 +01:00
check = expectStoryToMatchSceneSnapshot
}
} else {
check = expectStoryToMatchComponentSnapshot
}
test(frontend): Improve reliability of visual regression tests (#14422) * test(frontend): Ensure 100% reliability of visual regression tests * Update UI snapshots for `chromium` (2) * Update UI snapshots for `chromium` (2) * Use OptiPNG in CI * Update UI snapshots for `chromium` (1) * Don't rely on pre-commit hook for image compression * Allow waiting for selector instead of constant delay * Update UI snapshots for `webkit` (2) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (2) * Update UI snapshots for `webkit` (2) * Add extra insight rendering conditions * Set strict timeouts for visual regression test jobs * Optimize OptiPNG step * Fix histogram selector * Update UI snapshots for `chromium` (2) * Update UI snapshots for `chromium` (2) * Ensure non-blank canvas * Fix blank canvas detection and auto-detect `waitForLoadersToDisappear` * Use `Spinner` for loading state in `MonacoEditor` * Make timeout limits less strict * Update UI snapshots for `chromium` (2) * Improve blank canvas detection further * Update UI snapshots for `webkit` (2) * Update UI snapshots for `chromium` (2) * Update UI snapshots for `chromium` (2) * Update UI snapshots for `webkit` (2) * Update UI snapshots for `webkit` (2) * Update UI snapshots for `chromium` (2) * Tune selectors * Update UI snapshots for `chromium` (2) * 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) * Try a different way of ensuring graphs are rendered * Update UI snapshots for `webkit` (2) * Increase `waitForLoadersToDisappear` initial UI wait * Update UI snapshots for `webkit` (2) * Make it easier to see what file wasn't pushed * Update UI snapshots for `chromium` (2) * Update UI snapshots for `chromium` (2) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (1) * Fix `timeout-minutes` * Update UI snapshots for `chromium` (2) * Update UI snapshots for `webkit` (2) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (1) * Add extra wait for canvases * Update UI snapshots for `chromium` (2) * Update UI snapshots for `chromium` (2) --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
2023-03-02 22:11:03 +01:00
await waitForPageReady(page)
test(vrt): Don't clip scene snapshots (#19677) * test(vrt): Don't clip scene snapshots * Upgrade Playwright to 1.33 * Replace `excludeNavigationFromSnapshot` with `includeNavigationInSnapshot` * Tune locator * Fix `EmptyStates` flakiness * Fix `main` fallback * Try a different way of selecting `main` with fallback * Remove last `excludeNavigationFromSnapshot` * Use `.Navigation3000__scene` instead of `body` * Restore `overflow: visible` on navigation in tests * Fix top bar overlapping * More anti-clipping * Actually fix clipping * Fix `layout` parameter * Fix `.classList.add()` use * Remove empty `testOptions` * Tweak `waitForSelector` * Extend loader timeout * Update Surveys.stories.tsx * Update `UserPaths`'s `waitForSelector` * Print test errors * Revert "Print test errors" This reverts commit 71d305f8d3de872467e2a47504eb602fba2c77a3. * Capture whole scene in failure screenshot * Fix `CommandBar` snapshotting * Actually fix `CommandBar` snapshotting * Also fix modals * Force remount on snapshot retry * Actually fix modal, sidebar, and paths snapshotting * Fix observed flakiness * Remove legacy theme from visual tests * Update UI snapshots for `webkit` (2) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (2) * Fix sizing of `Toolbar` stories * Fix typing * Don't render zero-width funnel bar * Attempt to fix more flakiness * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (2) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (1) * Tweak selectors * Just hide the damn bar * Don't render grid layout without `gridWrapperWidth` * Use container query instead of React hook in `LemonBanner` * Update SavedInsights.stories.tsx * Explicitly size `LemonBanner` * Update Surveys.stories.tsx * Update UI snapshots for `chromium` (1) * Include navigation in side panel snapshots * Update UI snapshots for `chromium` (1) * Dispatch resize * Force settings sections in snapshots * Re-resize * Stabilize settings * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (2) * Update UI snapshots for `chromium` (2) --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
2024-03-18 10:51:46 +01:00
await page.evaluate((layout: string) => {
// Stop all animations for consistent snapshots, and adjust other styles
document.body.classList.add('storybook-test-runner')
test(vrt): Don't clip scene snapshots (#19677) * test(vrt): Don't clip scene snapshots * Upgrade Playwright to 1.33 * Replace `excludeNavigationFromSnapshot` with `includeNavigationInSnapshot` * Tune locator * Fix `EmptyStates` flakiness * Fix `main` fallback * Try a different way of selecting `main` with fallback * Remove last `excludeNavigationFromSnapshot` * Use `.Navigation3000__scene` instead of `body` * Restore `overflow: visible` on navigation in tests * Fix top bar overlapping * More anti-clipping * Actually fix clipping * Fix `layout` parameter * Fix `.classList.add()` use * Remove empty `testOptions` * Tweak `waitForSelector` * Extend loader timeout * Update Surveys.stories.tsx * Update `UserPaths`'s `waitForSelector` * Print test errors * Revert "Print test errors" This reverts commit 71d305f8d3de872467e2a47504eb602fba2c77a3. * Capture whole scene in failure screenshot * Fix `CommandBar` snapshotting * Actually fix `CommandBar` snapshotting * Also fix modals * Force remount on snapshot retry * Actually fix modal, sidebar, and paths snapshotting * Fix observed flakiness * Remove legacy theme from visual tests * Update UI snapshots for `webkit` (2) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (2) * Fix sizing of `Toolbar` stories * Fix typing * Don't render zero-width funnel bar * Attempt to fix more flakiness * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (2) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (1) * Tweak selectors * Just hide the damn bar * Don't render grid layout without `gridWrapperWidth` * Use container query instead of React hook in `LemonBanner` * Update SavedInsights.stories.tsx * Explicitly size `LemonBanner` * Update Surveys.stories.tsx * Update UI snapshots for `chromium` (1) * Include navigation in side panel snapshots * Update UI snapshots for `chromium` (1) * Dispatch resize * Force settings sections in snapshots * Re-resize * Stabilize settings * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (2) * Update UI snapshots for `chromium` (2) --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
2024-03-18 10:51:46 +01:00
document.body.classList.add(`storybook-test-runner--${layout}`)
}, storyContext.parameters?.layout || 'padded')
if (waitForLoadersToDisappear) {
// The timeout is reduced so that we never allow toasts they usually signify something wrong
test(vrt): Don't clip scene snapshots (#19677) * test(vrt): Don't clip scene snapshots * Upgrade Playwright to 1.33 * Replace `excludeNavigationFromSnapshot` with `includeNavigationInSnapshot` * Tune locator * Fix `EmptyStates` flakiness * Fix `main` fallback * Try a different way of selecting `main` with fallback * Remove last `excludeNavigationFromSnapshot` * Use `.Navigation3000__scene` instead of `body` * Restore `overflow: visible` on navigation in tests * Fix top bar overlapping * More anti-clipping * Actually fix clipping * Fix `layout` parameter * Fix `.classList.add()` use * Remove empty `testOptions` * Tweak `waitForSelector` * Extend loader timeout * Update Surveys.stories.tsx * Update `UserPaths`'s `waitForSelector` * Print test errors * Revert "Print test errors" This reverts commit 71d305f8d3de872467e2a47504eb602fba2c77a3. * Capture whole scene in failure screenshot * Fix `CommandBar` snapshotting * Actually fix `CommandBar` snapshotting * Also fix modals * Force remount on snapshot retry * Actually fix modal, sidebar, and paths snapshotting * Fix observed flakiness * Remove legacy theme from visual tests * Update UI snapshots for `webkit` (2) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (2) * Fix sizing of `Toolbar` stories * Fix typing * Don't render zero-width funnel bar * Attempt to fix more flakiness * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (2) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (1) * Tweak selectors * Just hide the damn bar * Don't render grid layout without `gridWrapperWidth` * Use container query instead of React hook in `LemonBanner` * Update SavedInsights.stories.tsx * Explicitly size `LemonBanner` * Update Surveys.stories.tsx * Update UI snapshots for `chromium` (1) * Include navigation in side panel snapshots * Update UI snapshots for `chromium` (1) * Dispatch resize * Force settings sections in snapshots * Re-resize * Stabilize settings * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (2) * Update UI snapshots for `chromium` (2) --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
2024-03-18 10:51:46 +01:00
await page.waitForSelector(LOADER_SELECTORS.join(','), { state: 'detached', timeout: 3000 })
}
test(vrt): Don't clip scene snapshots (#19677) * test(vrt): Don't clip scene snapshots * Upgrade Playwright to 1.33 * Replace `excludeNavigationFromSnapshot` with `includeNavigationInSnapshot` * Tune locator * Fix `EmptyStates` flakiness * Fix `main` fallback * Try a different way of selecting `main` with fallback * Remove last `excludeNavigationFromSnapshot` * Use `.Navigation3000__scene` instead of `body` * Restore `overflow: visible` on navigation in tests * Fix top bar overlapping * More anti-clipping * Actually fix clipping * Fix `layout` parameter * Fix `.classList.add()` use * Remove empty `testOptions` * Tweak `waitForSelector` * Extend loader timeout * Update Surveys.stories.tsx * Update `UserPaths`'s `waitForSelector` * Print test errors * Revert "Print test errors" This reverts commit 71d305f8d3de872467e2a47504eb602fba2c77a3. * Capture whole scene in failure screenshot * Fix `CommandBar` snapshotting * Actually fix `CommandBar` snapshotting * Also fix modals * Force remount on snapshot retry * Actually fix modal, sidebar, and paths snapshotting * Fix observed flakiness * Remove legacy theme from visual tests * Update UI snapshots for `webkit` (2) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (2) * Fix sizing of `Toolbar` stories * Fix typing * Don't render zero-width funnel bar * Attempt to fix more flakiness * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (2) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (1) * Tweak selectors * Just hide the damn bar * Don't render grid layout without `gridWrapperWidth` * Use container query instead of React hook in `LemonBanner` * Update SavedInsights.stories.tsx * Explicitly size `LemonBanner` * Update Surveys.stories.tsx * Update UI snapshots for `chromium` (1) * Include navigation in side panel snapshots * Update UI snapshots for `chromium` (1) * Dispatch resize * Force settings sections in snapshots * Re-resize * Stabilize settings * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (2) * Update UI snapshots for `chromium` (2) --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
2024-03-18 10:51:46 +01:00
if (typeof waitForSelector === 'string') {
await page.waitForSelector(waitForSelector)
test(vrt): Don't clip scene snapshots (#19677) * test(vrt): Don't clip scene snapshots * Upgrade Playwright to 1.33 * Replace `excludeNavigationFromSnapshot` with `includeNavigationInSnapshot` * Tune locator * Fix `EmptyStates` flakiness * Fix `main` fallback * Try a different way of selecting `main` with fallback * Remove last `excludeNavigationFromSnapshot` * Use `.Navigation3000__scene` instead of `body` * Restore `overflow: visible` on navigation in tests * Fix top bar overlapping * More anti-clipping * Actually fix clipping * Fix `layout` parameter * Fix `.classList.add()` use * Remove empty `testOptions` * Tweak `waitForSelector` * Extend loader timeout * Update Surveys.stories.tsx * Update `UserPaths`'s `waitForSelector` * Print test errors * Revert "Print test errors" This reverts commit 71d305f8d3de872467e2a47504eb602fba2c77a3. * Capture whole scene in failure screenshot * Fix `CommandBar` snapshotting * Actually fix `CommandBar` snapshotting * Also fix modals * Force remount on snapshot retry * Actually fix modal, sidebar, and paths snapshotting * Fix observed flakiness * Remove legacy theme from visual tests * Update UI snapshots for `webkit` (2) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (2) * Fix sizing of `Toolbar` stories * Fix typing * Don't render zero-width funnel bar * Attempt to fix more flakiness * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (2) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (1) * Tweak selectors * Just hide the damn bar * Don't render grid layout without `gridWrapperWidth` * Use container query instead of React hook in `LemonBanner` * Update SavedInsights.stories.tsx * Explicitly size `LemonBanner` * Update Surveys.stories.tsx * Update UI snapshots for `chromium` (1) * Include navigation in side panel snapshots * Update UI snapshots for `chromium` (1) * Dispatch resize * Force settings sections in snapshots * Re-resize * Stabilize settings * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (2) * Update UI snapshots for `chromium` (2) --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
2024-03-18 10:51:46 +01:00
} else if (Array.isArray(waitForSelector)) {
await Promise.all(waitForSelector.map((selector) => page.waitForSelector(selector)))
}
// Snapshot light theme
2023-12-22 12:38:21 +01:00
await page.evaluate(() => {
document.body.setAttribute('theme', 'light')
})
await waitForPageReady(page)
await page.waitForFunction(() => Array.from(document.images).every((i: HTMLImageElement) => !!i.naturalWidth))
await page.waitForTimeout(2000)
2023-12-22 12:38:21 +01:00
await check(page, context, browser, 'light', storyContext.parameters?.testOptions?.snapshotTargetSelector)
// Snapshot dark theme
2023-12-22 12:38:21 +01:00
await page.evaluate(() => {
document.body.setAttribute('theme', 'dark')
})
await waitForPageReady(page)
await page.waitForFunction(() => Array.from(document.images).every((i: HTMLImageElement) => !!i.naturalWidth))
await page.waitForTimeout(100)
2023-12-22 12:38:21 +01:00
await check(page, context, browser, 'dark', storyContext.parameters?.testOptions?.snapshotTargetSelector)
}
test(vrt): Don't clip scene snapshots (#19677) * test(vrt): Don't clip scene snapshots * Upgrade Playwright to 1.33 * Replace `excludeNavigationFromSnapshot` with `includeNavigationInSnapshot` * Tune locator * Fix `EmptyStates` flakiness * Fix `main` fallback * Try a different way of selecting `main` with fallback * Remove last `excludeNavigationFromSnapshot` * Use `.Navigation3000__scene` instead of `body` * Restore `overflow: visible` on navigation in tests * Fix top bar overlapping * More anti-clipping * Actually fix clipping * Fix `layout` parameter * Fix `.classList.add()` use * Remove empty `testOptions` * Tweak `waitForSelector` * Extend loader timeout * Update Surveys.stories.tsx * Update `UserPaths`'s `waitForSelector` * Print test errors * Revert "Print test errors" This reverts commit 71d305f8d3de872467e2a47504eb602fba2c77a3. * Capture whole scene in failure screenshot * Fix `CommandBar` snapshotting * Actually fix `CommandBar` snapshotting * Also fix modals * Force remount on snapshot retry * Actually fix modal, sidebar, and paths snapshotting * Fix observed flakiness * Remove legacy theme from visual tests * Update UI snapshots for `webkit` (2) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (2) * Fix sizing of `Toolbar` stories * Fix typing * Don't render zero-width funnel bar * Attempt to fix more flakiness * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (2) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (1) * Tweak selectors * Just hide the damn bar * Don't render grid layout without `gridWrapperWidth` * Use container query instead of React hook in `LemonBanner` * Update SavedInsights.stories.tsx * Explicitly size `LemonBanner` * Update Surveys.stories.tsx * Update UI snapshots for `chromium` (1) * Include navigation in side panel snapshots * Update UI snapshots for `chromium` (1) * Dispatch resize * Force settings sections in snapshots * Re-resize * Stabilize settings * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (2) * Update UI snapshots for `chromium` (2) --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
2024-03-18 10:51:46 +01:00
async function expectStoryToMatchViewportSnapshot(
page: Page,
context: TestContext,
browser: SupportedBrowserName,
theme: SnapshotTheme
): Promise<void> {
await expectLocatorToMatchStorySnapshot(page, context, browser, theme)
}
async function expectStoryToMatchSceneSnapshot(
page: Page,
context: TestContext,
browser: SupportedBrowserName,
theme: SnapshotTheme
): Promise<void> {
test(vrt): Don't clip scene snapshots (#19677) * test(vrt): Don't clip scene snapshots * Upgrade Playwright to 1.33 * Replace `excludeNavigationFromSnapshot` with `includeNavigationInSnapshot` * Tune locator * Fix `EmptyStates` flakiness * Fix `main` fallback * Try a different way of selecting `main` with fallback * Remove last `excludeNavigationFromSnapshot` * Use `.Navigation3000__scene` instead of `body` * Restore `overflow: visible` on navigation in tests * Fix top bar overlapping * More anti-clipping * Actually fix clipping * Fix `layout` parameter * Fix `.classList.add()` use * Remove empty `testOptions` * Tweak `waitForSelector` * Extend loader timeout * Update Surveys.stories.tsx * Update `UserPaths`'s `waitForSelector` * Print test errors * Revert "Print test errors" This reverts commit 71d305f8d3de872467e2a47504eb602fba2c77a3. * Capture whole scene in failure screenshot * Fix `CommandBar` snapshotting * Actually fix `CommandBar` snapshotting * Also fix modals * Force remount on snapshot retry * Actually fix modal, sidebar, and paths snapshotting * Fix observed flakiness * Remove legacy theme from visual tests * Update UI snapshots for `webkit` (2) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (2) * Fix sizing of `Toolbar` stories * Fix typing * Don't render zero-width funnel bar * Attempt to fix more flakiness * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (2) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (1) * Tweak selectors * Just hide the damn bar * Don't render grid layout without `gridWrapperWidth` * Use container query instead of React hook in `LemonBanner` * Update SavedInsights.stories.tsx * Explicitly size `LemonBanner` * Update Surveys.stories.tsx * Update UI snapshots for `chromium` (1) * Include navigation in side panel snapshots * Update UI snapshots for `chromium` (1) * Dispatch resize * Force settings sections in snapshots * Re-resize * Stabilize settings * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (2) * Update UI snapshots for `chromium` (2) --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
2024-03-18 10:51:46 +01:00
// If the `main` element isn't present, let's use `body` - this is needed in logged-out screens.
// We use .last(), because the order of selector matches is based on the order of elements in the DOM,
// and not the order of the selectors in the query.
await expectLocatorToMatchStorySnapshot(page.locator('body, main').last(), context, browser, theme)
}
async function expectStoryToMatchComponentSnapshot(
page: Page,
context: TestContext,
browser: SupportedBrowserName,
theme: SnapshotTheme,
targetSelector: string = '#storybook-root'
): Promise<void> {
test(vrt): Don't clip scene snapshots (#19677) * test(vrt): Don't clip scene snapshots * Upgrade Playwright to 1.33 * Replace `excludeNavigationFromSnapshot` with `includeNavigationInSnapshot` * Tune locator * Fix `EmptyStates` flakiness * Fix `main` fallback * Try a different way of selecting `main` with fallback * Remove last `excludeNavigationFromSnapshot` * Use `.Navigation3000__scene` instead of `body` * Restore `overflow: visible` on navigation in tests * Fix top bar overlapping * More anti-clipping * Actually fix clipping * Fix `layout` parameter * Fix `.classList.add()` use * Remove empty `testOptions` * Tweak `waitForSelector` * Extend loader timeout * Update Surveys.stories.tsx * Update `UserPaths`'s `waitForSelector` * Print test errors * Revert "Print test errors" This reverts commit 71d305f8d3de872467e2a47504eb602fba2c77a3. * Capture whole scene in failure screenshot * Fix `CommandBar` snapshotting * Actually fix `CommandBar` snapshotting * Also fix modals * Force remount on snapshot retry * Actually fix modal, sidebar, and paths snapshotting * Fix observed flakiness * Remove legacy theme from visual tests * Update UI snapshots for `webkit` (2) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (2) * Fix sizing of `Toolbar` stories * Fix typing * Don't render zero-width funnel bar * Attempt to fix more flakiness * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (2) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (1) * Tweak selectors * Just hide the damn bar * Don't render grid layout without `gridWrapperWidth` * Use container query instead of React hook in `LemonBanner` * Update SavedInsights.stories.tsx * Explicitly size `LemonBanner` * Update Surveys.stories.tsx * Update UI snapshots for `chromium` (1) * Include navigation in side panel snapshots * Update UI snapshots for `chromium` (1) * Dispatch resize * Force settings sections in snapshots * Re-resize * Stabilize settings * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (2) * Update UI snapshots for `chromium` (2) --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
2024-03-18 10:51:46 +01:00
await page.evaluate(() => {
const rootEl = document.getElementById('storybook-root')
if (!rootEl) {
throw new Error('Could not find root element')
}
// If needed, expand the root element so that all popovers are visible in the screenshot
document.querySelectorAll('.Popover').forEach((popover) => {
const currentRootBoundingClientRect = rootEl.getBoundingClientRect()
const popoverBoundingClientRect = popover.getBoundingClientRect()
if (popoverBoundingClientRect.right > currentRootBoundingClientRect.right) {
rootEl.style.width = `${popoverBoundingClientRect.right}px`
}
if (popoverBoundingClientRect.bottom > currentRootBoundingClientRect.bottom) {
rootEl.style.height = `${popoverBoundingClientRect.bottom}px`
}
if (popoverBoundingClientRect.top < currentRootBoundingClientRect.top) {
rootEl.style.height = `${-popoverBoundingClientRect.top + currentRootBoundingClientRect.bottom}px`
}
if (popoverBoundingClientRect.left < currentRootBoundingClientRect.left) {
rootEl.style.width = `${-popoverBoundingClientRect.left + currentRootBoundingClientRect.right}px`
}
})
test(vrt): Don't clip scene snapshots (#19677) * test(vrt): Don't clip scene snapshots * Upgrade Playwright to 1.33 * Replace `excludeNavigationFromSnapshot` with `includeNavigationInSnapshot` * Tune locator * Fix `EmptyStates` flakiness * Fix `main` fallback * Try a different way of selecting `main` with fallback * Remove last `excludeNavigationFromSnapshot` * Use `.Navigation3000__scene` instead of `body` * Restore `overflow: visible` on navigation in tests * Fix top bar overlapping * More anti-clipping * Actually fix clipping * Fix `layout` parameter * Fix `.classList.add()` use * Remove empty `testOptions` * Tweak `waitForSelector` * Extend loader timeout * Update Surveys.stories.tsx * Update `UserPaths`'s `waitForSelector` * Print test errors * Revert "Print test errors" This reverts commit 71d305f8d3de872467e2a47504eb602fba2c77a3. * Capture whole scene in failure screenshot * Fix `CommandBar` snapshotting * Actually fix `CommandBar` snapshotting * Also fix modals * Force remount on snapshot retry * Actually fix modal, sidebar, and paths snapshotting * Fix observed flakiness * Remove legacy theme from visual tests * Update UI snapshots for `webkit` (2) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (2) * Fix sizing of `Toolbar` stories * Fix typing * Don't render zero-width funnel bar * Attempt to fix more flakiness * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (2) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (1) * Tweak selectors * Just hide the damn bar * Don't render grid layout without `gridWrapperWidth` * Use container query instead of React hook in `LemonBanner` * Update SavedInsights.stories.tsx * Explicitly size `LemonBanner` * Update Surveys.stories.tsx * Update UI snapshots for `chromium` (1) * Include navigation in side panel snapshots * Update UI snapshots for `chromium` (1) * Dispatch resize * Force settings sections in snapshots * Re-resize * Stabilize settings * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (2) * Update UI snapshots for `chromium` (2) --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
2024-03-18 10:51:46 +01:00
})
await expectLocatorToMatchStorySnapshot(page.locator(targetSelector), context, browser, theme, {
omitBackground: true,
})
}
async function expectLocatorToMatchStorySnapshot(
locator: Locator | Page,
context: TestContext,
browser: SupportedBrowserName,
theme: SnapshotTheme,
options?: LocatorScreenshotOptions
): Promise<void> {
const image = await locator.screenshot({ ...options })
test(vrt): Don't clip scene snapshots (#19677) * test(vrt): Don't clip scene snapshots * Upgrade Playwright to 1.33 * Replace `excludeNavigationFromSnapshot` with `includeNavigationInSnapshot` * Tune locator * Fix `EmptyStates` flakiness * Fix `main` fallback * Try a different way of selecting `main` with fallback * Remove last `excludeNavigationFromSnapshot` * Use `.Navigation3000__scene` instead of `body` * Restore `overflow: visible` on navigation in tests * Fix top bar overlapping * More anti-clipping * Actually fix clipping * Fix `layout` parameter * Fix `.classList.add()` use * Remove empty `testOptions` * Tweak `waitForSelector` * Extend loader timeout * Update Surveys.stories.tsx * Update `UserPaths`'s `waitForSelector` * Print test errors * Revert "Print test errors" This reverts commit 71d305f8d3de872467e2a47504eb602fba2c77a3. * Capture whole scene in failure screenshot * Fix `CommandBar` snapshotting * Actually fix `CommandBar` snapshotting * Also fix modals * Force remount on snapshot retry * Actually fix modal, sidebar, and paths snapshotting * Fix observed flakiness * Remove legacy theme from visual tests * Update UI snapshots for `webkit` (2) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (2) * Fix sizing of `Toolbar` stories * Fix typing * Don't render zero-width funnel bar * Attempt to fix more flakiness * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (2) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (1) * Tweak selectors * Just hide the damn bar * Don't render grid layout without `gridWrapperWidth` * Use container query instead of React hook in `LemonBanner` * Update SavedInsights.stories.tsx * Explicitly size `LemonBanner` * Update Surveys.stories.tsx * Update UI snapshots for `chromium` (1) * Include navigation in side panel snapshots * Update UI snapshots for `chromium` (1) * Dispatch resize * Force settings sections in snapshots * Re-resize * Stabilize settings * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (2) * Update UI snapshots for `chromium` (2) --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
2024-03-18 10:51:46 +01:00
let customSnapshotIdentifier = `${context.id}--${theme}`
if (browser !== 'chromium') {
customSnapshotIdentifier += `--${browser}`
}
expect(image).toMatchImageSnapshot({
customSnapshotsDir,
customSnapshotIdentifier,
// Compare structural similarity instead of raw pixels - reducing false positives
// See https://github.com/americanexpress/jest-image-snapshot#recommendations-when-using-ssim-comparison
comparisonMethod: 'ssim',
// 0.01 would be a 1% difference
failureThreshold: 0.01,
failureThresholdType: 'percent',
})
}
/**
* Just like the `waitForPageReady` helper offered by Playwright - except we only wait for `networkidle` in CI,
* as it doesn't work with local Storybook (the live reload feature keeps up a long-running request, so we aren't idle).
*/
async function waitForPageReady(page: Page): Promise<void> {
await page.waitForLoadState('domcontentloaded')
await page.waitForLoadState('load')
if (process.env.CI) {
await page.waitForLoadState('networkidle')
}
await page.evaluate(() => document.fonts.ready)
}