Skip to content

Commit 424d522

Browse files
Update configureMain to support dynamic story paths and add tests for docs feature
1 parent 1aace04 commit 424d522

File tree

2 files changed

+41
-5
lines changed

2 files changed

+41
-5
lines changed

code/lib/create-storybook/src/generators/configure.test.ts

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ describe('configureMain', () => {
2626
name: '@storybook/react-vite',
2727
},
2828
frameworkPackage: '@storybook/react-vite',
29+
features: [],
2930
});
3031

3132
const { calls } = vi.mocked(fsp.writeFile).mock;
@@ -50,7 +51,7 @@ describe('configureMain', () => {
5051
`);
5152
});
5253

53-
it('should generate main.ts', async () => {
54+
it('should generate main.ts with docs feature', async () => {
5455
await configureMain({
5556
language: SupportedLanguage.TYPESCRIPT,
5657
addons: [],
@@ -60,6 +61,41 @@ describe('configureMain', () => {
6061
name: '@storybook/react-vite',
6162
},
6263
frameworkPackage: '@storybook/react-vite',
64+
features: ['docs'],
65+
});
66+
67+
const { calls } = vi.mocked(fsp.writeFile).mock;
68+
const [mainConfigPath, mainConfigContent] = calls[0];
69+
70+
expect(mainConfigPath).toEqual('./.storybook/main.ts');
71+
expect(mainConfigContent).toMatchInlineSnapshot(`
72+
"import type { StorybookConfig } from '@storybook/react-vite';
73+
74+
const config: StorybookConfig = {
75+
"stories": [
76+
"../stories/**/*.stories.@(js|jsx|mjs|ts|tsx)",
77+
"../stories/**/*.mdx"
78+
],
79+
"addons": [],
80+
"framework": {
81+
"name": "@storybook/react-vite"
82+
}
83+
};
84+
export default config;"
85+
`);
86+
});
87+
88+
it('should generate main.ts without docs feature', async () => {
89+
await configureMain({
90+
language: SupportedLanguage.TYPESCRIPT,
91+
addons: [],
92+
prefixes: [],
93+
storybookConfigFolder: '.storybook',
94+
framework: {
95+
name: '@storybook/react-vite',
96+
},
97+
frameworkPackage: '@storybook/react-vite',
98+
features: [],
6399
});
64100

65101
const { calls } = vi.mocked(fsp.writeFile).mock;
@@ -71,7 +107,6 @@ describe('configureMain', () => {
71107
72108
const config: StorybookConfig = {
73109
"stories": [
74-
"../stories/**/*.mdx",
75110
"../stories/**/*.stories.@(js|jsx|mjs|ts|tsx)"
76111
],
77112
"addons": [],
@@ -96,6 +131,7 @@ describe('configureMain', () => {
96131
name: "%%path.dirname(require.resolve(path.join('@storybook/react-webpack5', 'package.json')))%%",
97132
},
98133
frameworkPackage: '@storybook/react-webpack5',
134+
features: ['docs'],
99135
});
100136

101137
const { calls } = vi.mocked(fsp.writeFile).mock;
@@ -108,8 +144,8 @@ describe('configureMain', () => {
108144
/** @type { import('@storybook/react-webpack5').StorybookConfig } */
109145
const config = {
110146
"stories": [
111-
"../stories/**/*.mdx",
112-
"../stories/**/*.stories.@(js|jsx|mjs|ts|tsx)"
147+
"../stories/**/*.stories.@(js|jsx|mjs|ts|tsx)",
148+
"../stories/**/*.mdx"
113149
],
114150
"addons": [
115151
path.dirname(require.resolve(path.join('@storybook/addon-essentials', 'package.json'))),

code/lib/create-storybook/src/generators/configure.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export async function configureMain({
5656
}: ConfigureMainOptions) {
5757
const srcPath = resolve(storybookConfigFolder, '../src');
5858
const prefix = (await pathExists(srcPath)) ? '../src' : '../stories';
59-
const stories = [`**/*.stories.@(${extensions.join('|')})`];
59+
const stories = [`${prefix}/**/*.stories.@(${extensions.join('|')})`];
6060

6161
if (features.includes('docs')) {
6262
stories.push(`${prefix}/**/*.mdx`);

0 commit comments

Comments
 (0)