Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Portable stories: Support multiple annotation notations from preview #29733

Merged
merged 1 commit into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,25 @@ describe('composeStory', () => {
expect(composedStory.parameters.fromAnnotations.asDefaultImport).toEqual(true);
});

it('should compose project annotations when used in named and default exports from the same module', () => {
setProjectAnnotations([
{
initialGlobals: { namedExportAnnotation: true },
default: {
parameters: { defaultExportAnnotation: true },
},
},
]);

const Story: Story = {
render: () => {},
};

const composedStory = composeStory(Story, meta);
expect(composedStory.parameters.defaultExportAnnotation).toEqual(true);
expect(composedStory.globals.namedExportAnnotation).toEqual(true);
});

it('should return story with composed annotations from story, meta and project', () => {
const decoratorFromProjectAnnotations = vi.fn((StoryFn) => StoryFn());
const decoratorFromStoryAnnotations = vi.fn((StoryFn) => StoryFn());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,8 @@ function extractAnnotation<TRenderer extends Renderer = Renderer>(
// import * as annotations from '.storybook/preview'
// import annotations from '.storybook/preview'
// in both cases: 1 - the file has a default export; 2 - named exports only
// support imports such as
// import * as annotations from '.storybook/preview'
// import annotations from '.storybook/preview'
// in both cases: 1 - the file has a default export; 2 - named exports only
return 'default' in annotation ? annotation.default : annotation;
// also support when the file has both annotations coming from default and named exports
return composeConfigs([annotation]);
}

export function setProjectAnnotations<TRenderer extends Renderer = Renderer>(
Expand Down
Loading