Skip to content
This repository has been archived by the owner on Jul 29, 2024. It is now read-only.

Commit

Permalink
feat(frameworks/cli): add ability for jasmine to produce json result …
Browse files Browse the repository at this point in the history
…output
  • Loading branch information
hankduan committed Oct 16, 2014
1 parent 9cc0f63 commit 39d4785
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ var optimist = require('optimist').
describe('stackTrace', 'Print stack trace on error').
describe('params', 'Param object to be passed to the tests').
describe('framework', 'Test framework to use: jasmine, cucumber or mocha').
describe('testResultOutput', 'Path to save JSON test result (Jasmine only)').
alias('browser', 'capabilities.browserName').
alias('name', 'capabilities.name').
alias('platform', 'capabilities.platform').
Expand Down
32 changes: 30 additions & 2 deletions lib/frameworks/jasmine.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var q = require('q');
var fs = require('fs');

/**
* Execute the Runner's test cases through Jasmine.
Expand All @@ -15,18 +16,45 @@ exports.run = function(runner, specs) {

var RunnerReporter = function(emitter) {
this.emitter = emitter;
this.jsonOutput = [];
};

RunnerReporter.prototype.reportRunnerStarting = function() {};
RunnerReporter.prototype.reportRunnerResults = function() {};
RunnerReporter.prototype.reportRunnerResults = function() {
if (runner.getConfig().testResultOutput) {
var json = JSON.stringify(this.jsonOutput, null, ' ');
fs.writeFile(runner.getConfig().testResultOutput, json, function(err) {
if(err) {
throw err;
}
});
}
};
RunnerReporter.prototype.reportSuiteResults = function() {};
RunnerReporter.prototype.reportSpecStarting = function() {};
RunnerReporter.prototype.reportSpecStarting = function() {
this.startTime = new Date();
};
RunnerReporter.prototype.reportSpecResults = function(spec) {
if (spec.results().passed()) {
this.emitter.emit('testPass');
} else {
this.emitter.emit('testFail');
}

if (runner.getConfig().testResultOutput) {
var entry = {
result: [],
duration: new Date().getTime() - this.startTime.getTime()
};
spec.results().getItems().forEach(function(item) {
entry.result.push({
passed: item.passed(),
errorMsg: item.message,
stacktrace: item.trace.stack
});
});
this.jsonOutput.push(entry);
}
};
RunnerReporter.prototype.log = function() {};

Expand Down

0 comments on commit 39d4785

Please sign in to comment.