Skip to content

Maintenance: Add assertions outside step incorrectly nested in interactions panel#34296

Merged
valentinpalkovic merged 2 commits into
storybookjs:nextfrom
majiayu000:fix/issue-19401-step-waitfor-nesting
Mar 27, 2026
Merged

Maintenance: Add assertions outside step incorrectly nested in interactions panel#34296
valentinpalkovic merged 2 commits into
storybookjs:nextfrom
majiayu000:fix/issue-19401-step-waitfor-nesting

Conversation

@majiayu000
Copy link
Copy Markdown
Contributor

@majiayu000 majiayu000 commented Mar 24, 2026

Closes #19401

What I did

Added regression tests for the step/waitFor nesting bug in the interactions panel. When a play function uses await step('name', callback) followed by await waitFor(() => expect(...)), assertions inside waitFor could appear nested under the collapsed step instead of under waitFor.

After investigation, the significant code restructuring (moving instrumenter from addons/interactions to code/core, refactoring the instrumenter) appears to have fixed the underlying bug. The instrumenter now correctly restores the ancestors state after async step callbacks complete, so waitFor calls that follow a step no longer inherit the step's call ID in their ancestors.

These tests serve as regression guards to ensure the fix stays in place:

  • instrumenter.test.ts: Two new tests verifying that calls inside waitFor after a step have correct ancestors (only waitFor ID, not step ID), including retry scenarios.
  • Panel.test.ts: New test verifying that collapsing a step in the interactions panel does not hide subsequent waitFor calls and their children.

Checklist for Contributors

Testing

The changes in this PR are covered in the following automated tests:

  • stories
  • unit tests
  • integration tests
  • end-to-end tests

Manual testing

No manual testing required — this PR only adds regression tests. The tests verify correct behavior by asserting on the ancestors array of instrumented calls and on the isHidden state of panel rows.

Documentation

  • Add or update documentation reflecting your changes
  • If you are deprecating/removing a feature, make sure to update
    MIGRATION.MD

Checklist for Maintainers

  • When this PR is ready for testing, make sure to add ci:normal, ci:merged or ci:daily GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found in code/lib/cli-storybook/src/sandbox-templates.ts

  • Make sure this PR contains one of the labels below:

    Available labels
    • bug: Internal changes that fixes incorrect behavior.
    • maintenance: User-facing maintenance tasks.
    • dependencies: Upgrading (sometimes downgrading) dependencies.
    • build: Internal-facing build tooling & test updates. Will not show up in release changelog.
    • cleanup: Minor cleanup style change. Will not show up in release changelog.
    • documentation: Documentation only changes. Will not show up in release changelog.
    • feature request: Introducing a new feature.
    • BREAKING CHANGE: Changes that break compatibility in some way with current major version.
    • other: Changes that don't fit in the above categories.

🦋 Canary release

This PR does not have a canary release associated. You can request a canary release of this pull request by mentioning the @storybookjs/core team here.

core team members can create a canary release here or locally with gh workflow run --repo storybookjs/storybook publish.yml --field pr=<PR_NUMBER>

Summary by CodeRabbit

  • Tests
    • Added test coverage for interaction hiding behavior when collapsing steps in component testing.
    • Added test coverage for call nesting behavior with the intercept option in the instrumenter.

…anel

The bug where assertions outside of a Step appeared nested inside the Step
(storybookjs#19401) has been resolved by the core restructuring. Add regression tests
to guard against the issue recurring:

- Instrumenter test: verify calls after an interceptable async step have
  correct ancestors (not nested under the step)
- Panel test: verify collapsing a step does not hide subsequent waitFor
  and its children

Signed-off-by: majiayu000 <1835304752@qq.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 24, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b80d185d-072d-43f6-bfdc-09e52f4116a2

📥 Commits

Reviewing files that changed from the base of the PR and between 33afce2 and d78e2d5.

📒 Files selected for processing (2)
  • code/core/src/component-testing/components/Panel.test.ts
  • code/core/src/instrumenter/instrumenter.test.ts

📝 Walkthrough

Walkthrough

Two test cases are added to verify interaction handling behavior: one for collapse interactions hiding only direct child steps, and another for ensuring calls after an interceptable step are not nested within that step's context.

Changes

Cohort / File(s) Summary
Test Coverage for Interaction Collapse
code/core/src/component-testing/components/Panel.test.ts
New test case validates that collapsing a step call hides only its direct child interactions while unrelated waitFor calls and their descendants remain visible.
Test Coverage for Intercept Behavior
code/core/src/instrumenter/instrumenter.test.ts
New test case verifies that when using { intercept: true }, calls made after an interceptable step are not nested within that step's execution context, with proper ancestor tracking.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@storybook-app-bot
Copy link
Copy Markdown

storybook-app-bot Bot commented Mar 27, 2026

Package Benchmarks

Commit: 81ac5b2, ran on 27 March 2026 at 12:30:46 UTC

No significant changes detected, all good. 👏

@valentinpalkovic valentinpalkovic changed the title fix: assertions outside step incorrectly nested in interactions panel Maintenance: Add assertions outside step incorrectly nested in interactions panel Mar 27, 2026
@valentinpalkovic valentinpalkovic merged commit 5017de7 into storybookjs:next Mar 27, 2026
112 of 114 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Core Team Projects Mar 27, 2026
@github-actions github-actions Bot mentioned this pull request Mar 27, 2026
18 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

addon: actions ci:normal maintenance User-facing maintenance tasks

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Addon-interactions: assertion outside of Step appears as if it was inside of Step

2 participants