@@ -3,7 +3,14 @@ const requireInject = require('require-inject')
33
44// mock config
55const { defaults} = require ( '../../lib/utils/config.js' )
6- const config = { list : [ defaults ] }
6+ const credentials = {
7+ token : 'asdfasdf' ,
8+ alwaysAuth : false ,
9+ }
10+ const config = {
11+ list : [ defaults ] ,
12+ getCredentialsByURI : ( ) => credentials ,
13+ }
714const fs = require ( 'fs' )
815
916t . test ( 'should publish with libnpmpublish, respecting publishConfig' , ( t ) => {
@@ -23,6 +30,7 @@ t.test('should publish with libnpmpublish, respecting publishConfig', (t) => {
2330 flatOptions : {
2431 json : true ,
2532 defaultTag : 'latest' ,
33+ registry : 'https://registry.npmjs.org' ,
2634 } ,
2735 config,
2836 } ,
@@ -55,7 +63,7 @@ t.test('should publish with libnpmpublish, respecting publishConfig', (t) => {
5563 } ,
5664 } )
5765
58- publish ( [ testDir ] , ( er ) => {
66+ return publish ( [ testDir ] , ( er ) => {
5967 if ( er )
6068 throw er
6169 t . pass ( 'got to callback' )
@@ -77,6 +85,7 @@ t.test('re-loads publishConfig if added during script process', (t) => {
7785 flatOptions : {
7886 json : true ,
7987 defaultTag : 'latest' ,
88+ registry : 'https://registry.npmjs.org/' ,
8089 } ,
8190 config,
8291 } ,
@@ -108,7 +117,7 @@ t.test('re-loads publishConfig if added during script process', (t) => {
108117 } ,
109118 } )
110119
111- publish ( [ testDir ] , ( er ) => {
120+ return publish ( [ testDir ] , ( er ) => {
112121 if ( er )
113122 throw er
114123 t . pass ( 'got to callback' )
@@ -131,6 +140,7 @@ t.test('should not log if silent', (t) => {
131140 json : false ,
132141 defaultTag : 'latest' ,
133142 dryRun : true ,
143+ registry : 'https://registry.npmjs.org/' ,
134144 } ,
135145 config,
136146 } ,
@@ -159,7 +169,7 @@ t.test('should not log if silent', (t) => {
159169 } ,
160170 } )
161171
162- publish ( [ testDir ] , ( er ) => {
172+ return publish ( [ testDir ] , ( er ) => {
163173 if ( er )
164174 throw er
165175 t . pass ( 'got to callback' )
@@ -181,6 +191,7 @@ t.test('should log tarball contents', (t) => {
181191 json : false ,
182192 defaultTag : 'latest' ,
183193 dryRun : true ,
194+ registry : 'https://registry.npmjs.org/' ,
184195 } ,
185196 config,
186197 } ,
@@ -206,7 +217,7 @@ t.test('should log tarball contents', (t) => {
206217 } ,
207218 } )
208219
209- publish ( [ testDir ] , ( er ) => {
220+ return publish ( [ testDir ] , ( er ) => {
210221 if ( er )
211222 throw er
212223 t . pass ( 'got to callback' )
@@ -220,12 +231,13 @@ t.test('shows usage with wrong set of arguments', (t) => {
220231 flatOptions : {
221232 json : false ,
222233 defaultTag : '0.0.13' ,
234+ registry : 'https://registry.npmjs.org/' ,
223235 } ,
224236 config,
225237 } ,
226238 } )
227239
228- publish ( [ 'a' , 'b' , 'c' ] , ( er ) => t . matchSnapshot ( er , 'should print usage' ) )
240+ return publish ( [ 'a' , 'b' , 'c' ] , ( er ) => t . matchSnapshot ( er , 'should print usage' ) )
229241} )
230242
231243t . test ( 'throws when invalid tag' , ( t ) => {
@@ -235,12 +247,13 @@ t.test('throws when invalid tag', (t) => {
235247 flatOptions : {
236248 json : false ,
237249 defaultTag : '0.0.13' ,
250+ registry : 'https://registry.npmjs.org/' ,
238251 } ,
239252 config,
240253 } ,
241254 } )
242255
243- publish ( [ ] , ( err ) => {
256+ return publish ( [ ] , ( err ) => {
244257 t . match ( err , {
245258 message : / T a g n a m e m u s t n o t b e a v a l i d S e m V e r r a n g e : / ,
246259 } , 'throws when tag name is a valid SemVer range' )
@@ -274,6 +287,7 @@ t.test('can publish a tarball', t => {
274287 flatOptions : {
275288 json : true ,
276289 defaultTag : 'latest' ,
290+ registry : 'https://registry.npmjs.org/' ,
277291 } ,
278292 config,
279293 } ,
@@ -298,9 +312,56 @@ t.test('can publish a tarball', t => {
298312 } ,
299313 } )
300314
301- publish ( [ `${ testDir } /package.tgz` ] , ( er ) => {
315+ return publish ( [ `${ testDir } /package.tgz` ] , ( er ) => {
302316 if ( er )
303317 throw er
304318 t . pass ( 'got to callback' )
305319 } )
306320} )
321+
322+ t . test ( 'throw if no registry' , async t => {
323+ t . plan ( 1 )
324+ const publish = requireInject ( '../../lib/publish.js' , {
325+ '../../lib/npm.js' : {
326+ flatOptions : {
327+ json : false ,
328+ defaultTag : '0.0.13' ,
329+ registry : null ,
330+ } ,
331+ config,
332+ } ,
333+ } )
334+
335+ return publish ( [ ] , ( err ) => {
336+ t . match ( err , {
337+ message : 'No registry specified.' ,
338+ code : 'ENOREGISTRY' ,
339+ } , 'throws when registry unset' )
340+ } )
341+ } )
342+
343+ t . test ( 'throw if not logged in' , async t => {
344+ t . plan ( 1 )
345+ const publish = requireInject ( '../../lib/publish.js' , {
346+ '../../lib/npm.js' : {
347+ flatOptions : {
348+ json : false ,
349+ defaultTag : '0.0.13' ,
350+ registry : 'https://registry.npmjs.org/' ,
351+ } ,
352+ config : {
353+ ...config ,
354+ getCredentialsByURI : ( ) => ( {
355+ 356+ } ) ,
357+ } ,
358+ } ,
359+ } )
360+
361+ return publish ( [ ] , ( err ) => {
362+ t . match ( err , {
363+ message : 'This command requires you to be logged in.' ,
364+ code : 'ENEEDAUTH' ,
365+ } , 'throws when not logged in' )
366+ } )
367+ } )
0 commit comments