@@ -54,6 +54,7 @@ function unlinkSyncSafe(dir) {
5454
5555describe ( "execa-webpack-plugin" , ( ) => {
5656 const dir = path . join ( __dirname , "dir" ) ;
57+ const otherDir = path . join ( __dirname , "other-dir" ) ;
5758
5859 it ( "should throw error when `onBuildStart`, `onBuildEnd` and `onBuildExit` options are empty" , ( ) =>
5960 expect ( ( ) => run ( ) ) . toThrow ( ) ) ;
@@ -198,7 +199,6 @@ describe("execa-webpack-plugin", () => {
198199 } ) ;
199200 } ) ;
200201
201- // Need async test
202202 it ( "should throw error with `bail: true` option" , ( ) => {
203203 expect . assertions ( 1 ) ;
204204
@@ -227,6 +227,34 @@ describe("execa-webpack-plugin", () => {
227227 } ) ;
228228 } ) ;
229229
230+ it ( "should throw error with `bail: true` option (async)" , ( ) => {
231+ expect . assertions ( 1 ) ;
232+
233+ let catchError = null ;
234+
235+ return run ( {
236+ bail : true ,
237+ logLevel : "silent" ,
238+ onBuildExit : [
239+ {
240+ cmd : "not-found"
241+ }
242+ ]
243+ } )
244+ . catch ( error => {
245+ catchError = error ;
246+
247+ return Promise . resolve ( ) ;
248+ } )
249+ . then ( ( ) => {
250+ // execa not return error instanceOf Error
251+ // expect(catchError).toBeInstanceOf(Error);
252+ expect ( catchError ) . not . toBeNull ( ) ;
253+
254+ return Promise . resolve ( ) ;
255+ } ) ;
256+ } ) ;
257+
230258 it ( "should works and output 'stdout' and 'stderr' with `logLevel: 'info'` command" , ( ) =>
231259 run ( {
232260 logLevel : "info" ,
@@ -238,6 +266,17 @@ describe("execa-webpack-plugin", () => {
238266 ]
239267 } ) ) ;
240268
269+ it ( "should works and output 'stdout' and 'stderr' with `logLevel: 'info'` command (async)" , ( ) =>
270+ run ( {
271+ logLevel : "info" ,
272+ onBuildExit : [
273+ {
274+ args : [ path . join ( resourcesDir , "cli-stdout-stderr.js" ) ] ,
275+ cmd : "node"
276+ }
277+ ]
278+ } ) ) ;
279+
241280 it ( "should works with nested commands" , ( ) => {
242281 expect . assertions ( 2 ) ;
243282
@@ -266,6 +305,75 @@ describe("execa-webpack-plugin", () => {
266305 } ) ;
267306 } ) ;
268307
308+ it ( "should works with deep nested commands" , ( ) => {
309+ expect . assertions ( 2 ) ;
310+
311+ mkdirSyncSafe ( dir ) ;
312+
313+ expect ( fs . statSync ( dir ) . isDirectory ( ) ) . toBe ( true ) ;
314+
315+ return run ( {
316+ onBuildStart : [
317+ {
318+ args : [
319+ {
320+ args : [
321+ {
322+ args : [ path . join ( resourcesDir , "nested-nested.js" ) ] ,
323+ cmd : "node"
324+ }
325+ ] ,
326+ cmd : "node"
327+ }
328+ ] ,
329+ cmd : "del"
330+ }
331+ ]
332+ } ) . then ( ( ) => {
333+ expect ( ( ) => fs . statSync ( dir ) ) . toThrow ( ) ;
334+
335+ unlinkSyncSafe ( dir ) ;
336+
337+ return Promise . resolve ( ) ;
338+ } ) ;
339+ } ) ;
340+
341+ it ( "should works with multiple nested commands" , ( ) => {
342+ expect . assertions ( 4 ) ;
343+
344+ mkdirSyncSafe ( dir ) ;
345+ mkdirSyncSafe ( otherDir ) ;
346+
347+ expect ( fs . statSync ( dir ) . isDirectory ( ) ) . toBe ( true ) ;
348+ expect ( fs . statSync ( otherDir ) . isDirectory ( ) ) . toBe ( true ) ;
349+
350+ return run ( {
351+ onBuildStart : [
352+ {
353+ args : [
354+ {
355+ args : [ path . join ( resourcesDir , "nested.js" ) ] ,
356+ cmd : "node"
357+ } ,
358+ {
359+ args : [ path . join ( resourcesDir , "nested-other.js" ) ] ,
360+ cmd : "node"
361+ }
362+ ] ,
363+ cmd : "del"
364+ }
365+ ]
366+ } ) . then ( ( ) => {
367+ expect ( ( ) => fs . statSync ( dir ) ) . toThrow ( ) ;
368+ expect ( ( ) => fs . statSync ( otherDir ) ) . toThrow ( ) ;
369+
370+ unlinkSyncSafe ( dir ) ;
371+ unlinkSyncSafe ( otherDir ) ;
372+
373+ return Promise . resolve ( ) ;
374+ } ) ;
375+ } ) ;
376+
269377 it ( "should works with nested commands (async)" , ( ) => {
270378 expect . assertions ( 2 ) ;
271379
@@ -294,6 +402,75 @@ describe("execa-webpack-plugin", () => {
294402 } ) ;
295403 } ) ;
296404
405+ it ( "should works with deep nested commands (async)" , ( ) => {
406+ expect . assertions ( 2 ) ;
407+
408+ mkdirSyncSafe ( dir ) ;
409+
410+ expect ( fs . statSync ( dir ) . isDirectory ( ) ) . toBe ( true ) ;
411+
412+ return run ( {
413+ onBuildExit : [
414+ {
415+ args : [
416+ {
417+ args : [
418+ {
419+ args : [ path . join ( resourcesDir , "nested-nested.js" ) ] ,
420+ cmd : "node"
421+ }
422+ ] ,
423+ cmd : "node"
424+ }
425+ ] ,
426+ cmd : "del"
427+ }
428+ ]
429+ } ) . then ( ( ) => {
430+ expect ( ( ) => fs . statSync ( dir ) ) . toThrow ( ) ;
431+
432+ unlinkSyncSafe ( dir ) ;
433+
434+ return Promise . resolve ( ) ;
435+ } ) ;
436+ } ) ;
437+
438+ it ( "should works with multiple nested commands (async)" , ( ) => {
439+ expect . assertions ( 4 ) ;
440+
441+ mkdirSyncSafe ( dir ) ;
442+ mkdirSyncSafe ( otherDir ) ;
443+
444+ expect ( fs . statSync ( dir ) . isDirectory ( ) ) . toBe ( true ) ;
445+ expect ( fs . statSync ( otherDir ) . isDirectory ( ) ) . toBe ( true ) ;
446+
447+ return run ( {
448+ onBuildExit : [
449+ {
450+ args : [
451+ {
452+ args : [ path . join ( resourcesDir , "nested.js" ) ] ,
453+ cmd : "node"
454+ } ,
455+ {
456+ args : [ path . join ( resourcesDir , "nested-other.js" ) ] ,
457+ cmd : "node"
458+ }
459+ ] ,
460+ cmd : "del"
461+ }
462+ ]
463+ } ) . then ( ( ) => {
464+ expect ( ( ) => fs . statSync ( dir ) ) . toThrow ( ) ;
465+ expect ( ( ) => fs . statSync ( otherDir ) ) . toThrow ( ) ;
466+
467+ unlinkSyncSafe ( dir ) ;
468+ unlinkSyncSafe ( otherDir ) ;
469+
470+ return Promise . resolve ( ) ;
471+ } ) ;
472+ } ) ;
473+
297474 it ( "should works when nested commands return nothing and 'bail: false'" , ( ) => {
298475 expect . assertions ( 1 ) ;
299476
@@ -325,4 +502,36 @@ describe("execa-webpack-plugin", () => {
325502 return Promise . resolve ( ) ;
326503 } ) ;
327504 } ) ;
505+
506+ it ( "should works when nested commands return nothing and 'bail: false' (async)" , ( ) => {
507+ expect . assertions ( 1 ) ;
508+
509+ let catchError = null ;
510+
511+ return run ( {
512+ bail : false ,
513+ logLevel : "silent" ,
514+ onBuildExit : [
515+ {
516+ args : [
517+ {
518+ args : [ path . join ( resourcesDir , "nothing.js" ) ] ,
519+ cmd : "node"
520+ }
521+ ] ,
522+ cmd : "del"
523+ }
524+ ]
525+ } )
526+ . catch ( error => {
527+ catchError = error ;
528+
529+ return Promise . resolve ( ) ;
530+ } )
531+ . then ( ( ) => {
532+ expect ( catchError ) . toBeNull ( ) ;
533+
534+ return Promise . resolve ( ) ;
535+ } ) ;
536+ } ) ;
328537} ) ;
0 commit comments