Skip to content

Conversation

@kylegach
Copy link
Contributor

@kylegach kylegach commented Jul 31, 2025

Continues #32128

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.

Greptile Summary

This PR continues the documentation work from #32128 by adding comprehensive documentation for Storybook's new automocking feature introduced in version 9.1. The changes include:

New Documentation Snippets:

  • automock-register-spy.md: Examples showing spy-only mocking with sb.mock({ spy: true })
  • automock-register-full.md: Examples of fully automocked modules using sb.mock()
  • automock-register-mock-file.md: Examples of mock file registration that redirects imports to __mocks__ directories
  • automocked-modules-in-story.md: Multi-framework examples showing how to use the mocked utility in stories with beforeEach hooks and play functions

Major Documentation Update:

  • mocking-modules.mdx: Complete restructuring to position automocking as the primary recommended approach, with detailed technical explanations of build-time analysis, Vite plugin integration, and comparisons to Vitest mocking

The automocking feature leverages the sb.mock() utility to simplify module mocking through three approaches: spy-only (recommended), fully automocked, and mock files. This represents a significant improvement over previous manual mocking methods by providing build-time module analysis and seamless integration with Vite/Webpack builders. The documentation follows Storybook's standards with framework-agnostic examples supporting both TypeScript and JavaScript users across Angular, React, Vue, Svelte, and Web Components.

Confidence score: 4/5

  • This is a documentation-only PR that significantly improves user guidance for a major new feature
  • The content is technically sound and follows established Storybook documentation patterns
  • There are minor inconsistencies in the mocked utility usage patterns between TypeScript/JavaScript examples that could cause confusion
  • Some files need attention for filename reference consistency and potential clarity improvements around the mocked wrapper usage

Context used:

Context - When documenting code snippets, ensure to include Svelte CSF and CSF examples, and also include JS and TypeScript variants. (link)

@kylegach kylegach self-assigned this Jul 31, 2025
@kylegach kylegach requested a review from jonniebigodes as a code owner July 31, 2025 16:50
@kylegach kylegach added patch:yes Bugfix & documentation PR that need to be picked to main branch ci:docs Run the CI jobs for documentation checks only. labels Jul 31, 2025
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5 files reviewed, 7 comments

Edit Code Review Bot Settings | Greptile

@nx-cloud
Copy link

nx-cloud bot commented Jul 31, 2025

View your CI Pipeline Execution ↗ for commit f148fae

Command Status Duration Result
nx run-many -t build --parallel=3 ✅ Succeeded 1m 13s View ↗

☁️ Nx Cloud last updated this comment at 2025-08-01 16:50:32 UTC

Copy link
Contributor

@jonniebigodes jonniebigodes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some items for you to look into when you can. Approving to unblock you.

sb.mock('../lib/session.ts', { spy: true });
// 👇 Automatically spies on all exports from the `uuid` package in `node_modules`
sb.mock('uuid', { spy: true });
<CodeSnippets path="automock-register-spy.md" />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kylegach any particular reason why we're not wrapping the snippets with {/* prettier-ignore-start */} and {/* prettier-ignore-end */}?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's unnecessary after we switched the site to Next.js.

```

```js filename="AuthButton.stories.js" renderer="common" language="js"
import { expect } from 'storybook/test';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kylegach, the JS variants are not similar to the TS variants. There's a missing mocked import from storybook/test. Also, the uuidv4 should be wrapped in the mocked function call.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The mocked import and function call is only needed for types. So I kept the JS ones simplified.

@kylegach kylegach merged commit 84ea113 into next Aug 1, 2025
8 checks passed
@kylegach kylegach deleted the docs-automocking-2 branch August 1, 2025 16:33
yannbf pushed a commit that referenced this pull request Aug 4, 2025
Docs: Further improvements
(cherry picked from commit 84ea113)
@github-actions github-actions bot added the patch:done Patch/release PRs already cherry-picked to main/release branch label Aug 4, 2025
@ndelangen ndelangen removed the patch:yes Bugfix & documentation PR that need to be picked to main branch label Oct 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:docs Run the CI jobs for documentation checks only. documentation patch:done Patch/release PRs already cherry-picked to main/release branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants