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

Don't allow setting Meta of={X} if X is tagged with 'autodocs' #20373

Merged
merged 4 commits into from
Dec 22, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
53 changes: 30 additions & 23 deletions code/lib/core-server/src/utils/StoryIndexGenerator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,20 +321,6 @@ describe('StoryIndexGenerator', () => {
expect(await generator.getIndex()).toMatchInlineSnapshot(`
Object {
"entries": Object {
"a--docs": Object {
"id": "a--docs",
"importPath": "./src/A.stories.js",
"name": "docs",
"standalone": false,
"storiesImports": Array [],
"tags": Array [
"component-tag",
"autodocs",
"docs",
],
"title": "A",
"type": "docs",
},
"a--story-one": Object {
"id": "a--story-one",
"importPath": "./src/A.stories.js",
Expand Down Expand Up @@ -431,19 +417,20 @@ describe('StoryIndexGenerator', () => {
`);
});

const autodocsTrueOptions = {
...autodocsOptions,
docs: {
...autodocsOptions.docs,
autodocs: true,
},
};
it('generates an entry for every CSF file when docsOptions.autodocs = true', async () => {
const specifier: NormalizedStoriesSpecifier = normalizeStoriesEntry(
'./src/**/*.stories.(ts|js|jsx)',
options
);

const generator = new StoryIndexGenerator([specifier], {
...autodocsOptions,
docs: {
...autodocsOptions.docs,
autodocs: true,
},
});
const generator = new StoryIndexGenerator([specifier], autodocsTrueOptions);
await generator.initialize();

expect(Object.keys((await generator.getIndex()).entries)).toMatchInlineSnapshot(`
Expand All @@ -464,7 +451,24 @@ describe('StoryIndexGenerator', () => {
`);
});

it('does not generate a docs page entry if there is a standalone entry with the same name', async () => {
it.skip('throws an error if you attach a MetaOf entry to a tagged autodocs entry', async () => {
tmeasday marked this conversation as resolved.
Show resolved Hide resolved
const csfSpecifier: NormalizedStoriesSpecifier = normalizeStoriesEntry(
'./src/B.stories.ts',
options
);

const docsSpecifier: NormalizedStoriesSpecifier = normalizeStoriesEntry(
'./errors/MetaOfAutodocs.mdx',
options
);

const generator = new StoryIndexGenerator([csfSpecifier, docsSpecifier], autodocsOptions);
await generator.initialize();

await expect(generator.getIndex()).rejects.toThrowError(/tagged entry/);
});

it('allows you to override autodocs with MetaOf if it is automatic', async () => {
const csfSpecifier: NormalizedStoriesSpecifier = normalizeStoriesEntry(
'./src/A.stories.js',
options
Expand All @@ -475,7 +479,10 @@ describe('StoryIndexGenerator', () => {
options
);

const generator = new StoryIndexGenerator([csfSpecifier, docsSpecifier], autodocsOptions);
const generator = new StoryIndexGenerator(
[csfSpecifier, docsSpecifier],
autodocsTrueOptions
);
await generator.initialize();

expect(await generator.getIndex()).toMatchInlineSnapshot(`
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import * as BStories from '../src/B.stories';

<Meta of={BStories} />

# Docs with of

hello docs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const component = {};
export default {
component,
tags: ['component-tag', 'autodocs'],
tags: ['component-tag'],
};

export const StoryOne = { tags: ['story-tag'] };