@@ -28,15 +28,15 @@ class TestExecutionService implements ITestExecutionService {
28
28
private $options : IOptions ,
29
29
private $pluginsService : IPluginsService ,
30
30
private $errors : IErrors ,
31
- private $androidDebugService :IDebugService ,
31
+ private $androidDebugService : IDebugService ,
32
32
private $iOSDebugService : IDebugService ,
33
33
private $devicesService : Mobile . IDevicesService ,
34
34
private $childProcess : IChildProcess ) {
35
35
}
36
36
37
37
public platform : string ;
38
38
39
- public startTestRunner ( platform : string ) : IFuture < void > {
39
+ public startTestRunner ( platform : string ) : IFuture < void > {
40
40
return ( ( ) => {
41
41
this . platform = platform ;
42
42
this . $options . justlaunch = true ;
@@ -72,7 +72,7 @@ class TestExecutionService implements ITestExecutionService {
72
72
debugService . debugStart ( ) . wait ( ) ;
73
73
}
74
74
blockingOperationFuture . return ( ) ;
75
- } catch ( err ) {
75
+ } catch ( err ) {
76
76
// send the error to the real future
77
77
blockingOperationFuture . throw ( err ) ;
78
78
}
@@ -91,45 +91,49 @@ class TestExecutionService implements ITestExecutionService {
91
91
platform = platform . toLowerCase ( ) ;
92
92
this . platform = platform ;
93
93
94
- if ( this . $options . debugBrk && this . $options . watch ) {
94
+ if ( this . $options . debugBrk && this . $options . watch ) {
95
95
this . $errors . failWithoutHelp ( "You cannot use --watch and --debug-brk simultaneously. Remove one of the flags and try again." ) ;
96
96
}
97
97
98
- if ( ! this . $platformService . preparePlatform ( platform ) . wait ( ) ) {
99
- this . $errors . failWithoutHelp ( "Verify that listed files are well-formed and try again the operation." ) ;
100
- }
98
+ // We need the dependencies installed here, so we can start the Karma server.
99
+ this . $pluginsService . ensureAllDependenciesAreInstalled ( ) . wait ( ) ;
101
100
102
101
let projectDir = this . $projectData . projectDir ;
103
102
this . $devicesService . initialize ( { platform : platform , deviceId : this . $options . device } ) . wait ( ) ;
104
103
105
104
let karmaConfig = this . getKarmaConfiguration ( platform ) ,
106
105
karmaRunner = this . $childProcess . fork ( path . join ( __dirname , "karma-execution.js" ) ) ;
107
-
108
- karmaRunner . send ( { karmaConfig : karmaConfig } ) ;
109
106
karmaRunner . on ( "message" , ( karmaData : any ) => {
110
107
fiberBootstrap . run ( ( ) => {
111
108
this . $logger . trace ( "## Unit-testing: Parent process received message" , karmaData ) ;
112
109
let port : string ;
113
- if ( karmaData . url ) {
110
+ if ( karmaData . url ) {
114
111
port = karmaData . url . port ;
115
112
let socketIoJsUrl = `http://${ karmaData . url . host } /socket.io/socket.io.js` ;
116
113
let socketIoJs = this . $httpClient . httpRequest ( socketIoJsUrl ) . wait ( ) . body ;
117
114
this . $fs . writeFile ( path . join ( projectDir , TestExecutionService . SOCKETIO_JS_FILE_NAME ) , socketIoJs ) . wait ( ) ;
118
115
}
119
116
120
- if ( karmaData . launcherConfig ) {
117
+ if ( karmaData . launcherConfig ) {
121
118
let configOptions : IKarmaConfigOptions = JSON . parse ( karmaData . launcherConfig ) ;
122
119
let configJs = this . generateConfig ( port , configOptions ) ;
123
120
this . $fs . writeFile ( path . join ( projectDir , TestExecutionService . CONFIG_FILE_NAME ) , configJs ) . wait ( ) ;
124
121
}
125
122
126
- if ( this . $options . debugBrk ) {
123
+ // Prepare the project AFTER the TestExecutionService.CONFIG_FILE_NAME file is created in node_modules
124
+ // so it will be sent to device.
125
+ if ( ! this . $platformService . preparePlatform ( platform ) . wait ( ) ) {
126
+ this . $errors . failWithoutHelp ( "Verify that listed files are well-formed and try again the operation." ) ;
127
+ }
128
+
129
+ if ( this . $options . debugBrk ) {
127
130
this . getDebugService ( platform ) . debug ( ) . wait ( ) ;
128
131
} else {
129
132
this . liveSyncProject ( platform ) . wait ( ) ;
130
133
}
131
134
} ) ;
132
135
} ) ;
136
+
133
137
karmaRunner . on ( "exit" , ( exitCode : number ) => {
134
138
if ( exitCode !== 0 ) {
135
139
//End our process with a non-zero exit code
@@ -140,6 +144,9 @@ class TestExecutionService implements ITestExecutionService {
140
144
karmaFuture . return ( ) ;
141
145
}
142
146
} ) ;
147
+
148
+ karmaRunner . send ( { karmaConfig : karmaConfig } ) ;
149
+
143
150
return karmaFuture ;
144
151
}
145
152
@@ -172,9 +179,9 @@ class TestExecutionService implements ITestExecutionService {
172
179
173
180
private getDebugService ( platform : string ) : IDebugService {
174
181
let lowerCasedPlatform = platform . toLowerCase ( ) ;
175
- if ( lowerCasedPlatform === this . $devicePlatformsConstants . iOS . toLowerCase ( ) ) {
182
+ if ( lowerCasedPlatform === this . $devicePlatformsConstants . iOS . toLowerCase ( ) ) {
176
183
return this . $iOSDebugService ;
177
- } else if ( lowerCasedPlatform === this . $devicePlatformsConstants . Android . toLowerCase ( ) ) {
184
+ } else if ( lowerCasedPlatform === this . $devicePlatformsConstants . Android . toLowerCase ( ) ) {
178
185
return this . $androidDebugService ;
179
186
}
180
187
0 commit comments