@@ -61,6 +61,7 @@ t.test('recursive tree', async t => {
6161 await npm . exec ( 'query' , [ '*' ] )
6262 t . matchSnapshot ( joinedOutput ( ) , 'should return everything in the tree, accounting for recursion' )
6363} )
64+
6465t . test ( 'workspace query' , async t => {
6566 const { npm, joinedOutput } = await loadMockNpm ( t , {
6667 config : {
@@ -179,3 +180,72 @@ t.test('global', async t => {
179180 await npm . exec ( 'query' , [ '[name=lorem]' ] )
180181 t . matchSnapshot ( joinedOutput ( ) , 'should return global package' )
181182} )
183+
184+ t . test ( 'expect entries' , t => {
185+ const { exitCode } = process
186+ t . afterEach ( ( ) => process . exitCode = exitCode )
187+ const prefixDir = {
188+ node_modules : {
189+ a : { name : 'a' , version : '1.0.0' } ,
190+ } ,
191+ 'package.json' : JSON . stringify ( {
192+ name : 'project' ,
193+ dependencies : { a : '^1.0.0' } ,
194+ } ) ,
195+ }
196+ t . test ( 'false, has entries' , async t => {
197+ const { npm, joinedOutput } = await loadMockNpm ( t , {
198+ prefixDir,
199+ } )
200+ npm . config . set ( 'expect-entries' , false )
201+ await npm . exec ( 'query' , [ '#a' ] )
202+ t . not ( joinedOutput ( ) , '[]' , 'has entries' )
203+ t . ok ( process . exitCode , 'exits with code' )
204+ } )
205+ t . test ( 'false, no entries' , async t => {
206+ const { npm, joinedOutput } = await loadMockNpm ( t , {
207+ prefixDir,
208+ } )
209+ npm . config . set ( 'expect-entries' , false )
210+ await npm . exec ( 'query' , [ '#b' ] )
211+ t . equal ( joinedOutput ( ) , '[]' , 'does not have entries' )
212+ t . notOk ( process . exitCode , 'exits without code' )
213+ } )
214+ t . test ( 'true, has entries' , async t => {
215+ const { npm, joinedOutput } = await loadMockNpm ( t , {
216+ prefixDir,
217+ } )
218+ npm . config . set ( 'expect-entries' , true )
219+ await npm . exec ( 'query' , [ '#a' ] )
220+ t . not ( joinedOutput ( ) , '[]' , 'has entries' )
221+ t . notOk ( process . exitCode , 'exits without code' )
222+ } )
223+ t . test ( 'true, no entries' , async t => {
224+ const { npm, joinedOutput } = await loadMockNpm ( t , {
225+ prefixDir,
226+ } )
227+ npm . config . set ( 'expect-entries' , true )
228+ await npm . exec ( 'query' , [ '#b' ] )
229+ t . equal ( joinedOutput ( ) , '[]' , 'does not have entries' )
230+ t . ok ( process . exitCode , 'exits with code' )
231+ } )
232+ t . test ( 'number, matches' , async t => {
233+ const { npm, joinedOutput } = await loadMockNpm ( t , {
234+ prefixDir,
235+ } )
236+ npm . config . set ( 'expect-entries' , 1 )
237+ await npm . exec ( 'query' , [ '#a' ] )
238+ t . not ( joinedOutput ( ) , '[]' , 'has entries' )
239+ t . notOk ( process . exitCode , 'exits without code' )
240+ } )
241+ t . test ( 'number, does not match' , async t => {
242+ const { npm, joinedOutput } = await loadMockNpm ( t , {
243+ prefixDir,
244+ } )
245+ npm . config . set ( 'expect-entries' , 1 )
246+ await npm . exec ( 'query' , [ '#b' ] )
247+ t . equal ( joinedOutput ( ) , '[]' , 'does not have entries' )
248+ t . ok ( process . exitCode , 'exits with code' )
249+ } )
250+ t . end ( )
251+ } )
0 commit comments