@@ -47,23 +47,21 @@ const createCompiler = function(overrides) {
4747} ;
4848
4949const setupTwoCompilerEnvironment = function ( env , compiler1Values , compiler2Values ) {
50- const compilerEnvironment1 = new CompilerEnvironment ( ) ;
51- const compilerEnvironment2 = new CompilerEnvironment ( ) ;
52- const compilers = [
53- Object . assign ( {
54- name : "compiler1"
55- } , ( compiler1Values || { } ) , compilerEnvironment1 . getCompilerStub ( ) ) ,
56- Object . assign ( {
57- name : "compiler2"
58- } , ( compiler2Values || { } ) , compilerEnvironment2 . getCompilerStub ( ) )
59- ] ;
50+ return setupMutliCompilerEnvironment ( env , 2 , [ compiler1Values , compiler2Values ] ) ;
51+ } ;
52+
53+ const setupMutliCompilerEnvironment = function ( env , count , compilerValues ) {
54+ const values = Array . isArray ( compilerValues ) ? compilerValues : new Array ( count ) ;
55+ const environments = values . map ( ( ) => new CompilerEnvironment ( ) ) ;
56+ const compilers = environments . map ( ( e , i ) => Object . assign ( {
57+ name : `compiler${ i + 1 } `
58+ } , ( values [ i ] || { } ) , e . getCompilerStub ( ) ) ) ;
6059 env . myMultiCompiler = new MultiCompiler ( compilers ) ;
61- env . compiler1EventBindings = compilerEnvironment1 . getPluginEventBindings ( ) ;
62- env . compiler2EventBindings = compilerEnvironment2 . getPluginEventBindings ( ) ;
63- env . compiler1WatchCallbacks = compilerEnvironment1 . getWatchCallbacks ( ) ;
64- env . compiler2WatchCallbacks = compilerEnvironment2 . getWatchCallbacks ( ) ;
65- env . compiler1RunCallbacks = compilerEnvironment1 . getRunCallbacks ( ) ;
66- env . compiler2RunCallbacks = compilerEnvironment2 . getRunCallbacks ( ) ;
60+ environments . forEach ( ( compilerEnvironment , i ) => {
61+ env [ `compiler${ i + 1 } EventBindings` ] = compilerEnvironment . getPluginEventBindings ( ) ;
62+ env [ `compiler${ i + 1 } WatchCallbacks` ] = compilerEnvironment . getWatchCallbacks ( ) ;
63+ env [ `compiler${ i + 1 } RunCallbacks` ] = compilerEnvironment . getRunCallbacks ( ) ;
64+ } ) ;
6765} ;
6866
6967describe ( "MultiCompiler" , ( ) => {
@@ -450,6 +448,36 @@ describe("MultiCompiler", () => {
450448 should ( env . callback . getCall ( 0 ) . args [ 1 ] ) . be . undefined ( ) ;
451449 } ) ;
452450 } ) ;
451+
452+ describe ( "with no root compiler" , ( ) => {
453+ beforeEach ( ( ) => {
454+ setupMutliCompilerEnvironment ( env , 3 , [ {
455+ name : "a" ,
456+ } , {
457+ name : "b" ,
458+ dependencies : [ "a" , "c" ]
459+ } , {
460+ name : "c" ,
461+ dependencies : [ "b" ]
462+ } ] ) ;
463+ env . callback = sinon . spy ( ) ;
464+ env . options = [ {
465+ testWatchOptions : true
466+ } , {
467+ testWatchOptions2 : true
468+ } ] ;
469+ env . result = env . myMultiCompiler . watch ( env . options , env . callback ) ;
470+ } ) ;
471+
472+ it ( "should call the callback with an error message" , ( ) => {
473+ env . compiler1RunCallbacks . length . should . be . exactly ( 0 ) ;
474+ env . compiler2RunCallbacks . length . should . be . exactly ( 0 ) ;
475+ env . compiler3RunCallbacks . length . should . be . exactly ( 0 ) ;
476+ env . callback . callCount . should . be . exactly ( 1 ) ;
477+ env . callback . getCall ( 0 ) . args [ 0 ] . should . be . Error ( ) ;
478+ should ( env . callback . getCall ( 0 ) . args [ 1 ] ) . be . undefined ( ) ;
479+ } ) ;
480+ } ) ;
453481 } ) ;
454482
455483 describe ( "run" , ( ) => {
@@ -585,6 +613,31 @@ describe("MultiCompiler", () => {
585613 should ( env . callback . getCall ( 0 ) . args [ 1 ] ) . be . undefined ( ) ;
586614 } ) ;
587615 } ) ;
616+
617+ describe ( "with no root compiler" , ( ) => {
618+ beforeEach ( ( ) => {
619+ setupMutliCompilerEnvironment ( env , 3 , [ {
620+ name : "a" ,
621+ } , {
622+ name : "b" ,
623+ dependencies : [ "a" , "c" ]
624+ } , {
625+ name : "c" ,
626+ dependencies : [ "b" ]
627+ } ] ) ;
628+ env . callback = sinon . spy ( ) ;
629+ env . myMultiCompiler . run ( env . callback ) ;
630+ } ) ;
631+
632+ it ( "should call the callback with an error message" , ( ) => {
633+ env . compiler1RunCallbacks . length . should . be . exactly ( 0 ) ;
634+ env . compiler2RunCallbacks . length . should . be . exactly ( 0 ) ;
635+ env . compiler3RunCallbacks . length . should . be . exactly ( 0 ) ;
636+ env . callback . callCount . should . be . exactly ( 1 ) ;
637+ env . callback . getCall ( 0 ) . args [ 0 ] . should . be . Error ( ) ;
638+ should ( env . callback . getCall ( 0 ) . args [ 1 ] ) . be . undefined ( ) ;
639+ } ) ;
640+ } ) ;
588641 } ) ;
589642
590643 describe ( "purgeInputFileSystem" , ( ) => {
0 commit comments