Skip to content

Commit

Permalink
Add test to prove #20864 is unneccesary
Browse files Browse the repository at this point in the history
And set things up for #20863
  • Loading branch information
tmeasday committed Feb 1, 2023
1 parent 98d4ba1 commit bd51d02
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 4 deletions.
86 changes: 82 additions & 4 deletions code/lib/core-server/src/utils/StoryIndexGenerator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -463,25 +463,103 @@ describe('StoryIndexGenerator', () => {
);
});

it('throws an error if you attach a MetaOf entry to a tagged autodocs entry', async () => {
it('throws an error if you attach a named MetaOf entry which clashes with a tagged autodocs entry', async () => {
const csfSpecifier: NormalizedStoriesSpecifier = normalizeStoriesEntry(
'./src/B.stories.ts',
options
);

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

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

await expect(generator.getIndex()).rejects.toThrowError(
`You created a component docs page for B (./errors/MetaOfAutodocs.mdx), but also tagged the CSF file (./src/B.stories.ts) with 'autodocs'. This is probably a mistake.`
`You created a component docs page for B (./errors/MetaOfClashingDefaultName.mdx), but also tagged the CSF file (./src/B.stories.ts) with 'autodocs'. This is probably a mistake.`
);
});

it('throws an error if you attach a unnamed MetaOf entry which clashes with a tagged autodocs entry', async () => {
const csfSpecifier: NormalizedStoriesSpecifier = normalizeStoriesEntry(
'./src/B.stories.ts',
options
);

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

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

await expect(generator.getIndex()).rejects.toThrowError(
`You created a component docs page for B (./errors/MetaOfNoName.mdx), but also tagged the CSF file (./src/B.stories.ts) with 'autodocs'. This is probably a mistake.`
);
});

it('allows you to create a second MetaOf entry with a different name to autodocs', async () => {
const csfSpecifier: NormalizedStoriesSpecifier = normalizeStoriesEntry(
'./src/B.stories.ts',
options
);

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

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

expect(await generator.getIndex()).toMatchInlineSnapshot(`
Object {
"entries": Object {
"b--docs": Object {
"id": "b--docs",
"importPath": "./src/B.stories.ts",
"name": "docs",
"storiesImports": Array [],
"tags": Array [
"autodocs",
"docs",
],
"title": "B",
"type": "docs",
},
"b--name": Object {
"id": "b--name",
"importPath": "./errors/MetaOfName.mdx",
"name": "name",
"storiesImports": Array [
"./src/B.stories.ts",
],
"tags": Array [
"docs",
],
"title": "B",
"type": "docs",
},
"b--story-one": Object {
"id": "b--story-one",
"importPath": "./src/B.stories.ts",
"name": "Story One",
"tags": Array [
"autodocs",
"story",
],
"title": "B",
"type": "story",
},
},
"v": 4,
}
`);
});

it('allows you to override autodocs with MetaOf if it is automatic', async () => {
const csfSpecifier: NormalizedStoriesSpecifier = normalizeStoriesEntry(
'./src/A.stories.js',
Expand Down Expand Up @@ -829,7 +907,7 @@ describe('StoryIndexGenerator', () => {
describe('duplicates', () => {
it('warns when two MDX entries reference the same CSF file without a name', async () => {
const docsErrorSpecifier: NormalizedStoriesSpecifier = normalizeStoriesEntry(
'./errors/DuplicateMetaOf.mdx',
'./errors/DuplicateMetaOfNoName.mdx',
options
);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import * as BStories from '../src/B.stories';

{/* This is the same name as the default name (i.e. autodocs entry) */}

<Meta of={BStories} name="Docs" />

# Docs with of

hello docs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import * as BStories from '../src/B.stories';

<Meta of={BStories} name="name" />

# Docs with of

hello docs

0 comments on commit bd51d02

Please sign in to comment.