@@ -12,7 +12,19 @@ jest.mock('../../../code/lib/cli/src/versions', () => ({
1212} ) ) ;
1313
1414jest . mock ( '../../utils/exec' ) ;
15- const { execaCommand } = require ( '../../utils/exec' ) ;
15+
16+ jest . mock ( '../../utils/workspace' , ( ) => ( {
17+ getWorkspaces : jest . fn ( ) . mockResolvedValue ( [
18+ {
19+ name : '@storybook/addon-a11y' ,
20+ location : 'addons/a11y' ,
21+ } ,
22+ ] ) ,
23+ } ) ) ;
24+
25+ jest . spyOn ( console , 'log' ) . mockImplementation ( ( ) => { } ) ;
26+ jest . spyOn ( console , 'warn' ) . mockImplementation ( ( ) => { } ) ;
27+ jest . spyOn ( console , 'error' ) . mockImplementation ( ( ) => { } ) ;
1628
1729beforeEach ( ( ) => {
1830 jest . clearAllMocks ( ) ;
@@ -29,6 +41,7 @@ describe('Version', () => {
2941 'version.ts'
3042 ) ;
3143 const VERSIONS_PATH = path . join ( CODE_DIR_PATH , 'lib' , 'cli' , 'src' , 'versions.ts' ) ;
44+ const A11Y_PACKAGE_JSON_PATH = path . join ( CODE_DIR_PATH , 'addons' , 'a11y' , 'package.json' ) ;
3245
3346 it ( 'should throw when release type is invalid' , async ( ) => {
3447 fsExtra . __setMockFiles ( {
@@ -152,6 +165,23 @@ describe('Version', () => {
152165 [ CODE_PACKAGE_JSON_PATH ] : JSON . stringify ( { version : currentVersion } ) ,
153166 [ MANAGER_API_VERSION_PATH ] : `export const version = "${ currentVersion } ";` ,
154167 [ VERSIONS_PATH ] : `export default { "@storybook/addon-a11y": "${ currentVersion } " };` ,
168+ [ A11Y_PACKAGE_JSON_PATH ] : JSON . stringify ( {
169+ version : currentVersion ,
170+ dependencies : {
171+ '@storybook/core-server' : currentVersion ,
172+ 'unrelated-package-a' : '1.0.0' ,
173+ } ,
174+ devDependencies : {
175+ 'unrelated-package-b' : currentVersion ,
176+ '@storybook/core-common' : `^${ currentVersion } ` ,
177+ } ,
178+ peerDependencies : {
179+ '@storybook/preview-api' : `*` ,
180+ '@storybook/svelte' : '0.1.1' ,
181+ '@storybook/manager-api' : `~${ currentVersion } ` ,
182+ } ,
183+ } ) ,
184+ [ VERSIONS_PATH ] : `export default { "@storybook/addon-a11y": "${ currentVersion } " };` ,
155185 } ) ;
156186
157187 await version ( { releaseType, preId, exact } ) ;
@@ -161,18 +191,38 @@ describe('Version', () => {
161191 { version : expectedVersion } ,
162192 { spaces : 2 }
163193 ) ;
164- expect ( fsExtra . writeFile ) . toHaveBeenCalledWith (
165- path . join ( CODE_DIR_PATH , '.yarn' , 'versions' , 'generated-by-versions-script.yml' ) ,
166- expect . stringContaining ( expectedVersion )
167- ) ;
168- expect ( execaCommand ) . toHaveBeenCalledWith ( 'yarn version apply --all' , { cwd : CODE_DIR_PATH } ) ;
169194 expect ( fsExtra . writeFile ) . toHaveBeenCalledWith (
170195 MANAGER_API_VERSION_PATH ,
171- expect . stringContaining ( expectedVersion )
196+ `export const version = " ${ expectedVersion } ";`
172197 ) ;
173198 expect ( fsExtra . writeFile ) . toHaveBeenCalledWith (
174199 VERSIONS_PATH ,
175- expect . stringContaining ( expectedVersion )
200+ `export default { "@storybook/addon-a11y": "${ expectedVersion } " };`
201+ ) ;
202+ expect ( fsExtra . writeJson ) . toHaveBeenCalledWith (
203+ A11Y_PACKAGE_JSON_PATH ,
204+ expect . objectContaining ( {
205+ // should update package version
206+ version : expectedVersion ,
207+ dependencies : {
208+ // should update storybook dependencies matching current version
209+ '@storybook/core-server' : expectedVersion ,
210+ 'unrelated-package-a' : '1.0.0' ,
211+ } ,
212+ devDependencies : {
213+ // should not update non-storybook dependencies, even if they match current version
214+ 'unrelated-package-b' : currentVersion ,
215+ // should update dependencies with range modifiers correctly (e.g. ^1.0.0 -> ^2.0.0)
216+ '@storybook/core-common' : `^${ expectedVersion } ` ,
217+ } ,
218+ peerDependencies : {
219+ // should not update storybook depenedencies if they don't match current version
220+ '@storybook/preview-api' : `*` ,
221+ '@storybook/svelte' : '0.1.1' ,
222+ '@storybook/manager-api' : `~${ expectedVersion } ` ,
223+ } ,
224+ } ) ,
225+ { spaces : 2 }
176226 ) ;
177227 }
178228 ) ;
0 commit comments