@@ -6,6 +6,7 @@ const Path = require('path');
6
6
const Sinon = require ( 'sinon' ) ;
7
7
const SimpleGit = require ( 'simple-git/promise' ) ;
8
8
const Tmp = require ( 'tmp' ) ;
9
+ const Wreck = require ( '@hapi/wreck' ) ;
9
10
10
11
const NodeSupport = require ( '..' ) ;
11
12
@@ -407,6 +408,43 @@ describe('node-support', () => {
407
408
} ) ;
408
409
} ) ;
409
410
411
+ it ( 'throws when repository does not have a package.json' , async ( ) => {
412
+
413
+ listRemoteStub
414
+ . returns ( '9cef39d21ad229dea4b10295f55b0d9a83800b23\tHEAD\n' ) ;
415
+
416
+ Nock ( 'https://raw.githubusercontent.com' )
417
+ . get ( '/pkgjs/node-support/HEAD/package.json' )
418
+ . reply ( 404 )
419
+ . get ( '/pkgjs/node-support/HEAD/.travis.yml' )
420
+ . reply ( 200 , Fs . readFileSync ( Path . join ( __dirname , '..' , '.travis.yml' ) ) ) ;
421
+
422
+ await expect ( NodeSupport . detect ( { repository : 'git+https://github.com/pkgjs/node-support.git' } ) )
423
+ . to . reject ( `git+https://github.com/pkgjs/node-support.git does not contain a package.json` ) ;
424
+ } ) ;
425
+
426
+ it ( 'rethrows server errors' , async ( ) => {
427
+
428
+ Nock ( 'https://raw.githubusercontent.com' )
429
+ . get ( '/pkgjs/node-support/HEAD/package.json' )
430
+ . reply ( 500 )
431
+ . get ( '/pkgjs/node-support/HEAD/.travis.yml' )
432
+ . reply ( 200 , Fs . readFileSync ( Path . join ( __dirname , '..' , '.travis.yml' ) ) ) ;
433
+
434
+ await expect ( NodeSupport . detect ( { repository : 'git+https://github.com/pkgjs/node-support.git' } ) )
435
+ . to . reject ( / R e s p o n s e E r r o r / ) ;
436
+ } ) ;
437
+
438
+ it ( 'rethrows generic errors' , async ( ) => {
439
+
440
+ const err = new Error ( 'Something went wrong' ) ;
441
+
442
+ Sinon . stub ( Wreck , 'get' ) . throws ( err ) ;
443
+
444
+ await expect ( NodeSupport . detect ( { repository : 'git+https://github.com/pkgjs/node-support.git' } ) )
445
+ . to . reject ( 'Something went wrong' ) ;
446
+ } ) ;
447
+
410
448
it ( 'throws when a package does not live on public github.com' , async ( ) => {
411
449
412
450
await expect ( NodeSupport . detect ( { repository : 'git+https://github.example.com/pkgjs/node-support.git' } ) )
0 commit comments