@@ -5,9 +5,8 @@ const http = require('http')
5
5
const mr = require ( 'npm-registry-mock' )
6
6
const npm = require ( '../../lib/npm.js' )
7
7
const path = require ( 'path' )
8
- const rimraf = require ( 'rimraf' )
9
8
const Tacks = require ( 'tacks' )
10
- const test = require ( 'tap' ) . test
9
+ const t = require ( 'tap' )
11
10
const which = require ( 'which' )
12
11
13
12
const Dir = Tacks . Dir
@@ -44,12 +43,23 @@ const npmResponse = {
44
43
}
45
44
}
46
45
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 ) => {
48
58
const port = common . port + 1
49
- http . createServer ( function ( q , s ) {
59
+ nodeServer = http . createServer ( function ( q , s ) {
50
60
s . end ( JSON . stringify ( [ { lts : true , version : '0.0.0' } ] ) )
51
- this . close ( )
52
- } ) . listen ( port , ( ) => {
61
+ } )
62
+ nodeServer . listen ( port , ( ) => {
53
63
node_url = 'http://localhost:' + port
54
64
mr ( { port : common . port } , ( err , s ) => {
55
65
t . ifError ( err , 'registry mocked successfully' )
@@ -78,7 +88,7 @@ test('setup', (t) => {
78
88
} )
79
89
} )
80
90
81
- test ( 'npm doctor' , function ( t ) {
91
+ t . test ( 'npm doctor' , function ( t ) {
82
92
npm . commands . doctor ( { 'node-url' : node_url } , true , function ( e , list ) {
83
93
t . ifError ( e , 'npm loaded successfully' )
84
94
t . same ( list . length , 9 , 'list should have 9 prop' )
@@ -93,13 +103,29 @@ test('npm doctor', function (t) {
93
103
which ( 'git' , function ( e , resolvedPath ) {
94
104
t . ifError ( e , 'git command is installed' )
95
105
t . same ( list [ 4 ] [ 1 ] , resolvedPath , 'which git' )
96
- server . close ( )
97
106
t . done ( )
98
107
} )
99
108
} )
100
109
} )
101
110
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
+ } )
105
131
} )
0 commit comments