Skip to content

Docs: Add componentName to getAllStoryFiles in Jest portable stories guide - #35036

Merged
valentinpalkovic merged 6 commits into
storybookjs:nextfrom
AliMahmoudDev:next
Sep 18, 2026
Merged

valentinpalkovic merged 6 commits into
storybookjs:nextfrom
AliMahmoudDev:next

Conversation

@AliMahmoudDev

@AliMahmoudDev AliMahmoudDev commented Jun 3, 2026 •

Copy link
Copy Markdown

Issue

Fixes #26925

Problem

In the Jest migration guide for portable stories, the getAllStoryFiles() function returns { filePath, storyFile } but the consumer code destructures componentName:

getAllStoryFiles().forEach(({ storyFile, componentName }) => {
    const meta = storyFile.default;
    const title = meta.title || componentName;

Since componentName was never defined in the returned object, it was always undefined, causing title to fallback to undefined when meta.title wasn't set.

The Vitest version of the same guide correctly computes and returns componentName:

const componentName = path.basename(filePath).replace(/\.(stories|story)\.[^/.]+$/, \$/\);
return { filePath, storyFile, componentName, storyDir };

What Changed

File: docs/_snippets/portable-stories-jest-snapshot-test.md

Added componentName computation to both the JavaScript and TypeScript versions of getAllStoryFiles() in the Jest portable stories snapshot test snippet:

   return storyFiles.map((filePath) => {
     const storyFile = require(filePath);
+    const componentName = path.basename(filePath).replace(/\.(stories|story)\.[^/.]+$/, \$/\);
-    return { filePath, storyFile };
+    return { filePath, storyFile, componentName };
   });

This aligns the Jest code sample with the Vitest version and fixes the runtime error where componentName would be undefined.

How to test

Manual testing

Copy the updated Jest code sample from the docs and verify that:

  1. componentName is correctly extracted from the filename (e.g., Button.stories.tsx → Button)
  2. It is used as a proper fallback for meta.title in the test suite description

Type of change

  • Documentation fix (non-breaking)

Summary by CodeRabbit

  • Documentation
    • Enhanced Jest snapshot test snippets for Storybook with improved component name resolution for more flexible testing scenarios.

… portable stories guide

The Jest version of getAllStoryFiles() was missing the componentName
property in its return object, unlike the Vitest version which correctly
computes and returns it. This caused componentName to be undefined when
used as a fallback for meta.title in the test suite description.

Fixes storybookjs#26925

Co-authored-by: storybookjs-bot <storybook-bot@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

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: ffb1da48-093d-43da-86f0-84a53f39e459

📥 Commits

Reviewing files that changed from the base of the PR and between c91f986 and aa7de52.

📒 Files selected for processing (1)
  • docs/_snippets/portable-stories-jest-snapshot-test.md

📝 Walkthrough

Walkthrough

The PR updates the Storybook Jest snapshot test documentation snippets to compute componentName from story file basenames. Both JavaScript and TypeScript code examples in the portable-stories guide now derive and return componentName alongside filePath and storyFile, enabling test fallback behavior when story titles are not explicitly defined.

Changes

Jest Snapshot Test Snippet Updates

Layer / File(s) Summary
Add componentName to getAllStoryFiles
docs/_snippets/portable-stories-jest-snapshot-test.md
Both JavaScript (lines 28–29) and TypeScript (lines 117–118) code snippets for getAllStoryFiles now derive componentName from the story file's basename using path.parse() and return it as part of the object alongside filePath and storyFile.

🎯 1 (Trivial) | ⏱️ ~3 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.

@valentinpalkovic valentinpalkovic moved this to Empathy Queue (prioritized) in Core Team Projects Jun 3, 2026
@valentinpalkovic valentinpalkovic changed the title fix(docs): add componentName to getAllStoryFiles in Jest portable stories guide Docs: Add componentName to getAllStoryFiles in Jest portable stories guide Jun 3, 2026
@Sidnioulz Sidnioulz added the ci:docs Run the CI jobs for documentation checks only. label Jun 4, 2026
@Sidnioulz Sidnioulz self-assigned this Jun 4, 2026
@Sidnioulz Sidnioulz added qa:skip Pull Requests that do not need any QA. (e.g. documentation) qa:needed Pull Requests that will need manual QA prior to release. and removed qa:skip Pull Requests that do not need any QA. (e.g. documentation) labels Jun 4, 2026
@AliMahmoudDev

This comment was marked as abuse.

@Sidnioulz

Copy link
Copy Markdown
Contributor

@Sidnioulz the Chinese comment was from an earlier draft and has been removed. sorry about that

@AliMahmoudDev, Can you please list all of your GitHub account handles?

@AliMahmoudDev

This comment was marked as abuse.

@Sidnioulz Sidnioulz assigned Sidnioulz and unassigned Sidnioulz Jun 8, 2026
@Sidnioulz
Sidnioulz enabled auto-merge June 19, 2026 12:47
@valentinpalkovic valentinpalkovic added the sev:S4 Low priority. Wait for community PRs. label Jul 14, 2026
@valentinpalkovic
valentinpalkovic merged commit c6f3867 into storybookjs:next Sep 18, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-scan:automated ci:docs Run the CI jobs for documentation checks only. documentation portable stories qa:needed Pull Requests that will need manual QA prior to release. sev:S4 Low priority. Wait for community PRs.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[Documentation]: Configure the testing framework for portable stories (With Jest)

4 participants