@@ -16,14 +16,16 @@ const {
1616
1717const getPackagesMock = jest . fn ( ) ;
1818const execSync = jest . fn ( ) ;
19- const spawnSync = jest . fn ( ) ;
2019const execMock = jest . fn ( ) ;
20+ const fetchMock = jest . fn ( ) ;
2121
22- jest . mock ( 'child_process' , ( ) => ( { execSync, spawnSync } ) ) ;
22+ jest . mock ( 'child_process' , ( ) => ( { execSync} ) ) ;
2323jest . mock ( 'shelljs' , ( ) => ( { exec : execMock } ) ) ;
2424jest . mock ( '../../releases/utils/monorepo' , ( ) => ( {
2525 getPackages : getPackagesMock ,
2626} ) ) ;
27+ // $FlowIgnore[cannot-write]
28+ global . fetch = fetchMock ;
2729
2830const BUMP_COMMIT_MESSAGE =
2931 'bumped packages versions\n\n#publish-packages-to-npm' ;
@@ -76,7 +78,7 @@ describe('findAndPublishAllBumpedPackages', () => {
7678 ` ) ;
7779 } ) ;
7880
79- test ( 'should throw an error if updated version is not 0.x.y ' , async ( ) => {
81+ test ( 'should throw an error if updated version is not 0.x.x ' , async ( ) => {
8082 execSync . mockImplementation ( ( command : string ) => {
8183 switch ( command ) {
8284 case 'git log -1 --pretty=%B' :
@@ -93,16 +95,16 @@ describe('findAndPublishAllBumpedPackages', () => {
9395 } ,
9496 } ) ;
9597
96- spawnSync . mockImplementationOnce ( ( ) => ( {
97- stdout : `- "version": "0.72.0"\n+ "version": " ${ mockedPackageNewVersion } "\n` ,
98- } ) ) ;
98+ fetchMock . mockResolvedValueOnce ( {
99+ json : ( ) => Promise . resolve ( { versions : { } } ) ,
100+ } ) ;
99101
100102 await expect ( findAndPublishAllBumpedPackages ( ) ) . rejects . toThrow (
101- `Package version expected to be 0.x.y , but received ${ mockedPackageNewVersion } ` ,
103+ `Package version expected to be 0.x.x , but received ${ mockedPackageNewVersion } ` ,
102104 ) ;
103105 } ) ;
104106
105- test ( 'should publish all changed packages' , async ( ) => {
107+ test ( 'should publish all updated packages' , async ( ) => {
106108 execSync . mockImplementation ( ( command : string ) => {
107109 switch ( command ) {
108110 case 'git log -1 --pretty=%B' :
@@ -111,39 +113,48 @@ describe('findAndPublishAllBumpedPackages', () => {
111113 } ) ;
112114 getPackagesMock . mockResolvedValue ( {
113115 '@react-native/package-a' : {
116+ name : '@react-native/package-a' ,
114117 path : 'absolute/path/to/package-a' ,
115118 packageJson : {
116119 version : '0.72.1' ,
117120 } ,
118121 } ,
119122 '@react-native/package-b' : {
123+ name : '@react-native/package-b' ,
120124 path : 'absolute/path/to/package-b' ,
121125 packageJson : {
122126 version : '0.72.1' ,
123127 } ,
124128 } ,
125129 '@react-native/package-c' : {
130+ name : '@react-native/package-c' ,
126131 path : 'absolute/path/to/package-c' ,
127132 packageJson : {
128133 version : '0.72.0' ,
129134 } ,
130135 } ,
131136 } ) ;
132-
133- spawnSync . mockImplementationOnce ( ( ) => ( {
134- stdout : `- "version": "0.72.0"\n+ "version": "0.72.1"\n` ,
135- } ) ) ;
136- spawnSync . mockImplementationOnce ( ( ) => ( {
137- stdout : `- "version": "0.72.0"\n+ "version": "0.72.1"\n` ,
138- } ) ) ;
139- spawnSync . mockImplementationOnce ( ( ) => ( {
140- stdout : '\n' ,
141- } ) ) ;
142-
137+ fetchMock . mockResolvedValue ( {
138+ json : ( ) =>
139+ Promise . resolve ( {
140+ versions : { '0.72.0' : { } } ,
141+ } ) ,
142+ } ) ;
143143 execMock . mockImplementation ( ( ) => ( { code : 0 } ) ) ;
144144
145+ const consoleLog = jest . spyOn ( console , 'log' ) . mockImplementation ( ( ) => { } ) ;
146+
145147 await findAndPublishAllBumpedPackages ( ) ;
146148
149+ expect ( consoleLog . mock . calls . flat ( ) . join ( '\n' ) ) . toMatchInlineSnapshot ( `
150+ "Discovering updated packages
151+ - Skipping @react-native/package-c (0.72.0 already present on npm)
152+ Done ✅
153+ Publishing updated packages to npm
154+ - Publishing @react-native/package-a (0.72.1)
155+ - Publishing @react-native/package-b (0.72.1)
156+ Done ✅"
157+ ` ) ;
147158 expect ( execMock . mock . calls ) . toMatchInlineSnapshot ( `
148159 Array [
149160 Array [
0 commit comments