Skip to content

: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.

fix(storybook): add waitForSelectorTimeout to fix AccountsTab VR flake (#70144)

mendral-app[bot]9062857daba2
diff --git a/common/storybook/.storybook/test-runner.ts b/common/storybook/.storybook/test-runner.ts
index 7d4438f5731f..519ef1041cdc 100644
--- a/common/storybook/.storybook/test-runner.ts
+++ b/common/storybook/.storybook/test-runner.ts
@@ -39,6 +39,8 @@ declare module 'storybook/internal/types' {
waitForLoadersToDisappear?: boolean
/** If set, we'll wait for the given selector (or all selectors, if multiple) to be satisfied. */
waitForSelector?: string | string[]
+ /** Timeout in ms for waitForSelector. Defaults to Playwright's context timeout (PLAYWRIGHT_TIMEOUT_MS). */
+ waitForSelectorTimeout?: number
/**
* By default we wait for images to have width as an indication the page is ready for screenshot testing
* Some stories have broken images on purpose to test what the UI does
@@ -275,7 +277,8 @@ async function expectStoryToMatchSnapshot(
// Allow ResizeObserver callbacks to fire and React to re-render with updated dimensions
await page.waitForTimeout(300)
- const { waitForLoadersToDisappear = true, waitForSelector } = storyContext.parameters?.testOptions ?? {}
+ const { waitForLoadersToDisappear = true, waitForSelector, waitForSelectorTimeout } =
+ storyContext.parameters?.testOptions ?? {}
if (waitForLoadersToDisappear) {
// The timeout allows loaders and toasts to disappear - toasts usually signify something wrong
@@ -287,9 +290,11 @@ async function expectStoryToMatchSnapshot(
}
if (typeof waitForSelector === 'string') {
- await page.waitForSelector(waitForSelector)
+ await page.waitForSelector(waitForSelector, { timeout: waitForSelectorTimeout })
} else if (Array.isArray(waitForSelector)) {
- await Promise.all(waitForSelector.map((selector) => page.waitForSelector(selector)))
+ await Promise.all(
+ waitForSelector.map((selector) => page.waitForSelector(selector, { timeout: waitForSelectorTimeout }))
+ )
}
// Snapshot both light and dark themes
diff --git a/products/customer_analytics/frontend/components/Accounts/AccountsTab.stories.tsx b/products/customer_analytics/frontend/components/Accounts/AccountsTab.stories.tsx
index 4173d7504a7e..c08965639bfe 100644
--- a/products/customer_analytics/frontend/components/Accounts/AccountsTab.stories.tsx
+++ b/products/customer_analytics/frontend/components/Accounts/AccountsTab.stories.tsx
@@ -206,6 +206,7 @@ async function expandAndOpenTab(canvasElement: HTMLElement, tab: 'Usage' | 'Spen
// expanded-row content turns a lost expansion into a retry instead of a flaky collapsed capture.
const EXPANDED_ROW_TEST_OPTIONS = {
waitForSelector: ['[data-attr="accounts-refresh"]', '[data-attr="account-expansion"]'],
+ waitForSelectorTimeout: 30000,
}
function mockAccountsQuery(rows: AccountRow[]): (info: MockResolverInfo) => Promise<[number, unknown] | undefined> {
@@ -383,6 +384,7 @@ export const RowExpandedUsageNotFound: Story = {
render: () => <App />,
parameters: {
testOptions: {
+ ...EXPANDED_ROW_TEST_OPTIONS,
waitForSelector: ['[data-attr="accounts-refresh"]', '[data-attr="account-billing-insight-not-found"]'],
},
},
@@ -396,9 +398,7 @@ export const RowExpandedUsageNotFound: Story = {
export const RowExpandedUsagePopulated: Story = {
render: () => <App />,
parameters: {
- testOptions: {
- waitForSelector: ['[data-attr="accounts-refresh"]', '[data-attr="account-expansion"]'],
- },
+ testOptions: EXPANDED_ROW_TEST_OPTIONS,
},
decorators: billingTabDecorators(
insightsResponse(USAGE_INSIGHT),