@@ -5,9 +5,8 @@ const http = require('http')
55const mr = require ( 'npm-registry-mock' )
66const npm = require ( '../../lib/npm.js' )
77const path = require ( 'path' )
8- const rimraf = require ( 'rimraf' )
98const Tacks = require ( 'tacks' )
10- const test = require ( 'tap' ) . test
9+ const t = require ( 'tap' )
1110const which = require ( 'which' )
1211
1312const Dir = Tacks . Dir
@@ -44,12 +43,23 @@ const npmResponse = {
4443 }
4544}
4645
47- test ( 'setup' , ( t ) => {
46+ let nodeServer
47+
48+ t . teardown ( ( ) => {
49+ if ( server ) {
50+ server . close ( )
51+ }
52+ if ( nodeServer ) {
53+ nodeServer . close ( )
54+ }
55+ } )
56+
57+ t . test ( 'setup' , ( t ) => {
4858 const port = common . port + 1
49- http . createServer ( function ( q , s ) {
59+ nodeServer = http . createServer ( function ( q , s ) {
5060 s . end ( JSON . stringify ( [ { lts : true , version : '0.0.0' } ] ) )
51- this . close ( )
52- } ) . listen ( port , ( ) => {
61+ } )
62+ nodeServer . listen ( port , ( ) => {
5363 node_url = 'http://localhost:' + port
5464 mr ( { port : common . port } , ( err , s ) => {
5565 t . ifError ( err , 'registry mocked successfully' )
@@ -78,7 +88,7 @@ test('setup', (t) => {
7888 } )
7989} )
8090
81- test ( 'npm doctor' , function ( t ) {
91+ t . test ( 'npm doctor' , function ( t ) {
8292 npm . commands . doctor ( { 'node-url' : node_url } , true , function ( e , list ) {
8393 t . ifError ( e , 'npm loaded successfully' )
8494 t . same ( list . length , 9 , 'list should have 9 prop' )
@@ -93,13 +103,29 @@ test('npm doctor', function (t) {
93103 which ( 'git' , function ( e , resolvedPath ) {
94104 t . ifError ( e , 'git command is installed' )
95105 t . same ( list [ 4 ] [ 1 ] , resolvedPath , 'which git' )
96- server . close ( )
97106 t . done ( )
98107 } )
99108 } )
100109} )
101110
102- test ( 'cleanup' , ( t ) => {
103- rimraf . sync ( ROOT )
104- t . done ( )
111+ t . test ( 'npm doctor works without registry' , function ( t ) {
112+ npm . config . set ( 'registry' , false )
113+ npm . commands . doctor ( { 'node-url' : node_url } , true , function ( e , list ) {
114+ t . ifError ( e , 'npm loaded successfully' )
115+ t . same ( list . length , 9 , 'list should have 9 prop' )
116+ t . same ( list [ 0 ] [ 1 ] , 'OK' , 'npm ping' )
117+ t . same ( list [ 1 ] [ 1 ] , 'v' + npm . version , 'npm -v' )
118+ t . same ( list [ 2 ] [ 1 ] , process . version , 'node -v' )
119+ t . same ( list [ 3 ] [ 1 ] , '' , 'no registry, but no crash' )
120+ t . same ( list [ 5 ] [ 1 ] , 'ok' , 'Perms check on cached files' )
121+ t . same ( list [ 6 ] [ 1 ] , 'ok' , 'Perms check on global node_modules' )
122+ t . same ( list [ 7 ] [ 1 ] , 'ok' , 'Perms check on local node_modules' )
123+ t . match ( list [ 8 ] [ 1 ] , / ^ v e r i f i e d \d + t a r b a l l s ? $ / , 'Cache verified' )
124+ which ( 'git' , function ( e , resolvedPath ) {
125+ t . ifError ( e , 'git command is installed' )
126+ t . same ( list [ 4 ] [ 1 ] , resolvedPath , 'which git' )
127+ server . close ( )
128+ t . done ( )
129+ } )
130+ } )
105131} )
0 commit comments