@@ -7,6 +7,8 @@ const config = { list: [defaults] }
7
7
const fs = require ( 'fs' )
8
8
9
9
t . test ( 'should publish with libnpmpublish, respecting publishConfig' , ( t ) => {
10
+ t . plan ( 5 )
11
+
10
12
const publishConfig = { registry : 'https://some.registry' }
11
13
const testDir = t . testdir ( {
12
14
'package.json' : JSON . stringify ( {
@@ -41,27 +43,27 @@ t.test('should publish with libnpmpublish, respecting publishConfig', (t) => {
41
43
name : 'my-cool-pkg' ,
42
44
version : '1.0.0' ,
43
45
} ) )
44
- return ''
46
+ return Buffer . from ( '' )
45
47
} ,
46
48
libnpmpublish : {
47
- publish : ( arg , manifest , opts ) => {
48
- t . ok ( arg , ' gets path ')
49
- t . ok ( manifest , 'gets manifest ')
49
+ publish : ( manifest , tarData , opts ) => {
50
+ t . match ( manifest , { name : 'my-cool-pkg' , version : '1.0.0' } , ' gets manifest ')
51
+ t . isa ( tarData , Buffer , 'tarData is a buffer ')
50
52
t . ok ( opts , 'gets opts object' )
51
53
t . same ( opts . registry , publishConfig . registry , 'publishConfig is passed through' )
52
- t . ok ( true , 'libnpmpublish is called' )
53
54
} ,
54
55
} ,
55
56
} )
56
57
57
58
publish ( [ testDir ] , ( er ) => {
58
59
if ( er )
59
60
throw er
60
- t . end ( )
61
+ t . pass ( 'got to callback' )
61
62
} )
62
63
} )
63
64
64
65
t . test ( 're-loads publishConfig if added during script process' , ( t ) => {
66
+ t . plan ( 5 )
65
67
const publishConfig = { registry : 'https://some.registry' }
66
68
const testDir = t . testdir ( {
67
69
'package.json' : JSON . stringify ( {
@@ -94,27 +96,28 @@ t.test('re-loads publishConfig if added during script process', (t) => {
94
96
version : '1.0.0' ,
95
97
publishConfig,
96
98
} ) )
97
- return ''
99
+ return Buffer . from ( '' )
98
100
} ,
99
101
libnpmpublish : {
100
- publish : ( arg , manifest , opts ) => {
101
- t . ok ( arg , ' gets path ')
102
- t . ok ( manifest , 'gets manifest ')
102
+ publish : ( manifest , tarData , opts ) => {
103
+ t . match ( manifest , { name : 'my-cool-pkg' , version : '1.0.0' } , ' gets manifest ')
104
+ t . isa ( tarData , Buffer , 'tarData is a buffer ')
103
105
t . ok ( opts , 'gets opts object' )
104
106
t . same ( opts . registry , publishConfig . registry , 'publishConfig is passed through' )
105
- t . ok ( true , 'libnpmpublish is called' )
106
107
} ,
107
108
} ,
108
109
} )
109
110
110
111
publish ( [ testDir ] , ( er ) => {
111
112
if ( er )
112
113
throw er
113
- t . end ( )
114
+ t . pass ( 'got to callback' )
114
115
} )
115
116
} )
116
117
117
118
t . test ( 'should not log if silent' , ( t ) => {
119
+ t . plan ( 2 )
120
+
118
121
const testDir = t . testdir ( {
119
122
'package.json' : JSON . stringify ( {
120
123
name : 'my-cool-pkg' ,
@@ -133,29 +136,38 @@ t.test('should not log if silent', (t) => {
133
136
} ,
134
137
'../../lib/utils/tar.js' : {
135
138
getContents : ( ) => ( { } ) ,
136
- logTar : ( ) => { } ,
139
+ logTar : ( ) => {
140
+ t . pass ( 'called logTar (but nothing actually printed)' )
141
+ } ,
137
142
} ,
138
143
'../../lib/utils/otplease.js' : ( opts , fn ) => {
139
144
return Promise . resolve ( ) . then ( ( ) => fn ( opts ) )
140
145
} ,
146
+ '../../lib/utils/output.js' : ( ) => {
147
+ throw new Error ( 'should not output in silent mode' )
148
+ } ,
141
149
npmlog : {
142
150
verbose : ( ) => { } ,
151
+ notice : ( ) => { } ,
143
152
level : 'silent' ,
144
153
} ,
145
154
libnpmpack : async ( ) => '' ,
146
155
libnpmpublish : {
147
- publish : ( ) => { } ,
156
+ publish : ( manifest , tarData , opts ) => {
157
+ throw new Error ( 'should not call libnpmpublish!' )
158
+ } ,
148
159
} ,
149
160
} )
150
161
151
162
publish ( [ testDir ] , ( er ) => {
152
163
if ( er )
153
164
throw er
154
- t . end ( )
165
+ t . pass ( 'got to callback' )
155
166
} )
156
167
} )
157
168
158
169
t . test ( 'should log tarball contents' , ( t ) => {
170
+ t . plan ( 3 )
159
171
const testDir = t . testdir ( {
160
172
'package.json' : JSON . stringify ( {
161
173
name : 'my-cool-pkg' ,
@@ -177,29 +189,32 @@ t.test('should log tarball contents', (t) => {
177
189
id : 'someid' ,
178
190
} ) ,
179
191
logTar : ( ) => {
180
- t . ok ( true , 'logTar is called' )
192
+ t . pass ( 'logTar is called' )
181
193
} ,
182
194
} ,
183
195
'../../lib/utils/output.js' : ( ) => {
184
- t . ok ( true , 'output fn is called' )
196
+ t . pass ( 'output fn is called' )
185
197
} ,
186
198
'../../lib/utils/otplease.js' : ( opts , fn ) => {
187
199
return Promise . resolve ( ) . then ( ( ) => fn ( opts ) )
188
200
} ,
189
201
libnpmpack : async ( ) => '' ,
190
202
libnpmpublish : {
191
- publish : ( ) => { } ,
203
+ publish : ( ) => {
204
+ throw new Error ( 'should not call libnpmpublish!' )
205
+ } ,
192
206
} ,
193
207
} )
194
208
195
209
publish ( [ testDir ] , ( er ) => {
196
210
if ( er )
197
211
throw er
198
- t . end ( )
212
+ t . pass ( 'got to callback' )
199
213
} )
200
214
} )
201
215
202
216
t . test ( 'shows usage with wrong set of arguments' , ( t ) => {
217
+ t . plan ( 1 )
203
218
const publish = requireInject ( '../../lib/publish.js' , {
204
219
'../../lib/npm.js' : {
205
220
flatOptions : {
@@ -210,13 +225,11 @@ t.test('shows usage with wrong set of arguments', (t) => {
210
225
} ,
211
226
} )
212
227
213
- publish ( [ 'a' , 'b' , 'c' ] , ( er ) => {
214
- t . matchSnapshot ( er , 'should print usage' )
215
- t . end ( )
216
- } )
228
+ publish ( [ 'a' , 'b' , 'c' ] , ( er ) => t . matchSnapshot ( er , 'should print usage' ) )
217
229
} )
218
230
219
231
t . test ( 'throws when invalid tag' , ( t ) => {
232
+ t . plan ( 1 )
220
233
const publish = requireInject ( '../../lib/publish.js' , {
221
234
'../../lib/npm.js' : {
222
235
flatOptions : {
@@ -228,7 +241,66 @@ t.test('throws when invalid tag', (t) => {
228
241
} )
229
242
230
243
publish ( [ ] , ( err ) => {
231
- t . ok ( err , 'throws when tag name is a valid SemVer range' )
232
- t . end ( )
244
+ t . match ( err , {
245
+ 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 : / ,
246
+ } , 'throws when tag name is a valid SemVer range' )
247
+ } )
248
+ } )
249
+
250
+ t . test ( 'can publish a tarball' , t => {
251
+ t . plan ( 3 )
252
+ const testDir = t . testdir ( {
253
+ package : {
254
+ 'package.json' : JSON . stringify ( {
255
+ name : 'my-cool-tarball' ,
256
+ version : '1.2.3' ,
257
+ } ) ,
258
+ } ,
259
+ } )
260
+ const tar = require ( 'tar' )
261
+ tar . c ( {
262
+ cwd : testDir ,
263
+ file : `${ testDir } /package.tgz` ,
264
+ sync : true ,
265
+ } , [ 'package' ] )
266
+
267
+ // no cheating! read it from the tarball.
268
+ fs . unlinkSync ( `${ testDir } /package/package.json` )
269
+ fs . rmdirSync ( `${ testDir } /package` )
270
+
271
+ const tarFile = fs . readFileSync ( `${ testDir } /package.tgz` )
272
+ const publish = requireInject ( '../../lib/publish.js' , {
273
+ '../../lib/npm.js' : {
274
+ flatOptions : {
275
+ json : true ,
276
+ defaultTag : 'latest' ,
277
+ } ,
278
+ config,
279
+ } ,
280
+ '../../lib/utils/tar.js' : {
281
+ getContents : ( ) => ( {
282
+ id : 'someid' ,
283
+ } ) ,
284
+ logTar : ( ) => { } ,
285
+ } ,
286
+ '../../lib/utils/output.js' : ( ) => { } ,
287
+ '../../lib/utils/otplease.js' : ( opts , fn ) => {
288
+ return Promise . resolve ( ) . then ( ( ) => fn ( opts ) )
289
+ } ,
290
+ libnpmpublish : {
291
+ publish : ( manifest , tarData , opts ) => {
292
+ t . match ( manifest , {
293
+ name : 'my-cool-tarball' ,
294
+ version : '1.2.3' ,
295
+ } , 'sent manifest to lib pub' )
296
+ t . strictSame ( tarData , tarFile , 'sent the tarball data to lib pub' )
297
+ } ,
298
+ } ,
299
+ } )
300
+
301
+ publish ( [ `${ testDir } /package.tgz` ] , ( er ) => {
302
+ if ( er )
303
+ throw er
304
+ t . pass ( 'got to callback' )
233
305
} )
234
306
} )
0 commit comments