diff --git a/code/core/src/core-server/utils/StoryIndexGenerator.test.ts b/code/core/src/core-server/utils/StoryIndexGenerator.test.ts index e1e3f75389ec..f9359d21715c 100644 --- a/code/core/src/core-server/utils/StoryIndexGenerator.test.ts +++ b/code/core/src/core-server/utils/StoryIndexGenerator.test.ts @@ -92,6 +92,7 @@ describe('StoryIndexGenerator', () => { "tags": [ "dev", "test", + "manifest", "component-tag", "story-tag", ], @@ -141,6 +142,7 @@ describe('StoryIndexGenerator', () => { "tags": [ "dev", "test", + "manifest", "autodocs", ], "title": "F", @@ -156,6 +158,7 @@ describe('StoryIndexGenerator', () => { "tags": [ "dev", "test", + "manifest", "autodocs", ], "title": "F", @@ -189,6 +192,7 @@ describe('StoryIndexGenerator', () => { "tags": [ "dev", "test", + "manifest", "autodocs", ], "title": "stories", @@ -204,6 +208,7 @@ describe('StoryIndexGenerator', () => { "tags": [ "dev", "test", + "manifest", "autodocs", ], "title": "stories", @@ -239,6 +244,7 @@ describe('StoryIndexGenerator', () => { "tags": [ "dev", "test", + "manifest", ], "title": "componentPath/extension", "type": "story", @@ -253,6 +259,7 @@ describe('StoryIndexGenerator', () => { "tags": [ "dev", "test", + "manifest", ], "title": "componentPath/noExtension", "type": "story", @@ -267,6 +274,7 @@ describe('StoryIndexGenerator', () => { "tags": [ "dev", "test", + "manifest", ], "title": "componentPath/package", "type": "story", @@ -281,6 +289,7 @@ describe('StoryIndexGenerator', () => { "tags": [ "dev", "test", + "manifest", "component-tag", ], "title": "nested/Button", @@ -296,6 +305,7 @@ describe('StoryIndexGenerator', () => { "tags": [ "dev", "test", + "manifest", ], "title": "second-nested/G", "type": "story", @@ -330,6 +340,7 @@ describe('StoryIndexGenerator', () => { "tags": [ "dev", "test", + "manifest", "component-tag", "story-tag", ], @@ -344,6 +355,7 @@ describe('StoryIndexGenerator', () => { "tags": [ "dev", "test", + "manifest", "autodocs", ], "title": "B", @@ -359,6 +371,7 @@ describe('StoryIndexGenerator', () => { "tags": [ "dev", "test", + "manifest", "autodocs", ], "title": "B", @@ -374,6 +387,7 @@ describe('StoryIndexGenerator', () => { "tags": [ "dev", "test", + "manifest", ], "title": "componentPath/extension", "type": "story", @@ -388,6 +402,7 @@ describe('StoryIndexGenerator', () => { "tags": [ "dev", "test", + "manifest", ], "title": "componentPath/noExtension", "type": "story", @@ -402,6 +417,7 @@ describe('StoryIndexGenerator', () => { "tags": [ "dev", "test", + "manifest", ], "title": "componentPath/package", "type": "story", @@ -414,6 +430,7 @@ describe('StoryIndexGenerator', () => { "tags": [ "dev", "test", + "manifest", "autodocs", ], "title": "D", @@ -429,6 +446,7 @@ describe('StoryIndexGenerator', () => { "tags": [ "dev", "test", + "manifest", "autodocs", ], "title": "D", @@ -444,6 +462,7 @@ describe('StoryIndexGenerator', () => { "tags": [ "dev", "test", + "manifest", "foobar", ], "title": "Example/Button", @@ -459,6 +478,7 @@ describe('StoryIndexGenerator', () => { "tags": [ "dev", "test", + "manifest", ], "title": "first-nested/deeply/F", "type": "story", @@ -473,6 +493,7 @@ describe('StoryIndexGenerator', () => { "tags": [ "dev", "test", + "manifest", ], "title": "first-nested/deeply/Features", "type": "story", @@ -487,6 +508,7 @@ describe('StoryIndexGenerator', () => { "tags": [ "dev", "test", + "manifest", "play-fn", ], "title": "first-nested/deeply/Features", @@ -502,6 +524,7 @@ describe('StoryIndexGenerator', () => { "tags": [ "dev", "test", + "manifest", ], "title": "first-nested/deeply/Features", "type": "story", @@ -516,6 +539,7 @@ describe('StoryIndexGenerator', () => { "tags": [ "dev", "test", + "manifest", ], "title": "first-nested/deeply/Features", "type": "story", @@ -530,6 +554,7 @@ describe('StoryIndexGenerator', () => { "tags": [ "dev", "test", + "manifest", "play-fn", ], "title": "first-nested/deeply/Features", @@ -543,6 +568,7 @@ describe('StoryIndexGenerator', () => { "tags": [ "dev", "test", + "manifest", "autodocs", ], "title": "H", @@ -558,6 +584,7 @@ describe('StoryIndexGenerator', () => { "tags": [ "dev", "test", + "manifest", "autodocs", ], "title": "H", @@ -573,6 +600,7 @@ describe('StoryIndexGenerator', () => { "tags": [ "dev", "test", + "manifest", "component-tag", ], "title": "nested/Button", @@ -588,6 +616,7 @@ describe('StoryIndexGenerator', () => { "tags": [ "dev", "test", + "manifest", ], "title": "second-nested/G", "type": "story", @@ -642,6 +671,7 @@ describe('StoryIndexGenerator', () => { "tags": [ "dev", "test", + "manifest", "component-tag", "story-tag", ], @@ -656,6 +686,7 @@ describe('StoryIndexGenerator', () => { "tags": [ "dev", "test", + "manifest", "autodocs", ], "title": "B", @@ -671,6 +702,7 @@ describe('StoryIndexGenerator', () => { "tags": [ "dev", "test", + "manifest", "autodocs", ], "title": "B", @@ -686,6 +718,7 @@ describe('StoryIndexGenerator', () => { "tags": [ "dev", "test", + "manifest", ], "title": "componentPath/extension", "type": "story", @@ -700,6 +733,7 @@ describe('StoryIndexGenerator', () => { "tags": [ "dev", "test", + "manifest", ], "title": "componentPath/noExtension", "type": "story", @@ -714,6 +748,7 @@ describe('StoryIndexGenerator', () => { "tags": [ "dev", "test", + "manifest", ], "title": "componentPath/package", "type": "story", @@ -726,6 +761,7 @@ describe('StoryIndexGenerator', () => { "tags": [ "dev", "test", + "manifest", "autodocs", ], "title": "D", @@ -741,6 +777,7 @@ describe('StoryIndexGenerator', () => { "tags": [ "dev", "test", + "manifest", "autodocs", ], "title": "D", @@ -756,6 +793,7 @@ describe('StoryIndexGenerator', () => { "tags": [ "dev", "test", + "manifest", "foobar", ], "title": "Example/Button", @@ -771,6 +809,7 @@ describe('StoryIndexGenerator', () => { "tags": [ "dev", "test", + "manifest", ], "title": "first-nested/deeply/F", "type": "story", @@ -785,6 +824,7 @@ describe('StoryIndexGenerator', () => { "tags": [ "dev", "test", + "manifest", ], "title": "first-nested/deeply/Features", "type": "story", @@ -799,6 +839,7 @@ describe('StoryIndexGenerator', () => { "tags": [ "dev", "test", + "manifest", "play-fn", ], "title": "first-nested/deeply/Features", @@ -814,6 +855,7 @@ describe('StoryIndexGenerator', () => { "tags": [ "dev", "test", + "manifest", ], "title": "first-nested/deeply/Features", "type": "story", @@ -828,6 +870,7 @@ describe('StoryIndexGenerator', () => { "tags": [ "dev", "test", + "manifest", ], "title": "first-nested/deeply/Features", "type": "story", @@ -842,6 +885,7 @@ describe('StoryIndexGenerator', () => { "tags": [ "dev", "test", + "manifest", "play-fn", ], "title": "first-nested/deeply/Features", @@ -855,6 +899,7 @@ describe('StoryIndexGenerator', () => { "tags": [ "dev", "test", + "manifest", "autodocs", ], "title": "H", @@ -870,6 +915,7 @@ describe('StoryIndexGenerator', () => { "tags": [ "dev", "test", + "manifest", "autodocs", ], "title": "H", @@ -885,6 +931,7 @@ describe('StoryIndexGenerator', () => { "tags": [ "dev", "test", + "manifest", "component-tag", ], "title": "nested/Button", @@ -900,6 +947,7 @@ describe('StoryIndexGenerator', () => { "tags": [ "dev", "test", + "manifest", ], "title": "second-nested/G", "type": "story", @@ -1090,6 +1138,7 @@ describe('StoryIndexGenerator', () => { "tags": [ "dev", "test", + "manifest", "autodocs", ], "title": "B", @@ -1105,6 +1154,7 @@ describe('StoryIndexGenerator', () => { "tags": [ "dev", "test", + "manifest", "autodocs", "attached-mdx", ], @@ -1121,6 +1171,7 @@ describe('StoryIndexGenerator', () => { "tags": [ "dev", "test", + "manifest", "autodocs", ], "title": "B", @@ -1157,6 +1208,7 @@ describe('StoryIndexGenerator', () => { "tags": [ "dev", "test", + "manifest", "autodocs", ], "title": "B", @@ -1172,6 +1224,7 @@ describe('StoryIndexGenerator', () => { "tags": [ "dev", "test", + "manifest", "autodocs", "attached-mdx", ], @@ -1188,6 +1241,7 @@ describe('StoryIndexGenerator', () => { "tags": [ "dev", "test", + "manifest", "autodocs", ], "title": "B", @@ -1230,6 +1284,7 @@ describe('StoryIndexGenerator', () => { "tags": [ "dev", "test", + "manifest", "component-tag", "story-tag", "attached-mdx", @@ -1247,6 +1302,7 @@ describe('StoryIndexGenerator', () => { "tags": [ "dev", "test", + "manifest", "component-tag", "story-tag", ], @@ -1342,6 +1398,7 @@ describe('StoryIndexGenerator', () => { "tags": [ "dev", "test", + "manifest", "autodocs", ], "title": "duplicate/A", @@ -1357,6 +1414,7 @@ describe('StoryIndexGenerator', () => { "tags": [ "dev", "test", + "manifest", "autodocs", ], "title": "duplicate/A", @@ -1372,6 +1430,7 @@ describe('StoryIndexGenerator', () => { "tags": [ "dev", "test", + "manifest", "autodocs", ], "title": "duplicate/A", @@ -1423,6 +1482,7 @@ describe('StoryIndexGenerator', () => { "tags": [ "dev", "test", + "manifest", "autodocs", ], "title": "A", @@ -1438,6 +1498,7 @@ describe('StoryIndexGenerator', () => { "tags": [ "dev", "test", + "manifest", "autodocs", ], "title": "A", @@ -1469,6 +1530,7 @@ describe('StoryIndexGenerator', () => { "tags": [ "dev", "test", + "manifest", "component-tag", "story-tag", "attached-mdx", @@ -1486,6 +1548,7 @@ describe('StoryIndexGenerator', () => { "tags": [ "dev", "test", + "manifest", "component-tag", "story-tag", "attached-mdx", @@ -1503,6 +1566,7 @@ describe('StoryIndexGenerator', () => { "tags": [ "dev", "test", + "manifest", "component-tag", "story-tag", ], @@ -1517,6 +1581,7 @@ describe('StoryIndexGenerator', () => { "tags": [ "dev", "test", + "manifest", "unattached-mdx", ], "title": "ComponentReference", @@ -1530,6 +1595,7 @@ describe('StoryIndexGenerator', () => { "tags": [ "dev", "test", + "manifest", "unattached-mdx", ], "title": "docs2/Yabbadabbadooo", @@ -1543,6 +1609,7 @@ describe('StoryIndexGenerator', () => { "tags": [ "dev", "test", + "manifest", "unattached-mdx", ], "title": "NoTitle", @@ -1556,6 +1623,7 @@ describe('StoryIndexGenerator', () => { "tags": [ "dev", "test", + "manifest", "foo", "bar", "unattached-mdx", @@ -1622,6 +1690,7 @@ describe('StoryIndexGenerator', () => { "tags": [ "dev", "test", + "manifest", "component-tag", "story-tag", "attached-mdx", @@ -1639,6 +1708,7 @@ describe('StoryIndexGenerator', () => { "tags": [ "dev", "test", + "manifest", "component-tag", "story-tag", "attached-mdx", @@ -1656,6 +1726,7 @@ describe('StoryIndexGenerator', () => { "tags": [ "dev", "test", + "manifest", "component-tag", "story-tag", ], @@ -1670,6 +1741,7 @@ describe('StoryIndexGenerator', () => { "tags": [ "dev", "test", + "manifest", "unattached-mdx", ], "title": "ComponentReference", @@ -1683,6 +1755,7 @@ describe('StoryIndexGenerator', () => { "tags": [ "dev", "test", + "manifest", "unattached-mdx", ], "title": "docs2/Yabbadabbadooo", @@ -1696,6 +1769,7 @@ describe('StoryIndexGenerator', () => { "tags": [ "dev", "test", + "manifest", "unattached-mdx", ], "title": "NoTitle", @@ -1709,6 +1783,7 @@ describe('StoryIndexGenerator', () => { "tags": [ "dev", "test", + "manifest", "foo", "bar", "unattached-mdx", @@ -1746,6 +1821,7 @@ describe('StoryIndexGenerator', () => { "tags": [ "dev", "test", + "manifest", "component-tag", "story-tag", ], @@ -1760,6 +1836,7 @@ describe('StoryIndexGenerator', () => { "tags": [ "dev", "test", + "manifest", "autodocs", ], "title": "B", @@ -1775,6 +1852,7 @@ describe('StoryIndexGenerator', () => { "tags": [ "dev", "test", + "manifest", "autodocs", ], "title": "B", @@ -1791,6 +1869,7 @@ describe('StoryIndexGenerator', () => { "tags": [ "dev", "test", + "manifest", "autodocs", "attached-mdx", ], @@ -1831,6 +1910,7 @@ describe('StoryIndexGenerator', () => { "tags": [ "dev", "test", + "manifest", "attached-mdx", ], "title": "B", @@ -1846,6 +1926,7 @@ describe('StoryIndexGenerator', () => { "tags": [ "dev", "test", + "manifest", ], "title": "B", "type": "story", diff --git a/code/core/src/core-server/utils/StoryIndexGenerator.ts b/code/core/src/core-server/utils/StoryIndexGenerator.ts index 783630a08543..b71367d03742 100644 --- a/code/core/src/core-server/utils/StoryIndexGenerator.ts +++ b/code/core/src/core-server/utils/StoryIndexGenerator.ts @@ -875,7 +875,7 @@ export class StoryIndexGenerator { getProjectTags(previewCode?: string) { let projectTags = [] as Tag[]; - const defaultTags = ['dev', 'test']; + const defaultTags = ['dev', 'test', 'manifest']; if (previewCode) { try { const projectAnnotations = loadConfig(previewCode).parse(); diff --git a/code/core/src/core-server/utils/index-json.test.ts b/code/core/src/core-server/utils/index-json.test.ts index e3d8b22e17e0..f9a1ba45ce5c 100644 --- a/code/core/src/core-server/utils/index-json.test.ts +++ b/code/core/src/core-server/utils/index-json.test.ts @@ -123,6 +123,7 @@ describe('registerIndexJsonRoute', () => { "tags": [ "dev", "test", + "manifest", "component-tag", "story-tag", "attached-mdx", @@ -140,6 +141,7 @@ describe('registerIndexJsonRoute', () => { "tags": [ "dev", "test", + "manifest", "component-tag", "story-tag", "attached-mdx", @@ -156,6 +158,7 @@ describe('registerIndexJsonRoute', () => { "tags": [ "dev", "test", + "manifest", "component-tag", "story-tag", ], @@ -170,6 +173,7 @@ describe('registerIndexJsonRoute', () => { "tags": [ "dev", "test", + "manifest", "autodocs", ], "title": "B", @@ -184,6 +188,7 @@ describe('registerIndexJsonRoute', () => { "tags": [ "dev", "test", + "manifest", "autodocs", ], "title": "B", @@ -199,6 +204,7 @@ describe('registerIndexJsonRoute', () => { "tags": [ "dev", "test", + "manifest", ], "title": "componentPath/extension", "type": "story", @@ -213,6 +219,7 @@ describe('registerIndexJsonRoute', () => { "tags": [ "dev", "test", + "manifest", ], "title": "componentPath/noExtension", "type": "story", @@ -227,6 +234,7 @@ describe('registerIndexJsonRoute', () => { "tags": [ "dev", "test", + "manifest", ], "title": "componentPath/package", "type": "story", @@ -239,6 +247,7 @@ describe('registerIndexJsonRoute', () => { "tags": [ "dev", "test", + "manifest", "autodocs", ], "title": "D", @@ -253,6 +262,7 @@ describe('registerIndexJsonRoute', () => { "tags": [ "dev", "test", + "manifest", "autodocs", ], "title": "D", @@ -266,6 +276,7 @@ describe('registerIndexJsonRoute', () => { "tags": [ "dev", "test", + "manifest", "unattached-mdx", ], "title": "docs2/ComponentReference", @@ -279,6 +290,7 @@ describe('registerIndexJsonRoute', () => { "tags": [ "dev", "test", + "manifest", "unattached-mdx", ], "title": "docs2/NoTitle", @@ -292,6 +304,7 @@ describe('registerIndexJsonRoute', () => { "tags": [ "dev", "test", + "manifest", "foo", "bar", "unattached-mdx", @@ -307,6 +320,7 @@ describe('registerIndexJsonRoute', () => { "tags": [ "dev", "test", + "manifest", "unattached-mdx", ], "title": "docs2/Yabbadabbadooo", @@ -321,6 +335,7 @@ describe('registerIndexJsonRoute', () => { "tags": [ "dev", "test", + "manifest", "foobar", ], "title": "Example/Button", @@ -335,6 +350,7 @@ describe('registerIndexJsonRoute', () => { "tags": [ "dev", "test", + "manifest", ], "title": "first-nested/deeply/F", "type": "story", @@ -348,6 +364,7 @@ describe('registerIndexJsonRoute', () => { "tags": [ "dev", "test", + "manifest", ], "title": "first-nested/deeply/Features", "type": "story", @@ -361,6 +378,7 @@ describe('registerIndexJsonRoute', () => { "tags": [ "dev", "test", + "manifest", "play-fn", ], "title": "first-nested/deeply/Features", @@ -375,6 +393,7 @@ describe('registerIndexJsonRoute', () => { "tags": [ "dev", "test", + "manifest", ], "title": "first-nested/deeply/Features", "type": "story", @@ -388,6 +407,7 @@ describe('registerIndexJsonRoute', () => { "tags": [ "dev", "test", + "manifest", ], "title": "first-nested/deeply/Features", "type": "story", @@ -401,6 +421,7 @@ describe('registerIndexJsonRoute', () => { "tags": [ "dev", "test", + "manifest", "play-fn", ], "title": "first-nested/deeply/Features", @@ -414,6 +435,7 @@ describe('registerIndexJsonRoute', () => { "tags": [ "dev", "test", + "manifest", "autodocs", ], "title": "H", @@ -428,6 +450,7 @@ describe('registerIndexJsonRoute', () => { "tags": [ "dev", "test", + "manifest", "autodocs", ], "title": "H", @@ -442,6 +465,7 @@ describe('registerIndexJsonRoute', () => { "tags": [ "dev", "test", + "manifest", "component-tag", ], "title": "nested/Button", @@ -456,6 +480,7 @@ describe('registerIndexJsonRoute', () => { "tags": [ "dev", "test", + "manifest", ], "title": "second-nested/G", "type": "story", diff --git a/code/core/src/core-server/utils/manifests/manifests.test.ts b/code/core/src/core-server/utils/manifests/manifests.test.ts index 5728f1c8ba95..41ceddf8a452 100644 --- a/code/core/src/core-server/utils/manifests/manifests.test.ts +++ b/code/core/src/core-server/utils/manifests/manifests.test.ts @@ -20,7 +20,11 @@ describe('manifests', () => { let mockManifests: Manifests; const setupMockPresets = () => { - mockGenerator = { getIndex: vi.fn().mockResolvedValue({} as StoryIndex) }; + mockGenerator = { + getIndex: vi.fn().mockResolvedValue({ + entries: {}, + } as StoryIndex), + }; mockManifests = {}; return { @@ -114,6 +118,67 @@ describe('manifests', () => { expect(vi.mocked(logger).error).toHaveBeenCalledWith('Failed to generate manifests'); expect(vi.mocked(logger).error).toHaveBeenCalledWith(errorString); }); + + it('should filter entries by manifest tag and pass manifestEntries to preset', async () => { + mockGenerator.getIndex.mockResolvedValue({ + v: 5, + entries: { + 'story-with-manifest': { + type: 'story', + subtype: 'story', + id: 'story-with-manifest', + name: 'Story', + title: 'Example', + importPath: './Example.stories.tsx', + tags: ['manifest', 'other'], + }, + 'story-without-manifest': { + type: 'story', + subtype: 'story', + id: 'story-without-manifest', + name: 'Other', + title: 'Other', + importPath: './Other.stories.tsx', + tags: ['other'], + }, + 'docs-entry': { + type: 'docs', + id: 'docs', + name: 'Docs', + title: 'Docs', + importPath: './Docs.mdx', + tags: ['manifest'], + storiesImports: [], + }, + }, + } as StoryIndex); + + mockManifests = { custom: { data: 'value' } }; + + await writeManifests('/output', mockPresets); + + expect(mockPresets.apply).toHaveBeenCalledWith( + 'experimental_manifests', + undefined, + expect.objectContaining({ + manifestEntries: expect.arrayContaining([ + expect.objectContaining({ id: 'story-with-manifest' }), + ]), + }) + ); + + // Get the specific apply call to the experimental_manifests preset + const manifestsPresetCall = (mockPresets.apply as any).mock.calls.find( + (call: any) => call[0] === 'experimental_manifests' + ); + // Should include both story and docs entries with manifest tag + expect(manifestsPresetCall[2].manifestEntries).toHaveLength(2); + const entryIds = manifestsPresetCall[2].manifestEntries.map((entry: any) => entry.id); + expect(entryIds).toContain('story-with-manifest'); + expect(entryIds).toContain('docs'); + // Should NOT include story without manifest tag + expect(entryIds).not.toContain('story-without-manifest'); + }); }); describe('registerManifests', () => { diff --git a/code/core/src/core-server/utils/manifests/manifests.ts b/code/core/src/core-server/utils/manifests/manifests.ts index bbbf7c5f1ce6..a77907df7a59 100644 --- a/code/core/src/core-server/utils/manifests/manifests.ts +++ b/code/core/src/core-server/utils/manifests/manifests.ts @@ -9,12 +9,24 @@ import invariant from 'tiny-invariant'; import { renderComponentsManifest } from './render-components-manifest'; +async function getManifests(presets: Presets) { + const generator = await presets.apply('storyIndexGenerator'); + invariant(generator, 'storyIndexGenerator must be configured'); + const index = await generator.getIndex(); + const manifestEntries = Object.values(index.entries).filter( + (entry) => entry.tags?.includes('manifest') ?? false + ); + + return ( + (await presets.apply('experimental_manifests', undefined, { + manifestEntries, + })) ?? {} + ); +} + export async function writeManifests(outputDir: string, presets: Presets) { try { - const generator = await presets.apply('storyIndexGenerator'); - invariant(generator, 'storyIndexGenerator must be configured'); - const index = await generator.getIndex(); - const manifests = await presets.apply('experimental_manifests', {}, { index }); + const manifests = await getManifests(presets); if (Object.keys(manifests).length === 0) { return; } @@ -37,18 +49,10 @@ export async function writeManifests(outputDir: string, presets: Presets) { } export function registerManifests({ app, presets }: { app: Polka; presets: Presets }) { - async function getManifest(manifestName: string) { - const generator = await presets.apply('storyIndexGenerator'); - invariant(generator, 'storyIndexGenerator must be configured'); - const index = await generator.getIndex(); - const manifests = ((await presets.apply('experimental_manifests', {}, { index })) ?? - {}) as Manifests; - return manifests[manifestName]; - } - app.get('/manifests/:name.json', async (req, res) => { try { - const manifest = await getManifest(req.params.name); + const manifests = await getManifests(presets); + const manifest = manifests[req.params.name]; if (manifest) { res.setHeader('Content-Type', 'application/json'); @@ -66,7 +70,8 @@ export function registerManifests({ app, presets }: { app: Polka; presets: Prese app.get('/manifests/components.html', async (req, res) => { try { - const manifest = (await getManifest('components')) as ComponentsManifest | undefined; + const manifests = await getManifests(presets); + const manifest = manifests.components; if (!manifest) { res.statusCode = 404; diff --git a/code/renderers/react/src/componentManifest/fixtures.ts b/code/renderers/react/src/componentManifest/fixtures.ts index e7597601f306..2a3f5df215b3 100644 --- a/code/renderers/react/src/componentManifest/fixtures.ts +++ b/code/renderers/react/src/componentManifest/fixtures.ts @@ -8,6 +8,7 @@ export const fsMocks = { import { Button } from './Button'; const meta = { + title: 'Example/Button', component: Button, args: { onClick: fn() }, } satisfies Meta; @@ -62,6 +63,7 @@ export const fsMocks = { * @summary Component summary */ const meta = { + title: 'Example/Header', component: Header, args: { onLogin: fn(), @@ -118,7 +120,7 @@ export const indexJson = { title: 'Example/Button', importPath: './src/stories/Button.stories.ts', componentPath: './src/stories/Button.tsx', - tags: ['dev', 'test', 'vitest', 'autodocs'], + tags: ['dev', 'test', 'vitest', 'autodocs', 'manifest'], exportName: 'Primary', }, 'example-button--secondary': { @@ -129,7 +131,7 @@ export const indexJson = { title: 'Example/Button', importPath: './src/stories/Button.stories.ts', componentPath: './src/stories/Button.tsx', - tags: ['dev', 'test', 'vitest', 'autodocs'], + tags: ['dev', 'test', 'vitest', 'autodocs', 'manifest'], exportName: 'Secondary', }, 'example-button--large': { @@ -140,7 +142,7 @@ export const indexJson = { title: 'Example/Button', importPath: './src/stories/Button.stories.ts', componentPath: './src/stories/Button.tsx', - tags: ['dev', 'test', 'vitest', 'autodocs'], + tags: ['dev', 'test', 'vitest', 'autodocs', 'manifest'], exportName: 'Large', }, 'example-button--small': { @@ -151,7 +153,7 @@ export const indexJson = { title: 'Example/Button', importPath: './src/stories/Button.stories.ts', componentPath: './src/stories/Button.tsx', - tags: ['dev', 'test', 'vitest', 'autodocs'], + tags: ['dev', 'test', 'vitest', 'autodocs', 'manifest'], exportName: 'Small', }, 'example-header--docs': { @@ -171,7 +173,7 @@ export const indexJson = { title: 'Example/Header', importPath: './src/stories/Header.stories.ts', componentPath: './src/stories/Header.tsx', - tags: ['dev', 'test', 'vitest', 'autodocs'], + tags: ['dev', 'test', 'vitest', 'autodocs', 'manifest'], exportName: 'LoggedIn', }, 'example-header--logged-out': { @@ -182,7 +184,7 @@ export const indexJson = { title: 'Example/Header', importPath: './src/stories/Header.stories.ts', componentPath: './src/stories/Header.tsx', - tags: ['dev', 'test', 'vitest', 'autodocs'], + tags: ['dev', 'test', 'vitest', 'autodocs', 'manifest'], exportName: 'LoggedOut', }, }, diff --git a/code/renderers/react/src/componentManifest/generator.test.ts b/code/renderers/react/src/componentManifest/generator.test.ts index 1bda84f98fab..f33b2b88862b 100644 --- a/code/renderers/react/src/componentManifest/generator.test.ts +++ b/code/renderers/react/src/componentManifest/generator.test.ts @@ -12,7 +12,10 @@ beforeEach(() => { }); test('manifests generates correct id, name, description and examples ', async () => { - const result = await manifests(undefined, { index: indexJson } as any); + const manifestEntries = Object.values(indexJson.entries).filter( + (entry) => entry.tags?.includes('manifest') ?? false + ); + const result = await manifests(undefined, { manifestEntries } as any); expect(result?.components).toMatchInlineSnapshot(` { @@ -260,24 +263,21 @@ async function getManifestForStory(code: string) { '/app' ); - const indexJson = { - v: 5, - entries: { - 'example-button--primary': { - type: 'story', - subtype: 'story', - id: 'example-button--primary', - name: 'Primary', - title: 'Example/Button', - importPath: './src/stories/Button.stories.ts', - componentPath: './src/stories/Button.tsx', - tags: ['dev', 'test', 'vitest', 'autodocs'], - exportName: 'Primary', - }, + const manifestEntries = [ + { + type: 'story', + subtype: 'story', + id: 'example-button--primary', + name: 'Primary', + title: 'Example/Button', + importPath: './src/stories/Button.stories.ts', + componentPath: './src/stories/Button.tsx', + tags: ['dev', 'test', 'vitest', 'autodocs', 'manifest'], + exportName: 'Primary', }, - }; + ]; - const result = await manifests(undefined, { index: indexJson } as any); + const result = await manifests(undefined, { manifestEntries } as any); return result?.components?.components?.['example-button']; } @@ -288,6 +288,7 @@ function withCSF3(body: string) { import { Button } from './Button'; const meta = { + title: 'Example/Button', component: Button, args: { onClick: fn() }, } satisfies Meta; @@ -303,7 +304,9 @@ test('fall back to index title when no component name', async () => { import { Button } from './Button'; export default { + title: 'Example/Button', args: { onClick: fn() }, + tags: ['manifest'], }; export const Primary = () =>