Skip to content

Commit

Permalink
Portable stories: Support multiple annotation notations from preview …
Browse files Browse the repository at this point in the history
…file
  • Loading branch information
yannbf committed Nov 28, 2024
1 parent 4d08f6d commit 924d095
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 924d095

Please sign in to comment.