@@ -61,6 +61,7 @@ t.test('recursive tree', async t => {
61
61
await npm . exec ( 'query' , [ '*' ] )
62
62
t . matchSnapshot ( joinedOutput ( ) , 'should return everything in the tree, accounting for recursion' )
63
63
} )
64
+
64
65
t . test ( 'workspace query' , async t => {
65
66
const { npm, joinedOutput } = await loadMockNpm ( t , {
66
67
config : {
@@ -237,3 +238,85 @@ t.test('package-lock-only', t => {
237
238
} )
238
239
t . end ( )
239
240
} )
241
+
242
+ t . test ( 'expect entries' , t => {
243
+ const { exitCode } = process
244
+ t . afterEach ( ( ) => process . exitCode = exitCode )
245
+ const prefixDir = {
246
+ node_modules : {
247
+ a : { name : 'a' , version : '1.0.0' } ,
248
+ } ,
249
+ 'package.json' : JSON . stringify ( {
250
+ name : 'project' ,
251
+ dependencies : { a : '^1.0.0' } ,
252
+ } ) ,
253
+ }
254
+ t . test ( 'false, has entries' , async t => {
255
+ const { logs, npm, joinedOutput } = await loadMockNpm ( t , {
256
+ prefixDir,
257
+ } )
258
+ npm . config . set ( 'expect-results' , false )
259
+ await npm . exec ( 'query' , [ '#a' ] )
260
+ t . not ( joinedOutput ( ) , '[]' , 'has entries' )
261
+ t . same ( logs . warn , [ [ 'query' , 'Expected no results, got 1' ] ] )
262
+ t . ok ( process . exitCode , 'exits with code' )
263
+ } )
264
+ t . test ( 'false, no entries' , async t => {
265
+ const { npm, joinedOutput } = await loadMockNpm ( t , {
266
+ prefixDir,
267
+ } )
268
+ npm . config . set ( 'expect-results' , false )
269
+ await npm . exec ( 'query' , [ '#b' ] )
270
+ t . equal ( joinedOutput ( ) , '[]' , 'does not have entries' )
271
+ t . notOk ( process . exitCode , 'exits without code' )
272
+ } )
273
+ t . test ( 'true, has entries' , async t => {
274
+ const { npm, joinedOutput } = await loadMockNpm ( t , {
275
+ prefixDir,
276
+ } )
277
+ npm . config . set ( 'expect-results' , true )
278
+ await npm . exec ( 'query' , [ '#a' ] )
279
+ t . not ( joinedOutput ( ) , '[]' , 'has entries' )
280
+ t . notOk ( process . exitCode , 'exits without code' )
281
+ } )
282
+ t . test ( 'true, no entries' , async t => {
283
+ const { logs, npm, joinedOutput } = await loadMockNpm ( t , {
284
+ prefixDir,
285
+ } )
286
+ npm . config . set ( 'expect-results' , true )
287
+ await npm . exec ( 'query' , [ '#b' ] )
288
+ t . equal ( joinedOutput ( ) , '[]' , 'does not have entries' )
289
+ t . same ( logs . warn , [ [ 'query' , 'Expected results, got 0' ] ] )
290
+ t . ok ( process . exitCode , 'exits with code' )
291
+ } )
292
+ t . test ( 'count, matches' , async t => {
293
+ const { npm, joinedOutput } = await loadMockNpm ( t , {
294
+ prefixDir,
295
+ } )
296
+ npm . config . set ( 'expect-result-count' , 1 )
297
+ await npm . exec ( 'query' , [ '#a' ] )
298
+ t . not ( joinedOutput ( ) , '[]' , 'has entries' )
299
+ t . notOk ( process . exitCode , 'exits without code' )
300
+ } )
301
+ t . test ( 'count 1, does not match' , async t => {
302
+ const { logs, npm, joinedOutput } = await loadMockNpm ( t , {
303
+ prefixDir,
304
+ } )
305
+ npm . config . set ( 'expect-result-count' , 1 )
306
+ await npm . exec ( 'query' , [ '#b' ] )
307
+ t . equal ( joinedOutput ( ) , '[]' , 'does not have entries' )
308
+ t . same ( logs . warn , [ [ 'query' , 'Expected 1 result, got 0' ] ] )
309
+ t . ok ( process . exitCode , 'exits with code' )
310
+ } )
311
+ t . test ( 'count 3, does not match' , async t => {
312
+ const { logs, npm, joinedOutput } = await loadMockNpm ( t , {
313
+ prefixDir,
314
+ } )
315
+ npm . config . set ( 'expect-result-count' , 3 )
316
+ await npm . exec ( 'query' , [ '#b' ] )
317
+ t . equal ( joinedOutput ( ) , '[]' , 'does not have entries' )
318
+ t . same ( logs . warn , [ [ 'query' , 'Expected 3 results, got 0' ] ] )
319
+ t . ok ( process . exitCode , 'exits with code' )
320
+ } )
321
+ t . end ( )
322
+ } )
0 commit comments