1
1
import { getChangelogs , baseUrlMap , getChangelog } from '../changelog' ;
2
- import * as jsDelivr from '../jsDelivr' ;
3
2
4
3
jest . mock ( 'got' , ( ) => {
5
4
const gotSnapshotUrls = new Set ( [
@@ -17,12 +16,6 @@ jest.mock('got', () => {
17
16
} ;
18
17
} ) ;
19
18
20
- const spy = jest
21
- . spyOn ( jsDelivr , 'getFilesList' )
22
- . mockImplementation ( ( ) : Promise < any [ ] > => {
23
- return Promise . resolve ( [ ] ) ;
24
- } ) ;
25
-
26
19
describe ( 'should test baseUrlMap' , ( ) => {
27
20
it ( 'should work with paths' , ( ) => {
28
21
const bitbucketRepo = {
@@ -116,7 +109,7 @@ it('should handle not found changelog for github', async () => {
116
109
} ,
117
110
} ;
118
111
119
- const [ { changelogFilename } ] = await getChangelogs ( [ pkg ] ) ;
112
+ const [ { changelogFilename } ] = await getChangelogs ( [ pkg ] , [ ] ) ;
120
113
expect ( changelogFilename ) . toBe ( null ) ;
121
114
} ) ;
122
115
@@ -135,7 +128,7 @@ it('should get changelog for github', async () => {
135
128
} ,
136
129
} ;
137
130
138
- const [ { changelogFilename } ] = await getChangelogs ( [ pkg ] ) ;
131
+ const [ { changelogFilename } ] = await getChangelogs ( [ pkg ] , [ ] ) ;
139
132
expect ( changelogFilename ) . toBe (
140
133
'https://raw.githubusercontent.com/algolia/algoliasearch-netlify/master/CHANGELOG.md'
141
134
) ;
@@ -148,7 +141,7 @@ it('should get changelog from unpkg if there is no repository field', async () =
148
141
repository : null ,
149
142
} ;
150
143
151
- const [ { changelogFilename } ] = await getChangelogs ( [ pkg ] ) ;
144
+ const [ { changelogFilename } ] = await getChangelogs ( [ pkg ] , [ ] ) ;
152
145
153
146
expect ( changelogFilename ) . toBe (
154
147
'https://unpkg.com/@atlaskit/button@13.3.7/CHANGELOG.md'
@@ -170,7 +163,7 @@ it('should get changelog for gitlab', async () => {
170
163
} ,
171
164
} ;
172
165
173
- const [ { changelogFilename } ] = await getChangelogs ( [ pkg ] ) ;
166
+ const [ { changelogFilename } ] = await getChangelogs ( [ pkg ] , [ ] ) ;
174
167
expect ( changelogFilename ) . toBe (
175
168
'https://gitlab.com/janslow/gitlab-fetch/raw/master/CHANGELOG.md'
176
169
) ;
@@ -191,7 +184,7 @@ it('should get changelog for bitbucket', async () => {
191
184
} ,
192
185
} ;
193
186
194
- const [ { changelogFilename } ] = await getChangelogs ( [ pkg ] ) ;
187
+ const [ { changelogFilename } ] = await getChangelogs ( [ pkg ] , [ ] ) ;
195
188
expect ( changelogFilename ) . toBe (
196
189
'https://bitbucket.org/atlassian/aui/raw/master/changelog.md'
197
190
) ;
@@ -212,81 +205,77 @@ it('should work with HISTORY.md', async () => {
212
205
} ,
213
206
} ;
214
207
215
- const [ { changelogFilename } ] = await getChangelogs ( [ pkg ] ) ;
208
+ const [ { changelogFilename } ] = await getChangelogs ( [ pkg ] , [ ] ) ;
216
209
expect ( changelogFilename ) . toBe (
217
210
'https://raw.githubusercontent.com/expressjs/body-parser/master/HISTORY.md'
218
211
) ;
219
212
} ) ;
220
213
221
214
describe ( 'jsDelivr' , ( ) => {
222
215
it ( 'should early return when finding changelog' , async ( ) => {
223
- spy . mockResolvedValue ( [
224
- { name : '/package.json' , hash : '' , time : '1' , size : 1 } ,
225
- { name : '/CHANGELOG.md' , hash : '' , time : '1' , size : 1 } ,
226
- ] ) ;
227
-
228
- const { changelogFilename } = await getChangelog ( {
229
- name : 'foo' ,
230
- version : '1.0.0' ,
231
- repository : {
232
- url : '' ,
233
- host : 'github.com' ,
234
- user : 'expressjs' ,
235
- project : 'body-parser' ,
236
- path : '' ,
237
- head : 'master' ,
238
- branch : 'master' ,
216
+ const { changelogFilename } = await getChangelog (
217
+ {
218
+ name : 'foo' ,
219
+ version : '1.0.0' ,
220
+ repository : {
221
+ url : '' ,
222
+ host : 'github.com' ,
223
+ user : 'expressjs' ,
224
+ project : 'body-parser' ,
225
+ path : '' ,
226
+ head : 'master' ,
227
+ branch : 'master' ,
228
+ } ,
239
229
} ,
240
- } ) ;
241
- expect ( jsDelivr . getFilesList ) . toHaveBeenCalled ( ) ;
230
+ [
231
+ { name : '/package.json' , hash : '' , time : '1' , size : 1 } ,
232
+ { name : '/CHANGELOG.md' , hash : '' , time : '1' , size : 1 } ,
233
+ ]
234
+ ) ;
242
235
expect ( changelogFilename ) . toEqual (
243
236
'https://cdn.jsdelivr.net/npm/foo@1.0.0/CHANGELOG.md'
244
237
) ;
245
238
} ) ;
246
239
247
240
it ( 'should early return when finding changelog in nested file' , async ( ) => {
248
- spy . mockResolvedValue ( [
249
- { name : '/pkg/CHANGELOG.md' , hash : '' , time : '1' , size : 1 } ,
250
- ] ) ;
251
-
252
- const { changelogFilename } = await getChangelog ( {
253
- name : 'foo' ,
254
- version : '1.0.0' ,
255
- repository : {
256
- url : '' ,
257
- host : 'github.com' ,
258
- user : 'expressjs' ,
259
- project : 'body-parser' ,
260
- path : '' ,
261
- head : 'master' ,
262
- branch : 'master' ,
241
+ const { changelogFilename } = await getChangelog (
242
+ {
243
+ name : 'foo' ,
244
+ version : '1.0.0' ,
245
+ repository : {
246
+ url : '' ,
247
+ host : 'github.com' ,
248
+ user : 'expressjs' ,
249
+ project : 'body-parser' ,
250
+ path : '' ,
251
+ head : 'master' ,
252
+ branch : 'master' ,
253
+ } ,
263
254
} ,
264
- } ) ;
265
- expect ( jsDelivr . getFilesList ) . toHaveBeenCalled ( ) ;
255
+ [ { name : '/pkg/CHANGELOG.md' , hash : '' , time : '1' , size : 1 } ]
256
+ ) ;
266
257
expect ( changelogFilename ) . toEqual (
267
258
'https://cdn.jsdelivr.net/npm/foo@1.0.0/pkg/CHANGELOG.md'
268
259
) ;
269
260
} ) ;
270
261
271
262
it ( 'should not register a file looking like a changelog' , async ( ) => {
272
- spy . mockResolvedValue ( [
273
- { name : '/dist/changelog.js' , hash : '' , time : '1' , size : 1 } ,
274
- ] ) ;
275
-
276
- const { changelogFilename } = await getChangelog ( {
277
- name : 'foo' ,
278
- version : '1.0.0' ,
279
- repository : {
280
- url : '' ,
281
- host : 'github.com' ,
282
- user : 'hello' ,
283
- project : 'foo' ,
284
- path : '' ,
285
- head : 'master' ,
286
- branch : 'master' ,
263
+ const { changelogFilename } = await getChangelog (
264
+ {
265
+ name : 'foo' ,
266
+ version : '1.0.0' ,
267
+ repository : {
268
+ url : '' ,
269
+ host : 'github.com' ,
270
+ user : 'hello' ,
271
+ project : 'foo' ,
272
+ path : '' ,
273
+ head : 'master' ,
274
+ branch : 'master' ,
275
+ } ,
287
276
} ,
288
- } ) ;
289
- expect ( jsDelivr . getFilesList ) . toHaveBeenCalled ( ) ;
277
+ [ { name : '/dist/changelog.js' , hash : '' , time : '1' , size : 1 } ]
278
+ ) ;
290
279
expect ( changelogFilename ) . toEqual ( null ) ;
291
280
} ) ;
292
281
} ) ;
0 commit comments