Update phantom reporter to use Jasmine 2.x reporter interface

Includes support for pending specs
This commit is contained in:
Sheel Choksi and Tim Jarratt 2013-10-25 17:45:39 -07:00 committed by Rajan Agaskar and Sheel Choksi
parent a78d1cd558
commit cbb57ff310
2 changed files with 42 additions and 85 deletions

View File

@ -121,12 +121,7 @@ module.exports = function(grunt) {
var thisRun = {}; var thisRun = {};
status = { status = {
specs : 0,
failed : 0, failed : 0,
passed : 0,
total : 0,
skipped : 0,
duration : 0,
log : '' log : ''
}; };
@ -159,51 +154,46 @@ module.exports = function(grunt) {
grunt.event.emit.apply(grunt.event, args); grunt.event.emit.apply(grunt.event, args);
}); });
phantomjs.on('jasmine.reportRunnerStarting',function(suites) { phantomjs.on('jasmine.reportRunnerStarting',function() {
grunt.verbose.writeln('Starting...'); grunt.verbose.writeln('Starting...');
thisRun.start_time = (new Date()).getTime(); thisRun.start_time = (new Date()).getTime();
thisRun.executed_specs = 0; thisRun.executed_specs = 0;
thisRun.passed_specs = 0; thisRun.passed_specs = 0;
}); });
phantomjs.on('jasmine.reportSpecStarting',function(spec) { phantomjs.on('jasmine.reportSpecStarting',function(specMetadata) {
thisRun.executed_specs++; thisRun.executed_specs++;
grunt.verbose.write(spec.suite.description + ':' + spec.description + '...'); grunt.verbose.write(specMetadata.fullName + '...');
}); });
phantomjs.on('jasmine.reportSuiteResults',function(suite){ phantomjs.on('jasmine.reportSpecResults',function(specMetadata) {
//grunt.verbose.writeln(suite.description + ": " + suite.results.passedCount + " of " + suite.results.totalCount + " passed."); if (specMetadata.status === "passed") thisRun.passed_specs++;
});
phantomjs.on('jasmine.reportSpecResults',function(specId, result, fullName) { if (specMetadata.status === "passed") {
if (result.passed) thisRun.passed_specs++; grunt.verbose.writeln(specMetadata.description + ': ' + specMetadata.status.green);
if (!grunt.option('verbose'))
if (!result.passed) { grunt.log.write('.'.green);
} else if (specMetadata.status === "failed") {
if (grunt.option('verbose')) if (grunt.option('verbose'))
grunt.verbose.writeln(result.description + ': ' + result.msg.red); grunt.verbose.writeln(specMetadata.description + ': ' + specMetadata.status.red);
else { else {
logWrite(fullName + ': ' + result.msg.red); logWrite(specMetadata.fullName + ': ' + specMetadata.status.red);
grunt.log.write('x'.red); grunt.log.write('x'.red);
} }
} else { } else {
grunt.verbose.writeln(result.description + ': ' + result.msg.green); grunt.verbose.writeln(specMetadata.description + ': ' + specMetadata.status.yellow);
if (!grunt.option('verbose')) if (!grunt.option('verbose'))
grunt.log.write('.'); grunt.log.write('P'.yellow);
} }
for (var i = 0; i < result.messages.length; i++) { for (var i = 0; i < specMetadata.failedExpectations.length; i++) {
var item = result.messages[i]; var item = specMetadata.failedExpectations[i];
if (item.type === 'log') {
grunt.verbose.writeln(item.toString());
} else if (item.type === 'expect' && !item.passed_) {
var specIndex = ' ('+(i+1)+')'; var specIndex = ' ('+(i+1)+')';
logWrite(' ' + item.message.red+specIndex.red); logWrite(' ' + item.message.red+specIndex.red);
phantomjs.emit('onError', item.message, item.trace); phantomjs.emit('onError', item.message, item.stack);
} }
} phantomjs.emit('jasmine.testDone', specMetadata.failedExpectations.length);
phantomjs.emit( 'jasmine.testDone', result.totalCount, result.passedCount, result.failedCount, result.skipped );
}); });
phantomjs.on('jasmine.reportRunnerResults',function(){ phantomjs.on('jasmine.reportRunnerResults',function(){
@ -220,12 +210,8 @@ module.exports = function(grunt) {
grunt.log.writeln(spec_str + 'in ' + (dur/1000) + "s."); grunt.log.writeln(spec_str + 'in ' + (dur/1000) + "s.");
}); });
phantomjs.on('jasmine.testDone',function(totalAssertions, passedAssertions, failedAssertions, skippedAssertions){ phantomjs.on('jasmine.testDone',function(failedAssertions) {
status.specs++;
status.failed += failedAssertions; status.failed += failedAssertions;
status.passed += passedAssertions;
status.total += totalAssertions;
status.skipped += skippedAssertions;
}); });
phantomjs.on('jasmine.reportJUnitResults',function(junitData){ phantomjs.on('jasmine.reportJUnitResults',function(junitData){
@ -247,7 +233,6 @@ module.exports = function(grunt) {
phantomjs.on('jasmine.done',function(elapsed){ phantomjs.on('jasmine.done',function(elapsed){
phantomjs.halt(); phantomjs.halt();
status.duration = elapsed;
}); });
phantomjs.on('jasmine.done.PhantomReporter',function(){ phantomjs.on('jasmine.done.PhantomReporter',function(){

View File

@ -30,27 +30,19 @@ phantom.sendMessage = function() {
this.buffer = ''; this.buffer = '';
} }
PhantomReporter.prototype.reportRunnerStarting = function(runner) { PhantomReporter.prototype.jasmineStarted = function() {
this.started = true; this.started = true;
phantom.sendMessage('jasmine.reportRunnerStarting');
};
var suites = runner.topLevelSuites(); PhantomReporter.prototype.specStarted = function(specMetadata) {
for (var i = 0; i < suites.length; i++) { specMetadata.startTime = (new Date()).getTime();
var suite = suites[i]; phantom.sendMessage('jasmine.reportSpecStarting', specMetadata);
this.suites_.push(this.summarize_(suite)); };
PhantomReporter.prototype.suiteStarted = function(suiteMetadata) {
suiteMetadata.startTime = (new Date()).getTime();
} }
phantom.sendMessage('jasmine.reportRunnerStarting', this.suites_);
};
PhantomReporter.prototype.reportSpecStarting = function(spec) {
spec.startTime = (new Date()).getTime();
var message = {
suite : {
description : spec.suite.description
},
description : spec.description
};
phantom.sendMessage('jasmine.reportSpecStarting', message);
};
PhantomReporter.prototype.suites = function() { PhantomReporter.prototype.suites = function() {
return this.suites_; return this.suites_;
@ -90,24 +82,15 @@ phantom.sendMessage = function() {
return result; return result;
} }
PhantomReporter.prototype.reportRunnerResults = function(runner) { PhantomReporter.prototype.jasmineDone = function() {
this.finished = true; this.finished = true;
var specIds = map(runner.specs(), function(a){return a.id;}); phantom.sendMessage('jasmine.reportRunnerResults');
var summary = this.resultsForSpecs(specIds); //phantom.sendMessage('jasmine.reportJUnitResults', this.generateJUnitSummary(runner));
phantom.sendMessage('jasmine.reportRunnerResults',summary);
phantom.sendMessage('jasmine.reportJUnitResults', this.generateJUnitSummary(runner));
phantom.sendMessage('jasmine.done.PhantomReporter'); phantom.sendMessage('jasmine.done.PhantomReporter');
}; };
PhantomReporter.prototype.reportSuiteResults = function(suite) { PhantomReporter.prototype.suiteDone = function(suiteMetadata) {
if (suite.specs().length) { suiteMetadata.duration = (new Date()).getTime() - suiteMetadata.startTime;
suite.timestamp = new Date();
suite.duration = suite.timestamp.getTime() - suite.specs()[0].startTime;
phantom.sendMessage('jasmine.reportSuiteResults',{
description : suite.description,
results : suite.results()
});
}
}; };
function stringify(obj) { function stringify(obj) {
@ -147,24 +130,13 @@ phantom.sendMessage = function() {
return string; return string;
} }
PhantomReporter.prototype.reportSpecResults = function(spec) { PhantomReporter.prototype.specDone = function(specMetadata) {
spec.duration = (new Date()).getTime() - spec.startTime; specMetadata.duration = (new Date()).getTime() - specMetadata.startTime;
var _results = spec.results(); this.results_[specMetadata.id] = specMetadata;
var results = {
description : _results.description,
messages : _results.getItems(),
failedCount : _results.failedCount,
totalCount : _results.totalCount,
passedCount : _results.passedCount,
skipped : _results.skipped,
passed : _results.passed(),
msg : _results.failedCount > 0 ? "failed" : "passed"
};
this.results_[spec.id] = results;
// Quick hack to alleviate cyclical object breaking JSONification. // Quick hack to alleviate cyclical object breaking JSONification.
for (var ii = 0; ii < results.messages.length; ii++) { for (var ii = 0; ii < specMetadata.failedExpectations.length; ii++) {
var item = results.messages[ii]; var item = specMetadata.failedExpectations[ii];
if (item.expected) { if (item.expected) {
item.expected = stringify(item.expected); item.expected = stringify(item.expected);
} }
@ -173,7 +145,7 @@ phantom.sendMessage = function() {
} }
} }
phantom.sendMessage( 'jasmine.reportSpecResults', spec.id, results, this.getFullName(spec)); phantom.sendMessage( 'jasmine.reportSpecResults', specMetadata);
}; };
PhantomReporter.prototype.getFullName = function(spec) { PhantomReporter.prototype.getFullName = function(spec) {