diff --git a/lib/cli.js b/lib/cli.js index b9fe16361..b27d9f122 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -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'). diff --git a/lib/frameworks/jasmine.js b/lib/frameworks/jasmine.js index 4cae42b82..3c2ce94f5 100644 --- a/lib/frameworks/jasmine.js +++ b/lib/frameworks/jasmine.js @@ -1,4 +1,5 @@ var q = require('q'); +var fs = require('fs'); /** * Execute the Runner's test cases through Jasmine. @@ -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() {};