@@ -97,50 +97,61 @@ class TestExecutionService implements ITestExecutionService {
9797 }
9898
9999 public startKarmaServer ( platform : string ) : IFuture < void > {
100- return ( ( ) => {
101- platform = platform . toLowerCase ( ) ;
102- this . platform = platform ;
100+ let karmaFuture = new Future < void > ( ) ;
103101
104- if ( this . $options . debugBrk && this . $options . watch ) {
105- this . $errors . failWithoutHelp ( "You cannot use --watch and --debug-brk simultaneously. Remove one of the flags and try again." ) ;
106- }
107-
108- if ( ! this . $platformService . preparePlatform ( platform ) . wait ( ) ) {
109- this . $errors . failWithoutHelp ( "Verify that listed files are well-formed and try again the operation." ) ;
110- }
102+ platform = platform . toLowerCase ( ) ;
103+ this . platform = platform ;
111104
112- let projectDir = this . $projectData . projectDir ;
113- this . $devicesService . initialize ( { platform : platform , deviceId : this . $options . device } ) . wait ( ) ;
105+ if ( this . $options . debugBrk && this . $options . watch ) {
106+ this . $errors . failWithoutHelp ( "You cannot use --watch and --debug-brk simultaneously. Remove one of the flags and try again." ) ;
107+ }
114108
115- let karmaConfig = this . getKarmaConfiguration ( platform ) ,
116- karmaRunner = this . $childProcess . fork ( path . join ( __dirname , "karma-execution.js" ) ) ;
109+ if ( ! this . $platformService . preparePlatform ( platform ) . wait ( ) ) {
110+ this . $errors . failWithoutHelp ( "Verify that listed files are well-formed and try again the operation." ) ;
111+ }
117112
118- karmaRunner . send ( { karmaConfig : karmaConfig } ) ;
119- karmaRunner . on ( "message" , ( karmaData : any ) => {
120- fiberBootstrap . run ( ( ) => {
121- this . $logger . trace ( "## Unit-testing: Parent process received message" , karmaData ) ;
122- let port : string ;
123- if ( karmaData . url ) {
124- port = karmaData . url . port ;
125- let socketIoJsUrl = `http://${ karmaData . url . host } /socket.io/socket.io.js` ;
126- let socketIoJs = this . $httpClient . httpRequest ( socketIoJsUrl ) . wait ( ) . body ;
127- this . $fs . writeFile ( path . join ( projectDir , TestExecutionService . SOCKETIO_JS_FILE_NAME ) , socketIoJs ) . wait ( ) ;
128- }
113+ let projectDir = this . $projectData . projectDir ;
114+ this . $devicesService . initialize ( { platform : platform , deviceId : this . $options . device } ) . wait ( ) ;
115+
116+ let karmaConfig = this . getKarmaConfiguration ( platform ) ,
117+ karmaRunner = this . $childProcess . fork ( path . join ( __dirname , "karma-execution.js" ) ) ;
118+
119+ karmaRunner . send ( { karmaConfig : karmaConfig } ) ;
120+ karmaRunner . on ( "message" , ( karmaData : any ) => {
121+ fiberBootstrap . run ( ( ) => {
122+ this . $logger . trace ( "## Unit-testing: Parent process received message" , karmaData ) ;
123+ let port : string ;
124+ if ( karmaData . url ) {
125+ port = karmaData . url . port ;
126+ let socketIoJsUrl = `http://${ karmaData . url . host } /socket.io/socket.io.js` ;
127+ let socketIoJs = this . $httpClient . httpRequest ( socketIoJsUrl ) . wait ( ) . body ;
128+ this . $fs . writeFile ( path . join ( projectDir , TestExecutionService . SOCKETIO_JS_FILE_NAME ) , socketIoJs ) . wait ( ) ;
129+ }
129130
130- if ( karmaData . launcherConfig ) {
131- let configOptions : IKarmaConfigOptions = JSON . parse ( karmaData . launcherConfig ) ;
132- let configJs = this . generateConfig ( port , configOptions ) ;
133- this . $fs . writeFile ( path . join ( projectDir , TestExecutionService . CONFIG_FILE_NAME ) , configJs ) . wait ( ) ;
134- }
131+ if ( karmaData . launcherConfig ) {
132+ let configOptions : IKarmaConfigOptions = JSON . parse ( karmaData . launcherConfig ) ;
133+ let configJs = this . generateConfig ( port , configOptions ) ;
134+ this . $fs . writeFile ( path . join ( projectDir , TestExecutionService . CONFIG_FILE_NAME ) , configJs ) . wait ( ) ;
135+ }
135136
136- if ( this . $options . debugBrk ) {
137- this . getDebugService ( platform ) . debug ( ) . wait ( ) ;
138- } else {
139- this . liveSyncProject ( platform ) . wait ( ) ;
140- }
141- } ) ;
137+ if ( this . $options . debugBrk ) {
138+ this . getDebugService ( platform ) . debug ( ) . wait ( ) ;
139+ } else {
140+ this . liveSyncProject ( platform ) . wait ( ) ;
141+ }
142142 } ) ;
143- } ) . future < void > ( ) ( ) ;
143+ } ) ;
144+ karmaRunner . on ( "exit" , ( exitCode : number ) => {
145+ if ( exitCode !== 0 ) {
146+ //End our process with a non-zero exit code
147+ const testError = < any > new Error ( "Test run failed." ) ;
148+ testError . suppressCommandHelp = true ;
149+ karmaFuture . throw ( testError ) ;
150+ } else {
151+ karmaFuture . return ( ) ;
152+ }
153+ } ) ;
154+ return karmaFuture ;
144155 }
145156
146157 allowedParameters : ICommandParameter [ ] = [ ] ;
0 commit comments