Skip to content

Fix first unit tests execution #2019

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 30, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 21 additions & 14 deletions lib/services/test-execution-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ class TestExecutionService implements ITestExecutionService {
private $options: IOptions,
private $pluginsService: IPluginsService,
private $errors: IErrors,
private $androidDebugService:IDebugService,
private $androidDebugService: IDebugService,
private $iOSDebugService: IDebugService,
private $devicesService: Mobile.IDevicesService,
private $childProcess: IChildProcess) {
}

public platform: string;

public startTestRunner(platform: string) : IFuture<void> {
public startTestRunner(platform: string): IFuture<void> {
return (() => {
this.platform = platform;
this.$options.justlaunch = true;
Expand Down Expand Up @@ -72,7 +72,7 @@ class TestExecutionService implements ITestExecutionService {
debugService.debugStart().wait();
}
blockingOperationFuture.return();
} catch(err) {
} catch (err) {
// send the error to the real future
blockingOperationFuture.throw(err);
}
Expand All @@ -91,45 +91,49 @@ class TestExecutionService implements ITestExecutionService {
platform = platform.toLowerCase();
this.platform = platform;

if(this.$options.debugBrk && this.$options.watch) {
if (this.$options.debugBrk && this.$options.watch) {
this.$errors.failWithoutHelp("You cannot use --watch and --debug-brk simultaneously. Remove one of the flags and try again.");
}

if (!this.$platformService.preparePlatform(platform).wait()) {
this.$errors.failWithoutHelp("Verify that listed files are well-formed and try again the operation.");
}
// We need the dependencies installed here, so we can start the Karma server.
this.$pluginsService.ensureAllDependenciesAreInstalled().wait();

let projectDir = this.$projectData.projectDir;
this.$devicesService.initialize({ platform: platform, deviceId: this.$options.device }).wait();

let karmaConfig = this.getKarmaConfiguration(platform),
karmaRunner = this.$childProcess.fork(path.join(__dirname, "karma-execution.js"));

karmaRunner.send({karmaConfig: karmaConfig});
karmaRunner.on("message", (karmaData: any) => {
fiberBootstrap.run(() => {
this.$logger.trace("## Unit-testing: Parent process received message", karmaData);
let port: string;
if(karmaData.url) {
if (karmaData.url) {
port = karmaData.url.port;
let socketIoJsUrl = `http://${karmaData.url.host}/socket.io/socket.io.js`;
let socketIoJs = this.$httpClient.httpRequest(socketIoJsUrl).wait().body;
this.$fs.writeFile(path.join(projectDir, TestExecutionService.SOCKETIO_JS_FILE_NAME), socketIoJs).wait();
}

if(karmaData.launcherConfig) {
if (karmaData.launcherConfig) {
let configOptions: IKarmaConfigOptions = JSON.parse(karmaData.launcherConfig);
let configJs = this.generateConfig(port, configOptions);
this.$fs.writeFile(path.join(projectDir, TestExecutionService.CONFIG_FILE_NAME), configJs).wait();
}

if(this.$options.debugBrk) {
// Prepare the project AFTER the TestExecutionService.CONFIG_FILE_NAME file is created in node_modules
// so it will be sent to device.
if (!this.$platformService.preparePlatform(platform).wait()) {
this.$errors.failWithoutHelp("Verify that listed files are well-formed and try again the operation.");
}

if (this.$options.debugBrk) {
this.getDebugService(platform).debug().wait();
} else {
this.liveSyncProject(platform).wait();
}
});
});

karmaRunner.on("exit", (exitCode: number) => {
if (exitCode !== 0) {
//End our process with a non-zero exit code
Expand All @@ -140,6 +144,9 @@ class TestExecutionService implements ITestExecutionService {
karmaFuture.return();
}
});

karmaRunner.send({ karmaConfig: karmaConfig });

return karmaFuture;
}

Expand Down Expand Up @@ -172,9 +179,9 @@ class TestExecutionService implements ITestExecutionService {

private getDebugService(platform: string): IDebugService {
let lowerCasedPlatform = platform.toLowerCase();
if(lowerCasedPlatform === this.$devicePlatformsConstants.iOS.toLowerCase()) {
if (lowerCasedPlatform === this.$devicePlatformsConstants.iOS.toLowerCase()) {
return this.$iOSDebugService;
} else if(lowerCasedPlatform === this.$devicePlatformsConstants.Android.toLowerCase()) {
} else if (lowerCasedPlatform === this.$devicePlatformsConstants.Android.toLowerCase()) {
return this.$androidDebugService;
}

Expand Down