1
1
const t = require ( 'tap' )
2
2
const mockNpm = require ( '../fixtures/mock-npm' )
3
+ const pkgDirPack = require ( 'libnpmpack' )
3
4
const pacote = require ( 'pacote' )
4
5
5
6
const OUTPUT = [ ]
@@ -73,7 +74,7 @@ t.test('should pack given directory', (t) => {
73
74
const npm = mockNpm ( {
74
75
config : {
75
76
unicode : true ,
76
- json : true ,
77
+ json : false ,
77
78
'dry-run' : true ,
78
79
} ,
79
80
output,
@@ -108,7 +109,7 @@ t.test('should pack given directory for scoped package', (t) => {
108
109
const npm = mockNpm ( {
109
110
config : {
110
111
unicode : true ,
111
- json : true ,
112
+ json : false ,
112
113
'dry-run' : true ,
113
114
} ,
114
115
output,
@@ -158,6 +159,45 @@ t.test('should log pack contents', (t) => {
158
159
} )
159
160
} )
160
161
162
+ t . test ( 'should log output as valid json' , ( t ) => {
163
+ const testDir = t . testdir ( {
164
+ 'package.json' : JSON . stringify ( {
165
+ name : 'my-cool-pkg' ,
166
+ version : '1.0.0' ,
167
+ } , null , 2 ) ,
168
+ } )
169
+
170
+ const Pack = t . mock ( '../../lib/pack.js' , {
171
+ libnpmpack : ( ) => pkgDirPack ( testDir ) ,
172
+ npmlog : {
173
+ notice : ( ) => { } ,
174
+ showProgress : ( ) => { } ,
175
+ clearProgress : ( ) => { } ,
176
+ } ,
177
+ } )
178
+ const npm = mockNpm ( {
179
+ config : {
180
+ unicode : true ,
181
+ json : true ,
182
+ 'dry-run' : true ,
183
+ } ,
184
+ output,
185
+ } )
186
+ const pack = new Pack ( npm )
187
+
188
+ pack . exec ( [ testDir ] , err => {
189
+ t . error ( err , { bail : true } )
190
+
191
+ t . similar ( JSON . parse ( OUTPUT ) , [ {
192
+ filename : 'my-cool-pkg-1.0.0.tgz' ,
193
+ files : [ { path : 'package.json' } ] ,
194
+ entryCount : 1 ,
195
+ } ] , 'pack details output as valid json' )
196
+
197
+ t . end ( )
198
+ } )
199
+ } )
200
+
161
201
t . test ( 'invalid packument' , ( t ) => {
162
202
const mockPacote = {
163
203
manifest : ( ) => {
@@ -176,7 +216,7 @@ t.test('invalid packument', (t) => {
176
216
const npm = mockNpm ( {
177
217
config : {
178
218
unicode : true ,
179
- json : true ,
219
+ json : false ,
180
220
'dry-run' : true ,
181
221
} ,
182
222
output,
0 commit comments