Skip to content

Commit

Permalink
Merge pull request #29733 from storybookjs/yann/improve-ps-annotations
Browse files Browse the repository at this point in the history
Portable stories: Support multiple annotation notations from preview
  • Loading branch information
shilman authored Nov 29, 2024
2 parents a4ae081 + 924d095 commit 020074b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
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

0 comments on commit 020074b

Please sign in to comment.