Skip to content

Exit with non-zero code on test failures. #1818

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
Jun 9, 2016
Merged
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion lib/services/karma-execution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ process.on("message", (data: any) => {
if(data.karmaConfig) {
let pathToKarma = path.join(data.karmaConfig.projectDir, 'node_modules/karma'),
KarmaServer = require(path.join(pathToKarma, 'lib/server')),
karma = new KarmaServer(data.karmaConfig);
karma = new KarmaServer(data.karmaConfig, (exitCode: number) => {
//Exit with the correct exit code and signal the manager process.
process.exit(exitCode);
});

karma.start();
}
Expand Down
85 changes: 48 additions & 37 deletions lib/services/test-execution-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,50 +97,61 @@ class TestExecutionService implements ITestExecutionService {
}

public startKarmaServer(platform: string): IFuture<void> {
return (() => {
platform = platform.toLowerCase();
this.platform = platform;
let karmaFuture = new Future<void>();

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.");
}
platform = platform.toLowerCase();
this.platform = platform;

let projectDir = this.$projectData.projectDir;
this.$devicesService.initialize({ platform: platform, deviceId: this.$options.device }).wait();
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.");
}

let karmaConfig = this.getKarmaConfiguration(platform),
karmaRunner = this.$childProcess.fork(path.join(__dirname, "karma-execution.js"));
if (!this.$platformService.preparePlatform(platform).wait()) {
this.$errors.failWithoutHelp("Verify that listed files are well-formed and try again the operation.");
}

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) {
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();
}
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) {
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) {
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(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) {
this.getDebugService(platform).debug().wait();
} else {
this.liveSyncProject(platform).wait();
}
});
if(this.$options.debugBrk) {
this.getDebugService(platform).debug().wait();
} else {
this.liveSyncProject(platform).wait();
}
});
}).future<void>()();
});
karmaRunner.on("exit", (exitCode: number) => {
if (exitCode !== 0) {
//End our process with a non-zero exit code
const testError = <any>new Error("Test run failed.");
testError.suppressCommandHelp = true;
karmaFuture.throw(testError);
} else {
karmaFuture.return();
}
});
return karmaFuture;
}

allowedParameters: ICommandParameter[] = [];
Expand Down