@@ -168,6 +168,79 @@ test('npm repo test-repo-url-ssh - non-github (ssh://)', function (t) {
168
168
} )
169
169
} )
170
170
171
+ /* ----- Test by new mock registry: BEGIN ----- */
172
+
173
+ const Tacks = require ( 'tacks' )
174
+ const mockTar = require ( '../util/mock-tarball.js' )
175
+
176
+ const { Dir, File } = Tacks
177
+ const testDir = path . join ( __dirname , path . basename ( __filename , '.js' ) )
178
+
179
+ let server
180
+ test ( 'setup mocked registry' , t => {
181
+ common . fakeRegistry . compat ( { } , ( err , s ) => {
182
+ t . ifError ( err , 'registry mocked successfully' )
183
+ server = s
184
+ t . end ( )
185
+ } )
186
+ } )
187
+
188
+ test ( 'npm repo test-repo-with-directory' , t => {
189
+ const fixture = new Tacks ( Dir ( {
190
+ 'package.json' : File ( { } )
191
+ } ) )
192
+ fixture . create ( testDir )
193
+ const packument = {
194
+ name : 'test-repo-with-directory' ,
195
+ 'dist-tags' : { latest : '1.2.3' } ,
196
+ versions : {
197
+ '1.2.3' : {
198
+ name : 'test-repo-with-directory' ,
199
+ version : '1.2.3' ,
200
+ dist : {
201
+ tarball : `${ server . registry } /test-repo-with-directory/-/test-repo-with-directory-1.2.3.tgz`
202
+ } ,
203
+ repository : {
204
+ type : 'git' ,
205
+ url : 'git+https://github.com/foo/test-repo-with-directory.git' ,
206
+ directory : 'some/directory'
207
+ }
208
+ }
209
+ }
210
+ }
211
+ server . get ( '/test-repo-with-directory' ) . reply ( 200 , packument )
212
+ return mockTar ( {
213
+ 'package.json' : JSON . stringify ( {
214
+ name : 'test-repo-with-directory' ,
215
+ version : '1.2.3'
216
+ } )
217
+ } ) . then ( tarball => {
218
+ server . get ( '/test-repo-with-directory/-/test-repo-with-directory-1.2.3.tgz' ) . reply ( 200 , tarball )
219
+ return common . npm ( [
220
+ 'repo' , 'test-repo-with-directory' ,
221
+ '--registry=' + server . registry ,
222
+ '--loglevel=silent' ,
223
+ '--browser=' + fakeBrowser
224
+ ] )
225
+ } ) . then ( ( [ code , stdout , stderr ] ) => {
226
+ t . equal ( code , 0 )
227
+ t . comment ( stdout )
228
+ t . comment ( stderr )
229
+
230
+ const res = fs . readFileSync ( outFile , 'ascii' )
231
+ t . equal ( res , 'https://github.com/foo/test-repo-with-directory/tree/master/some/directory\n' )
232
+ rimraf . sync ( outFile )
233
+ } )
234
+ } )
235
+
236
+ test ( 'cleanup mocked registry' , t => {
237
+ server . close ( )
238
+ rimraf . sync ( testDir )
239
+ t . end ( )
240
+ } )
241
+
242
+ /* ----- Test by new mock registry: END ----- */
243
+
171
244
test ( 'cleanup' , function ( t ) {
172
245
fs . unlinkSync ( fakeBrowser )
173
246
t . pass ( 'cleaned up' )
0 commit comments