-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21168 from storybookjs/fix/refactor-automigrations
CLI: Improve how automigrations read `main.js`
- Loading branch information
Showing
29 changed files
with
390 additions
and
465 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import type { StorybookConfig } from '@storybook/types'; | ||
import type { PackageJson } from '../../js-package-manager'; | ||
import { autodocsTrue } from './autodocs-true'; | ||
import { makePackageManager, mockStorybookData } from '../helpers/testing-helpers'; | ||
|
||
const checkAutodocs = async ({ | ||
packageJson = {}, | ||
main: mainConfig, | ||
storybookVersion = '7.0.0', | ||
}: { | ||
packageJson?: PackageJson; | ||
main: Partial<StorybookConfig> & Record<string, unknown>; | ||
storybookVersion?: string; | ||
}) => { | ||
mockStorybookData({ mainConfig, storybookVersion }); | ||
|
||
return autodocsTrue.check({ | ||
packageManager: makePackageManager(packageJson), | ||
}); | ||
}; | ||
|
||
describe('autodocs-true fix', () => { | ||
afterEach(jest.restoreAllMocks); | ||
|
||
it('should skip when docs.autodocs is already defined', async () => { | ||
await expect(checkAutodocs({ main: { docs: { autodocs: 'tag' } } })).resolves.toBeFalsy(); | ||
}); | ||
|
||
it('should throw when docs.docsPage contains invalid value', async () => { | ||
const main = { docs: { docsPage: 123 } } as any; | ||
await expect(checkAutodocs({ main })).rejects.toThrow(); | ||
}); | ||
|
||
it('should prompt when using docs.docsPage legacy property', async () => { | ||
const main = { docs: { docsPage: true } } as any; | ||
await expect(checkAutodocs({ main })).resolves.toEqual({ | ||
value: 'tag', | ||
}); | ||
}); | ||
|
||
it('should prompt when not using docs.autodocs', async () => { | ||
await expect(checkAutodocs({ main: {} })).resolves.toEqual({ | ||
value: true, | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.