mirror of
https://github.com/storybookjs/storybook.git
synced 2025-03-16 05:03:11 +08:00
Throw proper error if you try and index an MDX file in ssv6
This commit is contained in:
parent
e0ee29c2bf
commit
783379bcb0
@ -141,7 +141,15 @@ export class StoryStoreFacade<TRenderer extends Renderer> {
|
||||
// NOTE: we could potentially share some of this code with the stories.json generation
|
||||
addStoriesFromExports(fileName: Path, fileExports: ModuleExports) {
|
||||
if (fileName.match(/\.mdx$/) && !fileName.match(/\.stories\.mdx$/)) {
|
||||
return;
|
||||
throw new Error(dedent`
|
||||
Cannot index \`.mdx\` file (\`${fileName}\`) in \`storyStoreV7: false\` mode.
|
||||
|
||||
The legacy story store does not support new-style \`.mdx\` files. If the file above
|
||||
is not intended to be indexed (i.e. displayed as an entry in the sidebar), either
|
||||
exclude it from your \`stories\` glob, or add <Meta isTemplate /> to it.
|
||||
|
||||
If you wanted to index the file, you'll need to name it \`stories.mdx\` and stick to the
|
||||
legacy (6.x) MDX API, or use the new store.`);
|
||||
}
|
||||
|
||||
// if the export haven't changed since last time we added them, this is a no-op
|
||||
|
@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
// import { describe, it, beforeAll, beforeEach, afterAll, afterEach, jest } from '@jest/globals';
|
||||
import { STORY_RENDERED, STORY_UNCHANGED, SET_INDEX } from '@storybook/core-events';
|
||||
import { STORY_RENDERED, STORY_UNCHANGED, SET_INDEX, CONFIG_ERROR } from '@storybook/core-events';
|
||||
|
||||
import type { ModuleExports, Path } from '@storybook/types';
|
||||
import { global } from '@storybook/global';
|
||||
@ -1005,6 +1005,34 @@ describe('start', () => {
|
||||
// Wait a second to let the docs "render" finish (and maybe throw)
|
||||
await waitForQuiescence();
|
||||
});
|
||||
|
||||
it('errors on .mdx files', async () => {
|
||||
const renderToCanvas = jest.fn();
|
||||
|
||||
const { configure } = start(renderToCanvas);
|
||||
|
||||
configure(
|
||||
'test',
|
||||
makeRequireContext({
|
||||
'./Introduction.mdx': {
|
||||
default: () => 'some mdx function',
|
||||
},
|
||||
})
|
||||
);
|
||||
|
||||
await waitForEvents([CONFIG_ERROR]);
|
||||
expect(mockChannel.emit.mock.calls.find((call) => call[0] === CONFIG_ERROR)?.[1])
|
||||
.toMatchInlineSnapshot(`
|
||||
[Error: Cannot index \`.mdx\` file (\`./Introduction.mdx\`) in \`storyStoreV7: false\` mode.
|
||||
|
||||
The legacy story store does not support new-style \`.mdx\` files. If the file above
|
||||
is not intended to be indexed (i.e. displayed as an entry in the sidebar), either
|
||||
exclude it from your \`stories\` glob, or add <Meta isTemplate /> to it.
|
||||
|
||||
If you wanted to index the file, you'll need to name it \`stories.mdx\` and stick to the
|
||||
legacy (6.x) MDX API, or use the new store.]
|
||||
`);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user