-
-
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.
CLI: Add Storyshots migration notice
- Loading branch information
Showing
7 changed files
with
98 additions
and
18 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
60 changes: 60 additions & 0 deletions
60
code/lib/cli/src/automigrate/fixes/storyshots-migration.test.ts
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,60 @@ | ||
import { describe, afterEach, it, expect, vi } from 'vitest'; | ||
|
||
import type { StorybookConfig } from '@storybook/types'; | ||
import { storyshotsMigration } from './storyshots-migration'; | ||
import type { JsPackageManager } from '../../js-package-manager'; | ||
|
||
const check = async ({ | ||
packageManager, | ||
main: mainConfig = {}, | ||
storybookVersion = '8.0.0', | ||
}: { | ||
packageManager: Partial<JsPackageManager>; | ||
main?: Partial<StorybookConfig> & Record<string, unknown>; | ||
storybookVersion?: string; | ||
}) => { | ||
return storyshotsMigration.check({ | ||
packageManager: packageManager as any, | ||
configDir: '', | ||
mainConfig: mainConfig as any, | ||
storybookVersion, | ||
}); | ||
}; | ||
|
||
describe('storyshots-migration fix', () => { | ||
afterEach(() => { | ||
vi.restoreAllMocks(); | ||
}); | ||
|
||
it('should detect storyshots registered in main.js', async () => { | ||
await expect( | ||
check({ | ||
packageManager: { | ||
getAllDependencies: async () => ({}), | ||
}, | ||
main: { addons: ['@storybook/addon-storyshots'] }, | ||
}) | ||
).resolves.toBeTruthy(); | ||
}); | ||
|
||
it('should detect storyshots in package.json', async () => { | ||
await expect( | ||
check({ | ||
packageManager: { | ||
getAllDependencies: async () => ({ '@storybook/addon-storyshots': '7.0.0' }), | ||
}, | ||
}) | ||
).resolves.toBeTruthy(); | ||
}); | ||
|
||
it('no-op when storyshots is not present', async () => { | ||
await expect( | ||
check({ | ||
packageManager: { | ||
getAllDependencies: async () => ({}), | ||
}, | ||
main: { addons: ['@storybook/essentials'] }, | ||
}) | ||
).resolves.toBeNull(); | ||
}); | ||
}); |
30 changes: 30 additions & 0 deletions
30
code/lib/cli/src/automigrate/fixes/storyshots-migration.ts
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,30 @@ | ||
import chalk from 'chalk'; | ||
import dedent from 'ts-dedent'; | ||
import type { Fix } from '../types'; | ||
|
||
export const storyshotsMigration: Fix = { | ||
id: 'storyshots-migration', | ||
promptOnly: true, | ||
|
||
async check({ mainConfig, packageManager }) { | ||
const allDeps = await packageManager.getAllDependencies(); | ||
const hasStoryshots = | ||
allDeps['@storybook/addon-storyshots'] || | ||
mainConfig.addons?.find((addon) => { | ||
const addonName = typeof addon === 'string' ? addon : addon.name; | ||
return addonName.includes('@storybook/addon-storyshots'); | ||
}); | ||
|
||
return hasStoryshots ?? null; | ||
}, | ||
prompt() { | ||
return dedent` | ||
${chalk.bold( | ||
'Attention' | ||
)}: Storyshots is now officially deprecated, is no longer being maintained, and was removed in Storybook 8. | ||
We recommend following the migration guide we've prepared to help you during this transition period: | ||
${chalk.yellow('https://storybook.js.org/docs/writing-tests/storyshots-migration-guide')} | ||
`; | ||
}, | ||
}; |
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