Skip to content

SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.

fix(storybook): remove timing races from story tests (#12954)

Vinicius Lourençof9d425bf5cb5
diff --git a/frontend/.storybook/preview.tsx b/frontend/.storybook/preview.tsx
index 8dffd0b724..2251118e46 100644
--- a/frontend/.storybook/preview.tsx
+++ b/frontend/.storybook/preview.tsx
@@ -1,6 +1,7 @@
import type { Preview } from '@storybook/react-vite';
import type { SetupWorker } from 'msw';
import { setupWorker } from 'msw';
+import { configure } from 'storybook/test';
import { settleForCapture } from '../src/storybook/visual/settleForCapture';
import PageDocs from '../src/storybook/docs/PageDocs';
@@ -83,6 +84,10 @@ const translationsReady = i18n.loadNamespaces(
),
);
+// testing-library's 1s default for `findBy*` and `waitFor` is shorter than a
+// popup or a query takes to land on a loaded CI runner.
+configure({ asyncUtilTimeout: 10_000 });
+
const preview: Preview = {
parameters: {
layout: 'fullscreen',
diff --git a/frontend/.storybook/test-runner.ts b/frontend/.storybook/test-runner.ts
index 1bc435dda2..f055b855a6 100644
--- a/frontend/.storybook/test-runner.ts
+++ b/frontend/.storybook/test-runner.ts
@@ -30,6 +30,8 @@ interface CapturedMessage {
text: string;
}
+const PREPARE_TIMEOUT_MS = 180_000;
+
const messagesByPage = new WeakMap<Page, CapturedMessage[]>();
/**
@@ -52,6 +54,15 @@ const config: TestRunnerConfig = {
// msw logs every mocked request at `log`; keep it out of the failure dump
// unless the job is re-run with debug logging (GitHub sets RUNNER_DEBUG=1).
logLevel: process.env.RUNNER_DEBUG === '1' ? 'info' : 'warn',
+ // The runner's default prepare, minus Playwright's 30s navigation timeout: on
+ // a cold dev server the first load compiles the whole preview, which outlasts
+ // it on a shared CI runner.
+ async prepare({ page }): Promise<void> {
+ await page.goto(new URL('iframe.html', process.env.TARGET_URL).toString(), {
+ waitUntil: 'load',
+ timeout: PREPARE_TIMEOUT_MS,
+ });
+ },
async preVisit(page): Promise<void> {
const existing = messagesByPage.get(page);
if (existing) {
diff --git a/frontend/src/pages/DashboardPage/PanelEditorPage/stories/PanelEditorPage.stories.tsx b/frontend/src/pages/DashboardPage/PanelEditorPage/stories/PanelEditorPage.stories.tsx
index 44675723ab..d3ad6ed511 100644
--- a/frontend/src/pages/DashboardPage/PanelEditorPage/stories/PanelEditorPage.stories.tsx
+++ b/frontend/src/pages/DashboardPage/PanelEditorPage/stories/PanelEditorPage.stories.tsx
@@ -67,6 +67,8 @@ export const NoPreviewData: Story = {
/** The editor remains usable while the independently fetched preview has failed. */
export const PreviewQueryError: Story = {
args: { dataState: 'error' },
+ // The mocked queries deliberately fail; the resulting console errors are the state under test.
+ parameters: { allowConsoleErrors: true },
};
/** A locked dashboard: the editor still opens, but it cannot save. */
diff --git a/frontend/src/pages/DashboardPage/stories/DashboardPage.stories.tsx b/frontend/src/pages/DashboardPage/stories/DashboardPage.stories.tsx
index 6a9750f32f..aef57cf7c8 100644
--- a/frontend/src/pages/DashboardPage/stories/DashboardPage.stories.tsx
+++ b/frontend/src/pages/DashboardPage/stories/DashboardPage.stories.tsx
@@ -91,6 +91,8 @@ export const NoData: Story = {
/** A partial data failure: the dashboard remains visible while panel queries fail. */
export const PanelQueryError: Story = {
args: { dataState: 'error' },
+ // The mocked queries deliberately fail; the resulting console errors are the state under test.
+ parameters: { allowConsoleErrors: true },
};
/** The panels mid-fetch, with the header, variable bar and grid already laid out. */
diff --git a/frontend/src/pages/MessagingQueues/stories/MessagingQueues.stories.tsx b/frontend/src/pages/MessagingQueues/stories/MessagingQueues.stories.tsx
index 6bae7eea59..18b09b16f6 100644
--- a/frontend/src/pages/MessagingQueues/stories/MessagingQueues.stories.tsx
+++ b/frontend/src/pages/MessagingQueues/stories/MessagingQueues.stories.tsx
@@ -1,5 +1,5 @@
import type { Meta, StoryObj } from '@storybook/react-vite';
-import { screen, userEvent, within } from 'storybook/test';
+import { expect, screen, userEvent, waitFor, within } from 'storybook/test';
import { storyMocks } from '@/storybook/controls/defineStoryMocks';
import type { PageStoryArgs } from '@/storybook/runtime/resolveStory';
@@ -56,13 +56,18 @@ export const ConfigurationChecklist: Story = {
// The button reads plain "Configuration" while the checks are in flight and
// ignores clicks until they land, so the count is what to wait on.
- await userEvent.click(
- await canvas.findByRole(
- 'button',
- { name: /missing configuration/i },
- untilLoaded,
- ),
+ const button = await canvas.findByRole(
+ 'button',
+ { name: /missing configuration/i },
+ untilLoaded,
+ );
+ // The count shows once any one check lands; the button stays loading, and
+ // ignores clicks, until all three have.
+ await waitFor(
+ () => expect(button).not.toHaveClass('ant-btn-loading'),
+ untilLoaded,
);
+ await userEvent.click(button);
// The modal header and its title both carry the text.
await screen.findAllByText(
'Kafka Service Attributes',
diff --git a/frontend/src/pages/Settings/Billing/stories/Billing.stories.tsx b/frontend/src/pages/Settings/Billing/stories/Billing.stories.tsx
index 0b9a8ddb42..7902e07943 100644
--- a/frontend/src/pages/Settings/Billing/stories/Billing.stories.tsx
+++ b/frontend/src/pages/Settings/Billing/stories/Billing.stories.tsx
@@ -170,4 +170,6 @@ export const Loading: Story = {
/** Error: the usage request failed, leaving the plan card with nothing to report. */
export const Error: Story = {
args: { dataState: 'error' },
+ // The mocked usage request deliberately fails; the resulting console errors are the state under test.
+ parameters: { allowConsoleErrors: true },
};
diff --git a/frontend/src/pages/Settings/ServiceAccounts/stories/ServiceAccounts.stories.tsx b/frontend/src/pages/Settings/ServiceAccounts/stories/ServiceAccounts.stories.tsx
index ec58819ada..6688f5fcbd 100644
--- a/frontend/src/pages/Settings/ServiceAccounts/stories/ServiceAccounts.stories.tsx
+++ b/frontend/src/pages/Settings/ServiceAccounts/stories/ServiceAccounts.stories.tsx
@@ -106,7 +106,11 @@ export const SearchNoResults: Story = {
/** Error: the list request failed while the rest of the settings shell stays usable. */
export const LoadError: Story = {
- parameters: { msw: { handlers: [accountsLoadError] } },
+ // The deliberate 500 is the state under test.
+ parameters: {
+ msw: { handlers: [accountsLoadError] },
+ allowConsoleErrors: true,
+ },
};
/** An account opened up: the name and the roles it acts under. */
diff --git a/frontend/src/storybook/foundations/Layering.stories.tsx b/frontend/src/storybook/foundations/Layering.stories.tsx
index e58f47a17b..88497ed335 100644
--- a/frontend/src/storybook/foundations/Layering.stories.tsx
+++ b/frontend/src/storybook/foundations/Layering.stories.tsx
@@ -1,12 +1,5 @@
import type { Meta, StoryObj } from '@storybook/react-vite';
-import {
- expect,
- screen,
- userEvent,
- waitFor,
- waitForElementToBeRemoved,
- within,
-} from 'storybook/test';
+import { expect, screen, userEvent, waitFor, within } from 'storybook/test';
import LayeringFixture from './LayeringFixture';
@@ -53,7 +46,9 @@ export const SelectOverDrawer: Story = {
const drawer = await screen.findByRole('dialog', { name: 'Layering drawer' });
await userEvent.keyboard('{Escape}');
- await waitForElementToBeRemoved(drawer);
+ // The close can finish before this runs, which `waitForElementToBeRemoved`
+ // rejects instead of passing.
+ await waitFor(() => expect(drawer).not.toBeInTheDocument());
await userEvent.click(trigger);
await userEvent.click(
await screen.findByRole('combobox', { name: 'Drawer environment' }),