7
7
* @format
8
8
*/
9
9
10
- const { generateChangelog,
10
+ const {
11
+ generateChangelog,
11
12
_computePreviousVersionFrom,
12
13
_generateChangelog,
13
14
_pushCommit,
14
- _createPR } = require ( '../generateChangelog' ) ;
15
+ _createPR,
16
+ } = require ( '../generateChangelog' ) ;
15
17
16
18
const silence = ( ) => { } ;
17
19
const mockGetNpmPackageInfo = jest . fn ( ) ;
@@ -40,27 +42,29 @@ describe('Generate Changelog', () => {
40
42
const receivedVersion = await _computePreviousVersionFrom ( currentVersion ) ;
41
43
42
44
expect ( receivedVersion ) . toEqual ( expectedVersion ) ;
43
- } )
45
+ } ) ;
44
46
45
- it ( 'returns previous rc version when rc is > 1' , async ( ) => {
47
+ it ( 'returns previous rc version when rc is > 1' , async ( ) => {
46
48
const currentVersion = '0.78.0-rc.5' ;
47
49
const expectedVersion = '0.78.0-rc.4' ;
48
50
49
51
const receivedVersion = await _computePreviousVersionFrom ( currentVersion ) ;
50
52
51
53
expect ( receivedVersion ) . toEqual ( expectedVersion ) ;
52
- } )
54
+ } ) ;
53
55
54
56
it ( 'returns previous patch version when rc is 0' , async ( ) => {
55
57
const currentVersion = '0.78.0-rc.0' ;
56
58
const expectedVersion = '0.77.1' ;
57
59
58
- mockGetNpmPackageInfo . mockReturnValueOnce ( Promise . resolve ( { version : '0.77.1' } ) ) ;
60
+ mockGetNpmPackageInfo . mockReturnValueOnce (
61
+ Promise . resolve ( { version : '0.77.1' } ) ,
62
+ ) ;
59
63
60
64
const receivedVersion = await _computePreviousVersionFrom ( currentVersion ) ;
61
65
62
66
expect ( receivedVersion ) . toEqual ( expectedVersion ) ;
63
- } )
67
+ } ) ;
64
68
65
69
it ( 'returns patch 0 when patch is 1' , async ( ) => {
66
70
const currentVersion = '0.78.1' ;
@@ -88,10 +92,12 @@ describe('Generate Changelog', () => {
88
92
expect ( receivedVersion ) . toBeNull ( ) ;
89
93
} ) ;
90
94
91
- it ( ' throws an error when the version can\ 't be parsed' , async ( ) => {
95
+ it ( " throws an error when the version can't be parsed" , async ( ) => {
92
96
const currentVersion = '0.78.0-rc0' ;
93
97
94
- await expect ( _computePreviousVersionFrom ( currentVersion ) ) . rejects . toThrow ( ) ;
98
+ await expect (
99
+ _computePreviousVersionFrom ( currentVersion ) ,
100
+ ) . rejects . toThrow ( ) ;
95
101
} ) ;
96
102
} ) ;
97
103
@@ -121,7 +127,10 @@ describe('Generate Changelog', () => {
121
127
expect ( mockRun ) . toHaveBeenNthCalledWith ( 1 , 'git checkout main' ) ;
122
128
expect ( mockRun ) . toHaveBeenNthCalledWith ( 2 , 'git fetch' ) ;
123
129
expect ( mockRun ) . toHaveBeenNthCalledWith ( 3 , 'git pull origin main' ) ;
124
- expect ( mockRun ) . toHaveBeenNthCalledWith ( 4 , `npx ${ expectedCommandArgs . join ( ' ' ) } ` ) ;
130
+ expect ( mockRun ) . toHaveBeenNthCalledWith (
131
+ 4 ,
132
+ `npx ${ expectedCommandArgs . join ( ' ' ) } ` ,
133
+ ) ;
125
134
} ) ;
126
135
} ) ;
127
136
@@ -132,10 +141,19 @@ describe('Generate Changelog', () => {
132
141
_pushCommit ( currentVersion ) ;
133
142
134
143
expect ( mockRun ) . toHaveBeenCalledTimes ( 4 ) ;
135
- expect ( mockRun ) . toHaveBeenNthCalledWith ( 1 , `git checkout -b changelog/v${ currentVersion } ` ) ;
144
+ expect ( mockRun ) . toHaveBeenNthCalledWith (
145
+ 1 ,
146
+ `git checkout -b changelog/v${ currentVersion } ` ,
147
+ ) ;
136
148
expect ( mockRun ) . toHaveBeenNthCalledWith ( 2 , 'git add CHANGELOG.md' ) ;
137
- expect ( mockRun ) . toHaveBeenNthCalledWith ( 3 , `git commit -m "[RN][Changelog] Add changelog for v${ currentVersion } "` ) ;
138
- expect ( mockRun ) . toHaveBeenNthCalledWith ( 4 , `git push origin changelog/v${ currentVersion } ` ) ;
149
+ expect ( mockRun ) . toHaveBeenNthCalledWith (
150
+ 3 ,
151
+ `git commit -m "[RN][Changelog] Add changelog for v${ currentVersion } "` ,
152
+ ) ;
153
+ expect ( mockRun ) . toHaveBeenNthCalledWith (
154
+ 4 ,
155
+ `git push origin changelog/v${ currentVersion } ` ,
156
+ ) ;
139
157
} ) ;
140
158
} ) ;
141
159
@@ -147,10 +165,10 @@ describe('Generate Changelog', () => {
147
165
mockFetch . mockReturnValueOnce ( Promise . resolve ( { status : 401 } ) ) ;
148
166
149
167
const headers = {
150
- ' Accept' : 'Accept: application/vnd.github+json' ,
168
+ Accept : 'Accept: application/vnd.github+json' ,
151
169
'X-GitHub-Api-Version' : '2022-11-28' ,
152
170
Authorization : `Bearer ${ token } ` ,
153
- }
171
+ } ;
154
172
155
173
const content = `
156
174
## Summary
@@ -160,7 +178,7 @@ Add Changelog for ${currentVersion}
160
178
[Internal] - Add Changelog for ${ currentVersion }
161
179
162
180
## Test Plan:
163
- N/A`
181
+ N/A` ;
164
182
165
183
const body = {
166
184
title : `[RN][Changelog] Add changelog for v${ currentVersion } ` ,
@@ -178,25 +196,26 @@ N/A`
178
196
method : 'POST' ,
179
197
headers : headers ,
180
198
body : JSON . stringify ( body ) ,
181
- }
199
+ } ,
182
200
) ;
183
201
} ) ;
184
202
it ( 'Returns the pr url' , async ( ) => {
185
203
const currentVersion = '0.79.0-rc5' ;
186
204
const token = 'token' ;
187
- const expectedPrURL = 'https://github.com/facebook/react-native/pulls/1234' ;
205
+ const expectedPrURL =
206
+ 'https://github.com/facebook/react-native/pulls/1234' ;
188
207
189
208
const returnedObject = {
190
209
status : 201 ,
191
210
json : ( ) => Promise . resolve ( { html_url : expectedPrURL } ) ,
192
- }
211
+ } ;
193
212
mockFetch . mockReturnValueOnce ( Promise . resolve ( returnedObject ) ) ;
194
213
195
214
const headers = {
196
- ' Accept' : 'Accept: application/vnd.github+json' ,
215
+ Accept : 'Accept: application/vnd.github+json' ,
197
216
'X-GitHub-Api-Version' : '2022-11-28' ,
198
217
Authorization : `Bearer ${ token } ` ,
199
- }
218
+ } ;
200
219
201
220
const content = `
202
221
## Summary
@@ -206,7 +225,7 @@ Add Changelog for ${currentVersion}
206
225
[Internal] - Add Changelog for ${ currentVersion }
207
226
208
227
## Test Plan:
209
- N/A`
228
+ N/A` ;
210
229
211
230
const body = {
212
231
title : `[RN][Changelog] Add changelog for v${ currentVersion } ` ,
215
234
body : content ,
216
235
} ;
217
236
218
- const receivedPrURL = await _createPR ( currentVersion , token )
237
+ const receivedPrURL = await _createPR ( currentVersion , token ) ;
219
238
220
239
expect ( mockFetch ) . toHaveBeenCalledTimes ( 1 ) ;
221
240
expect ( mockFetch ) . toHaveBeenCalledWith (
224
243
method : 'POST' ,
225
244
headers : headers ,
226
245
body : JSON . stringify ( body ) ,
227
- }
246
+ } ,
228
247
) ;
229
248
expect ( receivedPrURL ) . toEqual ( expectedPrURL ) ;
230
249
} ) ;
0 commit comments