@@ -5,17 +5,16 @@ var test = require('tap').test
5
5
var rimraf = require ( 'rimraf' )
6
6
var fs = require ( 'fs' )
7
7
var path = require ( 'path' )
8
- var fakeBrowser = path . join ( common . pkg , '_script.sh' )
9
- var outFile = path . join ( common . pkg , '_output' )
10
- var opts = { cwd : common . pkg }
11
- var mkdirp = require ( 'mkdirp' )
8
+ var fakeBrowser = path . join ( __dirname , '_script.sh' )
9
+ var outFile = path . join ( __dirname , '/ _output' )
10
+
11
+ var opts = { cwd : __dirname }
12
12
13
13
common . pendIfWindows ( 'This is trickier to convert without opening new shells' )
14
14
15
15
test ( 'setup' , function ( t ) {
16
- mkdirp . sync ( common . pkg )
17
16
var s = '#!/usr/bin/env bash\n' +
18
- 'echo "$@" > ' + JSON . stringify ( common . pkg ) + '/_output\n'
17
+ 'echo "$@" > ' + JSON . stringify ( __dirname ) + '/_output\n'
19
18
fs . writeFileSync ( fakeBrowser , s , 'ascii' )
20
19
fs . chmodSync ( fakeBrowser , '0755' )
21
20
t . pass ( 'made script' )
@@ -41,41 +40,6 @@ test('npm repo underscore', function (t) {
41
40
} )
42
41
} )
43
42
44
- test ( 'npm repo underscore --json' , function ( t ) {
45
- mr ( { port : common . port } , function ( er , s ) {
46
- common . npm ( [
47
- 'repo' , 'underscore' ,
48
- '--json' ,
49
- '--registry=' + common . registry ,
50
- '--loglevel=silent' ,
51
- '--no-browser'
52
- ] , opts , function ( err , code , stdout , stderr ) {
53
- t . ifError ( err , 'repo command ran without error' )
54
- t . equal ( code , 0 , 'exit ok' )
55
- t . matchSnapshot ( stdout , 'should print json result' )
56
- s . close ( )
57
- t . end ( )
58
- } )
59
- } )
60
- } )
61
-
62
- test ( 'npm repo underscore --no-browser' , function ( t ) {
63
- mr ( { port : common . port } , function ( er , s ) {
64
- common . npm ( [
65
- 'repo' , 'underscore' ,
66
- '--no-browser' ,
67
- '--registry=' + common . registry ,
68
- '--loglevel=silent'
69
- ] , opts , function ( err , code , stdout , stderr ) {
70
- t . ifError ( err , 'repo command ran without error' )
71
- t . equal ( code , 0 , 'exit ok' )
72
- t . matchSnapshot ( stdout , 'should print alternative msg' )
73
- s . close ( )
74
- t . end ( )
75
- } )
76
- } )
77
- } )
78
-
79
43
test ( 'npm repo optimist - github (https://)' , function ( t ) {
80
44
mr ( { port : common . port } , function ( er , s ) {
81
45
common . npm ( [
@@ -168,6 +132,79 @@ test('npm repo test-repo-url-ssh - non-github (ssh://)', function (t) {
168
132
} )
169
133
} )
170
134
135
+ /* ----- Test by new mock registry: BEGIN ----- */
136
+
137
+ const Tacks = require ( 'tacks' )
138
+ const mockTar = require ( '../util/mock-tarball.js' )
139
+
140
+ const { Dir, File } = Tacks
141
+ const testDir = path . join ( __dirname , path . basename ( __filename , '.js' ) )
142
+
143
+ let server
144
+ test ( 'setup mocked registry' , t => {
145
+ common . fakeRegistry . compat ( { } , ( err , s ) => {
146
+ t . ifError ( err , 'registry mocked successfully' )
147
+ server = s
148
+ t . end ( )
149
+ } )
150
+ } )
151
+
152
+ test ( 'npm repo test-repo-with-directory' , t => {
153
+ const fixture = new Tacks ( Dir ( {
154
+ 'package.json' : File ( { } )
155
+ } ) )
156
+ fixture . create ( testDir )
157
+ const packument = {
158
+ name : 'test-repo-with-directory' ,
159
+ 'dist-tags' : { latest : '1.2.3' } ,
160
+ versions : {
161
+ '1.2.3' : {
162
+ name : 'test-repo-with-directory' ,
163
+ version : '1.2.3' ,
164
+ dist : {
165
+ tarball : `${ server . registry } /test-repo-with-directory/-/test-repo-with-directory-1.2.3.tgz`
166
+ } ,
167
+ repository : {
168
+ type : 'git' ,
169
+ url : 'git+https://github.com/foo/test-repo-with-directory.git' ,
170
+ directory : 'some/directory'
171
+ }
172
+ }
173
+ }
174
+ }
175
+ server . get ( '/test-repo-with-directory' ) . reply ( 200 , packument )
176
+ return mockTar ( {
177
+ 'package.json' : JSON . stringify ( {
178
+ name : 'test-repo-with-directory' ,
179
+ version : '1.2.3'
180
+ } )
181
+ } ) . then ( tarball => {
182
+ server . get ( '/test-repo-with-directory/-/test-repo-with-directory-1.2.3.tgz' ) . reply ( 200 , tarball )
183
+ return common . npm ( [
184
+ 'repo' , 'test-repo-with-directory' ,
185
+ '--registry=' + server . registry ,
186
+ '--loglevel=silent' ,
187
+ '--browser=' + fakeBrowser
188
+ ] )
189
+ } ) . then ( ( [ code , stdout , stderr ] ) => {
190
+ t . equal ( code , 0 )
191
+ t . comment ( stdout )
192
+ t . comment ( stderr )
193
+
194
+ const res = fs . readFileSync ( outFile , 'ascii' )
195
+ t . equal ( res , 'https://github.com/foo/test-repo-with-directory/tree/master/some/directory\n' )
196
+ rimraf . sync ( outFile )
197
+ } )
198
+ } )
199
+
200
+ test ( 'cleanup mocked registry' , t => {
201
+ server . close ( )
202
+ rimraf . sync ( testDir )
203
+ t . end ( )
204
+ } )
205
+
206
+ /* ----- Test by new mock registry: END ----- */
207
+
171
208
test ( 'cleanup' , function ( t ) {
172
209
fs . unlinkSync ( fakeBrowser )
173
210
t . pass ( 'cleaned up' )
0 commit comments