@@ -6,6 +6,7 @@ const spawn = require('cross-spawn');
66const installer = require ( '../src/installer' ) ;
77
88describe ( 'installer' , ( ) => {
9+ jest . spyOn ( installer , 'prompt' ) . mockImplementation ( ( ) => true ) ;
910 describe ( '.defaultOptions' , ( ) => {
1011 it ( 'should default dev to false' , ( ) => {
1112 expect ( installer . defaultOptions . dev ) . toEqual ( false ) ;
@@ -160,18 +161,18 @@ describe('installer', () => {
160161 } ) ;
161162
162163 describe ( 'given a falsey value' , ( ) => {
163- it ( 'should return undefined' , ( ) => {
164- expect ( installer . install ( ) ) . toEqual ( undefined ) ;
165- expect ( installer . install ( 0 ) ) . toEqual ( undefined ) ;
166- expect ( installer . install ( false ) ) . toEqual ( undefined ) ;
167- expect ( installer . install ( null ) ) . toEqual ( undefined ) ;
168- expect ( installer . install ( '' ) ) . toEqual ( undefined ) ;
164+ it ( 'should return undefined' , async ( ) => {
165+ expect ( await installer . install ( ) ) . toEqual ( undefined ) ;
166+ expect ( await installer . install ( 0 ) ) . toEqual ( undefined ) ;
167+ expect ( await installer . install ( false ) ) . toEqual ( undefined ) ;
168+ expect ( await installer . install ( null ) ) . toEqual ( undefined ) ;
169+ expect ( await installer . install ( '' ) ) . toEqual ( undefined ) ;
169170 } ) ;
170171 } ) ;
171172
172173 describe ( 'given an empty array' , ( ) => {
173- it ( 'should return undefined' , ( ) => {
174- expect ( installer . install ( [ ] ) ) . toEqual ( undefined ) ;
174+ it ( 'should return undefined' , async ( ) => {
175+ expect ( await installer . install ( [ ] ) ) . toEqual ( undefined ) ;
175176 } ) ;
176177 } ) ;
177178
@@ -182,14 +183,14 @@ describe('installer', () => {
182183 } ) ;
183184 } ) ;
184185
185- it ( 'should attempt to install once' , ( ) => {
186- installer . install ( 'does.not.exist.jsx' ) ;
186+ it ( 'should attempt to install once' , async ( ) => {
187+ await installer . install ( 'does.not.exist.jsx' ) ;
187188
188189 expect ( this . sync ) . toHaveBeenCalled ( ) ;
189190 } ) ;
190191
191- it ( 'should not attempt to install it again' , ( ) => {
192- installer . install ( 'does.not.exist.jsx' ) ;
192+ it ( 'should not attempt to install it again' , async ( ) => {
193+ await installer . install ( 'does.not.exist.jsx' ) ;
193194
194195 expect ( this . sync ) . not . toHaveBeenCalled ( ) ;
195196 } ) ;
@@ -208,8 +209,8 @@ describe('installer', () => {
208209
209210 describe ( 'given a dependency' , ( ) => {
210211 describe ( 'with no options' , ( ) => {
211- it ( 'should install it with --save' , ( ) => {
212- installer . install ( 'foo' , {
212+ it ( 'should install it with --save' , async ( ) => {
213+ await installer . install ( 'foo' , {
213214 yarn : true ,
214215 } ) ;
215216 expect ( this . sync ) . toHaveBeenCalled ( ) ;
@@ -220,8 +221,8 @@ describe('installer', () => {
220221 } ) ;
221222
222223 describe ( 'with dev set to true' , ( ) => {
223- it ( 'should install it with --dev' , ( ) => {
224- installer . install ( 'foo' , {
224+ it ( 'should install it with --dev' , async ( ) => {
225+ await installer . install ( 'foo' , {
225226 dev : true ,
226227 yarn : true ,
227228 } ) ;
@@ -244,8 +245,8 @@ describe('installer', () => {
244245 jest . clearAllMocks ( ) ;
245246 } ) ;
246247
247- it ( 'should install without options' , ( ) => {
248- installer . install ( 'foo' , {
248+ it ( 'should install without options' , async ( ) => {
249+ await installer . install ( 'foo' , {
249250 yarn : true ,
250251 } ) ;
251252 expect ( this . sync ) . toHaveBeenCalled ( ) ;
@@ -256,8 +257,8 @@ describe('installer', () => {
256257 } ) ;
257258
258259 describe ( 'with quiet set to true' , ( ) => {
259- it ( 'should install it with --silent --noprogress' , ( ) => {
260- installer . install ( 'foo' , {
260+ it ( 'should install it with --silent --noprogress' , async ( ) => {
261+ await installer . install ( 'foo' , {
261262 quiet : true ,
262263 yarn : true ,
263264 } ) ;
@@ -296,8 +297,8 @@ describe('installer', () => {
296297 } ) ;
297298
298299 describe ( 'given no options' , ( ) => {
299- it ( 'should install peerDependencies' , ( ) => {
300- installer . install ( 'redbox-react' , {
300+ it ( 'should install peerDependencies' , async ( ) => {
301+ await installer . install ( 'redbox-react' , {
301302 yarn : true ,
302303 } ) ;
303304
@@ -316,8 +317,8 @@ describe('installer', () => {
316317 } ) ;
317318
318319 describe ( 'given peerDependencies set to false' , ( ) => {
319- it ( 'should not install peerDependencies' , ( ) => {
320- installer . install ( 'redbox-react' , {
320+ it ( 'should not install peerDependencies' , async ( ) => {
321+ await installer . install ( 'redbox-react' , {
321322 peerDependencies : false ,
322323 yarn : true ,
323324 } ) ;
@@ -347,8 +348,8 @@ describe('installer', () => {
347348
348349 describe ( 'given a dependency' , ( ) => {
349350 describe ( 'with no options' , ( ) => {
350- it ( 'should install it with --save' , ( ) => {
351- installer . install ( 'foo' ) ;
351+ it ( 'should install it with --save' , async ( ) => {
352+ await installer . install ( 'foo' ) ;
352353
353354 expect ( this . sync ) . toHaveBeenCalled ( ) ;
354355 expect ( this . sync . mock . calls . length ) . toEqual ( 1 ) ;
@@ -362,8 +363,8 @@ describe('installer', () => {
362363 } ) ;
363364
364365 describe ( 'with dev set to true' , ( ) => {
365- it ( 'should install it with --save-dev' , ( ) => {
366- installer . install ( 'foo' , {
366+ it ( 'should install it with --save-dev' , async ( ) => {
367+ await installer . install ( 'foo' , {
367368 dev : true ,
368369 } ) ;
369370
@@ -389,8 +390,8 @@ describe('installer', () => {
389390 jest . clearAllMocks ( ) ;
390391 } ) ;
391392
392- it ( 'should install without --save' , ( ) => {
393- installer . install ( 'foo' ) ;
393+ it ( 'should install without --save' , async ( ) => {
394+ await installer . install ( 'foo' ) ;
394395 expect ( this . sync ) . toHaveBeenCalled ( ) ;
395396 expect ( this . sync . mock . calls . length ) . toEqual ( 1 ) ;
396397 expect ( this . sync . mock . calls [ 0 ] [ 0 ] ) . toEqual ( 'npm' ) ;
@@ -399,8 +400,8 @@ describe('installer', () => {
399400 } ) ;
400401
401402 describe ( 'with quiet set to true' , ( ) => {
402- it ( 'should install it with --silent --noprogress' , ( ) => {
403- installer . install ( 'foo' , {
403+ it ( 'should install it with --silent --noprogress' , async ( ) => {
404+ await installer . install ( 'foo' , {
404405 quiet : true ,
405406 } ) ;
406407
@@ -440,8 +441,8 @@ describe('installer', () => {
440441 } ) ;
441442
442443 describe ( 'given no options' , ( ) => {
443- it ( 'should install peerDependencies' , ( ) => {
444- installer . install ( 'redbox-react' ) ;
444+ it ( 'should install peerDependencies' , async ( ) => {
445+ await installer . install ( 'redbox-react' ) ;
445446
446447 expect ( this . sync . mock . calls . length ) . toEqual ( 2 ) ;
447448 expect ( this . sync . mock . calls [ 0 ] [ 1 ] ) . toEqual ( [
@@ -460,8 +461,8 @@ describe('installer', () => {
460461 } ) ;
461462
462463 describe ( 'given peerDependencies set to false' , ( ) => {
463- it ( 'should not install peerDependencies' , ( ) => {
464- installer . install ( 'redbox-react' , {
464+ it ( 'should not install peerDependencies' , async ( ) => {
465+ await installer . install ( 'redbox-react' , {
465466 peerDependencies : false ,
466467 } ) ;
467468
0 commit comments