@@ -270,3 +270,80 @@ t.test('string methods populate correctly', t => {
270
270
271
271
t . end ( )
272
272
} )
273
+
274
+ t . test ( 'from manifest' , t => {
275
+ t . equal ( HostedGit . fromManifest ( ) , undefined , 'no manifest returns undefined' )
276
+ t . equal ( HostedGit . fromManifest ( ) , undefined , 'no manifest returns undefined' )
277
+ t . equal ( HostedGit . fromManifest ( false ) , undefined , 'false manifest returns undefined' )
278
+ t . equal ( HostedGit . fromManifest ( ( ) => { } ) , undefined , 'function manifest returns undefined' )
279
+
280
+ const unknownHostRepo = {
281
+ name : 'foo' ,
282
+ repository : {
283
+ url : 'https://nope.com' ,
284
+ } ,
285
+ }
286
+ t . same ( HostedGit . fromManifest ( unknownHostRepo ) , 'https://nope.com/' )
287
+
288
+ const insecureUnknownHostRepo = {
289
+ name : 'foo' ,
290
+ repository : {
291
+ url : 'http://nope.com' ,
292
+ } ,
293
+ }
294
+ t . same ( HostedGit . fromManifest ( insecureUnknownHostRepo ) , 'https://nope.com/' )
295
+
296
+ const insecureGitUnknownHostRepo = {
297
+ name : 'foo' ,
298
+ repository : {
299
+ url : 'git+http://nope.com' ,
300
+ } ,
301
+ }
302
+ t . same ( HostedGit . fromManifest ( insecureGitUnknownHostRepo ) , 'http://nope.com' )
303
+
304
+ const badRepo = {
305
+ name : 'foo' ,
306
+ repository : {
307
+ url : '#' ,
308
+ } ,
309
+ }
310
+ t . equal ( HostedGit . fromManifest ( badRepo ) , null )
311
+
312
+ const manifest = {
313
+ name : 'foo' ,
314
+ repository : {
315
+ type : 'git' ,
316
+ url : 'git+ssh://github.com/foo/bar.git' ,
317
+ } ,
318
+ }
319
+
320
+ const parsed = HostedGit . fromManifest ( manifest )
321
+ t . same ( parsed . browse ( ) , 'https://github.com/foo/bar' )
322
+
323
+ const monorepo = {
324
+ name : 'clowncar' ,
325
+ repository : {
326
+ type : 'git' ,
327
+ url : 'git+ssh://github.com/foo/bar.git' ,
328
+ directory : 'packages/foo' ,
329
+ } ,
330
+ }
331
+
332
+ const honk = HostedGit . fromManifest ( monorepo )
333
+ t . same ( honk . browse ( monorepo . repository . directory ) , 'https://github.com/foo/bar/tree/HEAD/packages/foo' )
334
+
335
+ const stringRepo = {
336
+ name : 'foo' ,
337
+ repository : 'git+ssh://github.com/foo/bar.git' ,
338
+ }
339
+ const stringRepoParsed = HostedGit . fromManifest ( stringRepo )
340
+ t . same ( stringRepoParsed . browse ( ) , 'https://github.com/foo/bar' )
341
+
342
+ const nonStringRepo = {
343
+ name : 'foo' ,
344
+ repository : 42 ,
345
+ }
346
+ t . throws ( ( ) => HostedGit . fromManifest ( nonStringRepo ) )
347
+
348
+ t . end ( )
349
+ } )
0 commit comments