1
1
'use strict' ;
2
2
3
3
const Fs = require ( 'fs' ) ;
4
+ const Nock = require ( 'nock' ) ;
4
5
const Path = require ( 'path' ) ;
5
6
const Tmp = require ( 'tmp' ) ;
6
7
7
8
const NodeSupport = require ( '..' ) ;
8
9
9
10
10
- const { describe, it, afterEach } = exports . lab = require ( '@hapi/lab' ) . script ( ) ;
11
+ const { describe, it, beforeEach , afterEach } = exports . lab = require ( '@hapi/lab' ) . script ( ) ;
11
12
const { expect } = require ( '@hapi/code' ) ;
12
13
13
14
@@ -246,8 +247,27 @@ describe('node-support', () => {
246
247
247
248
describe ( 'repository' , ( ) => {
248
249
250
+ beforeEach ( ( ) => {
251
+
252
+ if ( ! Nock . isActive ( ) ) {
253
+ Nock . activate ( ) ;
254
+ }
255
+ } ) ;
256
+
257
+ afterEach ( ( ) => {
258
+
259
+ Nock . restore ( ) ;
260
+ Nock . cleanAll ( ) ;
261
+ } ) ;
262
+
249
263
it ( 'returns node versions from `.travis.yml` in the repository' , async ( ) => {
250
264
265
+ Nock ( 'https://raw.githubusercontent.com' )
266
+ . get ( '/pkgjs/node-support/HEAD/package.json' )
267
+ . reply ( 200 , Fs . readFileSync ( Path . join ( __dirname , '..' , 'package.json' ) ) )
268
+ . get ( '/pkgjs/node-support/HEAD/.travis.yml' )
269
+ . reply ( 200 , Fs . readFileSync ( Path . join ( __dirname , '..' , '.travis.yml' ) ) ) ;
270
+
251
271
const result = await NodeSupport . detect ( { repository : 'git+https://github.com/pkgjs/node-support.git' } ) ;
252
272
253
273
expect ( result ) . to . equal ( {
@@ -258,6 +278,12 @@ describe('node-support', () => {
258
278
}
259
279
} ) ;
260
280
} ) ;
281
+
282
+ it ( 'throws when a package does not live on public github.com' , async ( ) => {
283
+
284
+ await expect ( NodeSupport . detect ( { repository : 'git+https://github.example.com/pkgjs/node-support.git' } ) )
285
+ . to . reject ( 'Only github.com paths supported, feel free to PR at https://github.com/pkgjs/node-support' ) ;
286
+ } ) ;
261
287
} ) ;
262
288
} ) ;
263
289
} ) ;
0 commit comments