From 1ecedf547a116bf274645b90310a5541dff963e9 Mon Sep 17 00:00:00 2001 From: Jeppe Reinhold Date: Sat, 29 Jul 2023 22:59:51 +0200 Subject: [PATCH 1/5] add __id and metaId to BaseIndexInput --- .../StoryIndexGenerator.deprecated.test.ts | 11 +- .../src/utils/StoryIndexGenerator.test.ts | 22 ++-- .../src/utils/StoryIndexGenerator.ts | 5 +- .../utils/__tests__/index-extraction.test.ts | 102 ++++++++++++++---- code/lib/types/src/modules/indexer.ts | 47 +++++--- 5 files changed, 137 insertions(+), 50 deletions(-) diff --git a/code/lib/core-server/src/utils/StoryIndexGenerator.deprecated.test.ts b/code/lib/core-server/src/utils/StoryIndexGenerator.deprecated.test.ts index 38614f6aabd9..dd026bfea2a8 100644 --- a/code/lib/core-server/src/utils/StoryIndexGenerator.deprecated.test.ts +++ b/code/lib/core-server/src/utils/StoryIndexGenerator.deprecated.test.ts @@ -1164,14 +1164,15 @@ describe('StoryIndexGenerator with deprecated indexer API', () => { const csf = loadCsf(code, { ...options, fileName }).parse(); // eslint-disable-next-line no-underscore-dangle - return Object.entries(csf._stories).map(([key, story]) => ({ - key, - id: story.id, + return Object.entries(csf._stories).map(([exportName, story]) => ({ + type: 'story', + importPath: fileName, + exportName, name: story.name, title: csf.meta.title, - importPath: fileName, - type: 'story', + metaId: csf.meta.id, tags: story.tags ?? csf.meta.tags, + __id: story.id, })); }, }, diff --git a/code/lib/core-server/src/utils/StoryIndexGenerator.test.ts b/code/lib/core-server/src/utils/StoryIndexGenerator.test.ts index 15af3e19ebb0..297aaef6517b 100644 --- a/code/lib/core-server/src/utils/StoryIndexGenerator.test.ts +++ b/code/lib/core-server/src/utils/StoryIndexGenerator.test.ts @@ -42,14 +42,15 @@ const storiesMdxIndexer: Indexer = { const csf = loadCsf(code, { ...opts, fileName }).parse(); // eslint-disable-next-line no-underscore-dangle - return Object.entries(csf._stories).map(([key, story]) => ({ - key, - id: story.id, + return Object.entries(csf._stories).map(([exportName, story]) => ({ + type: 'story', + importPath: fileName, + exportName, name: story.name, title: csf.meta.title, - importPath: fileName, - type: 'story', + metaId: csf.meta.id, tags: story.tags ?? csf.meta.tags, + __id: story.id, })); }, }; @@ -61,14 +62,15 @@ const csfIndexer: Indexer = { const csf = loadCsf(code, { ...options, fileName }).parse(); // eslint-disable-next-line no-underscore-dangle - return Object.entries(csf._stories).map(([key, story]) => ({ - key, - id: story.id, + return Object.entries(csf._stories).map(([exportName, story]) => ({ + type: 'story', + importPath: fileName, + exportName, name: story.name, title: csf.meta.title, - importPath: fileName, - type: 'story', + metaId: csf.meta.id, tags: story.tags ?? csf.meta.tags, + __id: story.id, })); }, }; diff --git a/code/lib/core-server/src/utils/StoryIndexGenerator.ts b/code/lib/core-server/src/utils/StoryIndexGenerator.ts index bbd5234e3cdd..8d18013aae2a 100644 --- a/code/lib/core-server/src/utils/StoryIndexGenerator.ts +++ b/code/lib/core-server/src/utils/StoryIndexGenerator.ts @@ -302,9 +302,10 @@ export class StoryIndexGenerator { const entries: ((StoryIndexEntry | DocsCacheEntry) & { tags: Tag[] })[] = indexInputs.map( (input) => { - const name = input.name ?? storyNameFromExport(input.key); + const name = input.name ?? storyNameFromExport(input.exportName); const title = input.title ?? defaultMakeTitle(); - const id = input.id ?? toId(title, name); + // eslint-disable-next-line no-underscore-dangle + const id = input.__id ?? toId(input.metaId ?? title, storyNameFromExport(input.exportName)); const tags = (input.tags || []).concat('story'); return { diff --git a/code/lib/core-server/src/utils/__tests__/index-extraction.test.ts b/code/lib/core-server/src/utils/__tests__/index-extraction.test.ts index a9de04473d39..ce9bdb1e5d20 100644 --- a/code/lib/core-server/src/utils/__tests__/index-extraction.test.ts +++ b/code/lib/core-server/src/utils/__tests__/index-extraction.test.ts @@ -35,14 +35,27 @@ describe('story extraction', () => { { test: /\.stories\.(m?js|ts)x?$/, index: async (fileName) => [ + // properties identical to the auto-generated ones, eg. 'StoryOne' -> 'Story One' { - key: 'StoryOne', - id: 'a--story-one', + type: 'story', + importPath: fileName, + exportName: 'StoryOne', name: 'Story One', title: 'A', + metaId: 'a', tags: ['story-tag-from-indexer'], - importPath: fileName, + __id: 'a--story-one', + }, + // properties different from the auto-generated ones, eg. 'StoryOne' -> 'Another Story Name' + { type: 'story', + importPath: fileName, + exportName: 'StoryOne', + name: 'Another Story Name', + title: 'Custom Title', + metaId: 'custom-id', + tags: ['story-tag-from-indexer'], + __id: 'some-custom-id--the-first-story', }, ], }, @@ -65,6 +78,17 @@ describe('story extraction', () => { "title": "A", "type": "story", }, + Object { + "id": "some-custom-id--the-first-story", + "importPath": "./src/A.stories.js", + "name": "Another Story Name", + "tags": Array [ + "story-tag-from-indexer", + "story", + ], + "title": "Custom Title", + "type": "story", + }, ], "type": "stories", } @@ -83,7 +107,7 @@ describe('story extraction', () => { test: /\.stories\.(m?js|ts)x?$/, index: async (fileName) => [ { - key: 'StoryOne', + exportName: 'StoryOne', importPath: fileName, type: 'story', }, @@ -125,8 +149,8 @@ describe('story extraction', () => { test: /\.stories\.(m?js|ts)x?$/, index: async (fileName) => [ { - key: 'StoryOne', - id: 'a--story-one', + exportName: 'StoryOne', + __id: 'a--story-one', name: 'Story One', tags: ['story-tag-from-indexer'], importPath: fileName, @@ -171,8 +195,8 @@ describe('story extraction', () => { test: /\.stories\.(m?js|ts)x?$/, index: async (fileName) => [ { - key: 'StoryOne', - id: 'a--story-one', + exportName: 'StoryOne', + __id: 'a--story-one', title: 'A', tags: ['story-tag-from-indexer'], importPath: fileName, @@ -205,7 +229,7 @@ describe('story extraction', () => { `); }); - it('auto-generates id from name and title inputs', async () => { + it('auto-generates id from name, title and/or metaId inputs', async () => { const relativePath = './src/A.stories.js'; const absolutePath = path.join(options.workingDir, relativePath); const specifier: NormalizedStoriesSpecifier = normalizeStoriesEntry(relativePath, options); @@ -217,13 +241,29 @@ describe('story extraction', () => { test: /\.stories\.(m?js|ts)x?$/, index: async (fileName) => [ { - key: 'StoryOne', + exportName: 'StoryOne', name: 'Story One', title: 'A', tags: ['story-tag-from-indexer'], importPath: fileName, type: 'story', }, + { + exportName: 'StoryTwo', + name: 'Custom Name For Second Story', + title: 'Custom Title', + tags: ['story-tag-from-indexer'], + importPath: fileName, + type: 'story', + }, + { + exportName: 'StoryThree', + metaId: 'custom-meta-id', + title: 'Custom Title', + tags: ['story-tag-from-indexer'], + importPath: fileName, + type: 'story', + }, ], }, ], @@ -245,13 +285,35 @@ describe('story extraction', () => { "title": "A", "type": "story", }, + Object { + "id": "custom-title--story-two", + "importPath": "./src/A.stories.js", + "name": "Custom Name For Second Story", + "tags": Array [ + "story-tag-from-indexer", + "story", + ], + "title": "Custom Title", + "type": "story", + }, + Object { + "id": "custom-meta-id--story-three", + "importPath": "./src/A.stories.js", + "name": "Story Three", + "tags": Array [ + "story-tag-from-indexer", + "story", + ], + "title": "Custom Title", + "type": "story", + }, ], "type": "stories", } `); }); - it('auto-generates id, title and name from key input', async () => { + it('auto-generates id, title and name from exportName input', async () => { const relativePath = './src/A.stories.js'; const absolutePath = path.join(options.workingDir, relativePath); const specifier: NormalizedStoriesSpecifier = normalizeStoriesEntry(relativePath, options); @@ -263,7 +325,7 @@ describe('story extraction', () => { test: /\.stories\.(m?js|ts)x?$/, index: async (fileName) => [ { - key: 'StoryOne', + exportName: 'StoryOne', tags: ['story-tag-from-indexer'], importPath: fileName, type: 'story', @@ -309,8 +371,8 @@ describe('docs entries from story extraction', () => { test: /\.stories\.(m?js|ts)x?$/, index: async (fileName) => [ { - key: 'StoryOne', - id: 'a--story-one', + exportName: 'StoryOne', + __id: 'a--story-one', name: 'Story One', title: 'A', tags: ['story-tag-from-indexer'], @@ -369,8 +431,8 @@ describe('docs entries from story extraction', () => { test: /\.stories\.(m?js|ts)x?$/, index: async (fileName) => [ { - key: 'StoryOne', - id: 'a--story-one', + exportName: 'StoryOne', + __id: 'a--story-one', name: 'Story One', title: 'A', tags: [AUTODOCS_TAG, 'story-tag-from-indexer'], @@ -430,8 +492,8 @@ describe('docs entries from story extraction', () => { test: /\.stories\.(m?js|ts)x?$/, index: async (fileName) => [ { - key: 'StoryOne', - id: 'a--story-one', + exportName: 'StoryOne', + __id: 'a--story-one', name: 'Story One', title: 'A', tags: [AUTODOCS_TAG, 'story-tag-from-indexer'], @@ -478,8 +540,8 @@ describe('docs entries from story extraction', () => { test: /\.stories\.(m?js|ts)x?$/, index: async (fileName) => [ { - key: 'StoryOne', - id: 'a--story-one', + exportName: 'StoryOne', + __id: 'a--story-one', name: 'Story One', title: 'A', tags: [STORIES_MDX_TAG, 'story-tag-from-indexer'], diff --git a/code/lib/types/src/modules/indexer.ts b/code/lib/types/src/modules/indexer.ts index 1789585347e0..c27ea46387a7 100644 --- a/code/lib/types/src/modules/indexer.ts +++ b/code/lib/types/src/modules/indexer.ts @@ -1,6 +1,7 @@ import type { StoryId, ComponentTitle, StoryName, Parameters, Tag, Path } from './csf'; -type ExportKey = string; +type ExportName = string; +type MetaId = string; interface StoriesSpecifier { /** @@ -100,27 +101,47 @@ export type DocsIndexEntry = BaseIndexEntry & { export type IndexEntry = StoryIndexEntry | DocsIndexEntry; -export interface BaseIndexInput { - /** the file to import from e.g. the story file */ +/** + * The base input for indexing a story or docs entry. + */ +export type BaseIndexInput = { + /** The file to import from e.g. the story file. */ importPath: Path; - /** the key to import from the file e.g. the story export for this entry */ - key: ExportKey; - /** the location in the sidebar, auto-generated from {@link importPath} if unspecified */ - title?: ComponentTitle; - /** the name of the story, auto-generated from {@link key} if unspecified */ + /** The name of the export to import. */ + exportName: ExportName; + /** The name of the entry, auto-generated from {@link exportName} if unspecified. */ name?: StoryName; - /** the unique story ID, auto-generated from {@link title} and {@link name} if unspecified */ - id?: StoryId; - /** tags for filtering entries in Storybook and its tools */ + /** The location in the sidebar, auto-generated from {@link importPath} if unspecified. */ + title?: ComponentTitle; + /** + * The custom id optionally set at `meta.id` if it needs to differ from the id generated via {@link title}. + * If unspecified, the meta id will be auto-generated from {@link title}. + * If specified, the meta in the CSF file _must_ have a matching id set at `meta.id`, to be correctly matched. + */ + metaId?: MetaId; + /** Tags for filtering entries in Storybook and its tools. */ tags?: Tag[]; -} + /** + * The id of the entry, auto-generated from {@link title}/{@link metaId} and {@link exportName} if unspecified. + * If specified, the story in the CSF file _must_ have a matching id set at `parameters.__id`, to be correctly matched. + * Only use this if you need to override the auto-generated id. + */ + __id?: StoryId; +}; + +/** + * The input for indexing a story entry. + */ export type StoryIndexInput = BaseIndexInput & { type: 'story'; }; +/** + * The input for indexing a docs entry. + */ export type DocsIndexInput = BaseIndexInput & { type: 'docs'; - /** paths to story files that must be pre-loaded for this docs entry */ + /** Paths to story files that must be pre-loaded for this docs entry. */ storiesImports?: Path[]; }; From 2f8d0af31989b8fa7c473a918c59c742055a2b1e Mon Sep 17 00:00:00 2001 From: Jeppe Reinhold Date: Sat, 29 Jul 2023 23:14:05 +0200 Subject: [PATCH 2/5] add stories for custom ids --- .../template/stories/indexer.stories.ts | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 code/lib/preview-api/template/stories/indexer.stories.ts diff --git a/code/lib/preview-api/template/stories/indexer.stories.ts b/code/lib/preview-api/template/stories/indexer.stories.ts new file mode 100644 index 000000000000..0bcfd98b0d85 --- /dev/null +++ b/code/lib/preview-api/template/stories/indexer.stories.ts @@ -0,0 +1,26 @@ +import { expect } from '@storybook/jest'; +import { global as globalThis } from '@storybook/global'; +import type { PlayFunctionContext } from '@storybook/types'; + +export default { + component: globalThis.Components.Pre, + args: { text: 'Check that id assertions in interaction tests are passing' }, + id: 'indexer-custom-meta-id', +}; + +// FIXME: fails with "Didn't find 'lib-preview-api-indexer--default' in CSF file, this is unexpected" +export const Default = { + play: async ({ id }: PlayFunctionContext) => { + await expect(id).toBe('indexer-custom-meta-id--default'); + }, +}; + +// FIXME: fails with Didn't find 'lib-preview-api-indexer--custom-parameters-id' in CSF file, this is unexpected +export const CustomParametersId = { + parameters: { + __id: 'custom-id', + }, + play: async ({ id }: PlayFunctionContext) => { + await expect(id).toBe('indexer-custom-meta-id--custom-id'); + }, +}; From 8246e98ba09d40c9ede032932d9df2d2f5e9352d Mon Sep 17 00:00:00 2001 From: Jeppe Reinhold Date: Sat, 29 Jul 2023 23:53:47 +0200 Subject: [PATCH 3/5] fix tests for new indexer api --- .../src/utils/__tests__/index-extraction.test.ts | 4 ++-- .../lib/core-server/src/utils/stories-json.test.ts | 14 ++++++++------ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/code/lib/core-server/src/utils/__tests__/index-extraction.test.ts b/code/lib/core-server/src/utils/__tests__/index-extraction.test.ts index ce9bdb1e5d20..772ac0b833e3 100644 --- a/code/lib/core-server/src/utils/__tests__/index-extraction.test.ts +++ b/code/lib/core-server/src/utils/__tests__/index-extraction.test.ts @@ -55,7 +55,7 @@ describe('story extraction', () => { title: 'Custom Title', metaId: 'custom-id', tags: ['story-tag-from-indexer'], - __id: 'some-custom-id--the-first-story', + __id: 'some-fully-custom-id', }, ], }, @@ -79,7 +79,7 @@ describe('story extraction', () => { "type": "story", }, Object { - "id": "some-custom-id--the-first-story", + "id": "some-fully-custom-id", "importPath": "./src/A.stories.js", "name": "Another Story Name", "tags": Array [ diff --git a/code/lib/core-server/src/utils/stories-json.test.ts b/code/lib/core-server/src/utils/stories-json.test.ts index 018caa6e69db..92ccdd1a48f5 100644 --- a/code/lib/core-server/src/utils/stories-json.test.ts +++ b/code/lib/core-server/src/utils/stories-json.test.ts @@ -48,9 +48,10 @@ const storiesMdxIndexer: Indexer = { const csf = loadCsf(code, { ...opts, fileName }).parse(); // eslint-disable-next-line no-underscore-dangle - return Object.entries(csf._stories).map(([key, story]) => ({ - key, - id: story.id, + return Object.entries(csf._stories).map(([exportName, story]) => ({ + exportName, + __id: story.id, + metaId: csf.meta.id, name: story.name, title: csf.meta.title, importPath: fileName, @@ -67,10 +68,11 @@ const csfIndexer: Indexer = { const csf = loadCsf(code, { ...options, fileName }).parse(); // eslint-disable-next-line no-underscore-dangle - return Object.entries(csf._stories).map(([key, story]) => ({ - key, - id: story.id, + return Object.entries(csf._stories).map(([exportName, story]) => ({ + exportName, + __id: story.id, name: story.name, + metaId: csf.meta.id, title: csf.meta.title, importPath: fileName, type: 'story', From 7519597616e12a7f22e7ee70f8303236099eef9a Mon Sep 17 00:00:00 2001 From: Jeppe Reinhold Date: Sun, 30 Jul 2023 00:02:35 +0200 Subject: [PATCH 4/5] Add parameters.__id handling to CsfFile.parse() --- code/lib/csf-tools/src/CsfFile.test.ts | 21 ++++++ code/lib/csf-tools/src/CsfFile.ts | 75 +++++++++++-------- .../template/stories/indexer.stories.ts | 4 +- 3 files changed, 66 insertions(+), 34 deletions(-) diff --git a/code/lib/csf-tools/src/CsfFile.test.ts b/code/lib/csf-tools/src/CsfFile.test.ts index 02f42923250b..4fd4af30bd79 100644 --- a/code/lib/csf-tools/src/CsfFile.test.ts +++ b/code/lib/csf-tools/src/CsfFile.test.ts @@ -202,6 +202,27 @@ describe('CsfFile', () => { `); }); + it('custom parameters.__id', () => { + expect( + parse( + dedent` + export default { title: 'foo/bar', id: 'custom-meta-id' }; + export const JustCustomMetaId = {}; + export const CustomParemetersId = { parameters: { __id: 'custom-id' } }; + ` + ) + ).toMatchInlineSnapshot(` + meta: + title: foo/bar + id: custom-meta-id + stories: + - id: custom-meta-id--just-custom-meta-id + name: Just Custom Meta Id + - id: custom-id + name: Custom Paremeters Id + `); + }); + it('typescript', () => { expect( parse( diff --git a/code/lib/csf-tools/src/CsfFile.ts b/code/lib/csf-tools/src/CsfFile.ts index 8934698f5cb8..79a47de24f87 100644 --- a/code/lib/csf-tools/src/CsfFile.ts +++ b/code/lib/csf-tools/src/CsfFile.ts @@ -326,32 +326,41 @@ export class CsfFile { } else { storyNode = decl; } - let parameters; + const parameters: { [key: string]: any } = {}; if (t.isObjectExpression(storyNode)) { - // eslint-disable-next-line @typescript-eslint/naming-convention - let __isArgsStory = true; // assume default render is an args story + parameters.__isArgsStory = true; // assume default render is an args story // CSF3 object export (storyNode.properties as t.ObjectProperty[]).forEach((p) => { if (t.isIdentifier(p.key)) { if (p.key.name === 'render') { - __isArgsStory = isArgsStory(p.value as t.Expression, parent, self); + parameters.__isArgsStory = isArgsStory( + p.value as t.Expression, + parent, + self + ); } else if (p.key.name === 'name' && t.isStringLiteral(p.value)) { name = p.value.value; } else if (p.key.name === 'storyName' && t.isStringLiteral(p.value)) { logger.warn( `Unexpected usage of "storyName" in "${exportName}". Please use "name" instead.` ); + } else if (p.key.name === 'parameters' && t.isObjectExpression(p.value)) { + const idProperty = p.value.properties.find( + (property) => + t.isObjectProperty(property) && + t.isIdentifier(property.key) && + property.key.name === '__id' + ) as t.ObjectProperty | undefined; + if (idProperty) { + parameters.__id = (idProperty.value as t.StringLiteral).value; + } } + self._storyAnnotations[exportName][p.key.name] = p.value; } }); - parameters = { __isArgsStory }; } else { - parameters = { - // __id: toId(self._meta.title, name), - // FIXME: Template.bind({}); - __isArgsStory: isArgsStory(storyNode as t.Node, parent, self), - }; + parameters.__isArgsStory = isArgsStory(storyNode as t.Node, parent, self); } self._stories[exportName] = { id: 'FIXME', @@ -477,27 +486,31 @@ export class CsfFile { self._meta.tags = [...(self._meta.tags || []), 'play-fn']; } self._stories = entries.reduce((acc, [key, story]) => { - if (isExportStory(key, self._meta as StaticMeta)) { - const id = toId((self._meta?.id || self._meta?.title) as string, storyNameFromExport(key)); - const parameters: Record = { ...story.parameters, __id: id }; - const { includeStories } = self._meta || {}; - if ( - key === '__page' && - (entries.length === 1 || (Array.isArray(includeStories) && includeStories.length === 1)) - ) { - parameters.docsOnly = true; - } - acc[key] = { ...story, id, parameters }; - const { tags, play } = self._storyAnnotations[key]; - if (tags) { - const node = t.isIdentifier(tags) - ? findVarInitialization(tags.name, this._ast.program) - : tags; - acc[key].tags = parseTags(node); - } - if (play) { - acc[key].tags = [...(acc[key].tags || []), 'play-fn']; - } + if (!isExportStory(key, self._meta as StaticMeta)) { + return acc; + } + const id = + story.parameters?.__id ?? + toId((self._meta?.id || self._meta?.title) as string, storyNameFromExport(key)); + const parameters: Record = { ...story.parameters, __id: id }; + + const { includeStories } = self._meta || {}; + if ( + key === '__page' && + (entries.length === 1 || (Array.isArray(includeStories) && includeStories.length === 1)) + ) { + parameters.docsOnly = true; + } + acc[key] = { ...story, id, parameters }; + const { tags, play } = self._storyAnnotations[key]; + if (tags) { + const node = t.isIdentifier(tags) + ? findVarInitialization(tags.name, this._ast.program) + : tags; + acc[key].tags = parseTags(node); + } + if (play) { + acc[key].tags = [...(acc[key].tags || []), 'play-fn']; } return acc; }, {} as Record); diff --git a/code/lib/preview-api/template/stories/indexer.stories.ts b/code/lib/preview-api/template/stories/indexer.stories.ts index 0bcfd98b0d85..645b6a14b3f7 100644 --- a/code/lib/preview-api/template/stories/indexer.stories.ts +++ b/code/lib/preview-api/template/stories/indexer.stories.ts @@ -8,19 +8,17 @@ export default { id: 'indexer-custom-meta-id', }; -// FIXME: fails with "Didn't find 'lib-preview-api-indexer--default' in CSF file, this is unexpected" export const Default = { play: async ({ id }: PlayFunctionContext) => { await expect(id).toBe('indexer-custom-meta-id--default'); }, }; -// FIXME: fails with Didn't find 'lib-preview-api-indexer--custom-parameters-id' in CSF file, this is unexpected export const CustomParametersId = { parameters: { __id: 'custom-id', }, play: async ({ id }: PlayFunctionContext) => { - await expect(id).toBe('indexer-custom-meta-id--custom-id'); + await expect(id).toBe('custom-id'); }, }; From cf7d4cf000eb7a67c96d3a6c48b1fe15834f3fcd Mon Sep 17 00:00:00 2001 From: Jeppe Reinhold Date: Sun, 30 Jul 2023 00:15:28 +0200 Subject: [PATCH 5/5] improve test titles --- .../core-server/src/utils/__tests__/index-extraction.test.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/code/lib/core-server/src/utils/__tests__/index-extraction.test.ts b/code/lib/core-server/src/utils/__tests__/index-extraction.test.ts index 772ac0b833e3..f58fc3907a26 100644 --- a/code/lib/core-server/src/utils/__tests__/index-extraction.test.ts +++ b/code/lib/core-server/src/utils/__tests__/index-extraction.test.ts @@ -229,7 +229,7 @@ describe('story extraction', () => { `); }); - it('auto-generates id from name, title and/or metaId inputs', async () => { + it('auto-generates id', async () => { const relativePath = './src/A.stories.js'; const absolutePath = path.join(options.workingDir, relativePath); const specifier: NormalizedStoriesSpecifier = normalizeStoriesEntry(relativePath, options); @@ -240,6 +240,7 @@ describe('story extraction', () => { { test: /\.stories\.(m?js|ts)x?$/, index: async (fileName) => [ + // exportName + title -> id { exportName: 'StoryOne', name: 'Story One', @@ -248,6 +249,7 @@ describe('story extraction', () => { importPath: fileName, type: 'story', }, + // exportName + custom title (ignoring custom name) -> id { exportName: 'StoryTwo', name: 'Custom Name For Second Story', @@ -256,6 +258,7 @@ describe('story extraction', () => { importPath: fileName, type: 'story', }, + // exportName + custom metaId (ignoring custom title and name) -> id { exportName: 'StoryThree', metaId: 'custom-meta-id',