Update phantom reporter to use Jasmine 2.x reporter interface
Includes support for pending specs
This commit is contained in:
parent
a78d1cd558
commit
cbb57ff310
@ -121,12 +121,7 @@ module.exports = function(grunt) {
|
||||
var thisRun = {};
|
||||
|
||||
status = {
|
||||
specs : 0,
|
||||
failed : 0,
|
||||
passed : 0,
|
||||
total : 0,
|
||||
skipped : 0,
|
||||
duration : 0,
|
||||
log : ''
|
||||
};
|
||||
|
||||
@ -159,51 +154,46 @@ module.exports = function(grunt) {
|
||||
grunt.event.emit.apply(grunt.event, args);
|
||||
});
|
||||
|
||||
phantomjs.on('jasmine.reportRunnerStarting',function(suites) {
|
||||
phantomjs.on('jasmine.reportRunnerStarting',function() {
|
||||
grunt.verbose.writeln('Starting...');
|
||||
thisRun.start_time = (new Date()).getTime();
|
||||
thisRun.executed_specs = 0;
|
||||
thisRun.passed_specs = 0;
|
||||
});
|
||||
|
||||
phantomjs.on('jasmine.reportSpecStarting',function(spec) {
|
||||
phantomjs.on('jasmine.reportSpecStarting',function(specMetadata) {
|
||||
thisRun.executed_specs++;
|
||||
grunt.verbose.write(spec.suite.description + ':' + spec.description + '...');
|
||||
grunt.verbose.write(specMetadata.fullName + '...');
|
||||
});
|
||||
|
||||
phantomjs.on('jasmine.reportSuiteResults',function(suite){
|
||||
//grunt.verbose.writeln(suite.description + ": " + suite.results.passedCount + " of " + suite.results.totalCount + " passed.");
|
||||
});
|
||||
phantomjs.on('jasmine.reportSpecResults',function(specMetadata) {
|
||||
if (specMetadata.status === "passed") thisRun.passed_specs++;
|
||||
|
||||
phantomjs.on('jasmine.reportSpecResults',function(specId, result, fullName) {
|
||||
if (result.passed) thisRun.passed_specs++;
|
||||
|
||||
if (!result.passed) {
|
||||
if (specMetadata.status === "passed") {
|
||||
grunt.verbose.writeln(specMetadata.description + ': ' + specMetadata.status.green);
|
||||
if (!grunt.option('verbose'))
|
||||
grunt.log.write('.'.green);
|
||||
} else if (specMetadata.status === "failed") {
|
||||
if (grunt.option('verbose'))
|
||||
grunt.verbose.writeln(result.description + ': ' + result.msg.red);
|
||||
grunt.verbose.writeln(specMetadata.description + ': ' + specMetadata.status.red);
|
||||
else {
|
||||
logWrite(fullName + ': ' + result.msg.red);
|
||||
logWrite(specMetadata.fullName + ': ' + specMetadata.status.red);
|
||||
grunt.log.write('x'.red);
|
||||
}
|
||||
} else {
|
||||
grunt.verbose.writeln(result.description + ': ' + result.msg.green);
|
||||
grunt.verbose.writeln(specMetadata.description + ': ' + specMetadata.status.yellow);
|
||||
if (!grunt.option('verbose'))
|
||||
grunt.log.write('.');
|
||||
grunt.log.write('P'.yellow);
|
||||
}
|
||||
|
||||
for (var i = 0; i < result.messages.length; i++) {
|
||||
var item = result.messages[i];
|
||||
for (var i = 0; i < specMetadata.failedExpectations.length; 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)+')';
|
||||
logWrite(' ' + item.message.red+specIndex.red);
|
||||
phantomjs.emit('onError', item.message, item.trace);
|
||||
}
|
||||
var specIndex = ' ('+(i+1)+')';
|
||||
logWrite(' ' + item.message.red+specIndex.red);
|
||||
phantomjs.emit('onError', item.message, item.stack);
|
||||
}
|
||||
phantomjs.emit( 'jasmine.testDone', result.totalCount, result.passedCount, result.failedCount, result.skipped );
|
||||
|
||||
phantomjs.emit('jasmine.testDone', specMetadata.failedExpectations.length);
|
||||
});
|
||||
|
||||
phantomjs.on('jasmine.reportRunnerResults',function(){
|
||||
@ -220,12 +210,8 @@ module.exports = function(grunt) {
|
||||
grunt.log.writeln(spec_str + 'in ' + (dur/1000) + "s.");
|
||||
});
|
||||
|
||||
phantomjs.on('jasmine.testDone',function(totalAssertions, passedAssertions, failedAssertions, skippedAssertions){
|
||||
status.specs++;
|
||||
status.failed += failedAssertions;
|
||||
status.passed += passedAssertions;
|
||||
status.total += totalAssertions;
|
||||
status.skipped += skippedAssertions;
|
||||
phantomjs.on('jasmine.testDone',function(failedAssertions) {
|
||||
status.failed += failedAssertions;
|
||||
});
|
||||
|
||||
phantomjs.on('jasmine.reportJUnitResults',function(junitData){
|
||||
@ -247,7 +233,6 @@ module.exports = function(grunt) {
|
||||
|
||||
phantomjs.on('jasmine.done',function(elapsed){
|
||||
phantomjs.halt();
|
||||
status.duration = elapsed;
|
||||
});
|
||||
|
||||
phantomjs.on('jasmine.done.PhantomReporter',function(){
|
||||
|
@ -30,28 +30,20 @@ phantom.sendMessage = function() {
|
||||
this.buffer = '';
|
||||
}
|
||||
|
||||
PhantomReporter.prototype.reportRunnerStarting = function(runner) {
|
||||
PhantomReporter.prototype.jasmineStarted = function() {
|
||||
this.started = true;
|
||||
|
||||
var suites = runner.topLevelSuites();
|
||||
for (var i = 0; i < suites.length; i++) {
|
||||
var suite = suites[i];
|
||||
this.suites_.push(this.summarize_(suite));
|
||||
}
|
||||
phantom.sendMessage('jasmine.reportRunnerStarting', this.suites_);
|
||||
phantom.sendMessage('jasmine.reportRunnerStarting');
|
||||
};
|
||||
|
||||
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.specStarted = function(specMetadata) {
|
||||
specMetadata.startTime = (new Date()).getTime();
|
||||
phantom.sendMessage('jasmine.reportSpecStarting', specMetadata);
|
||||
};
|
||||
|
||||
PhantomReporter.prototype.suiteStarted = function(suiteMetadata) {
|
||||
suiteMetadata.startTime = (new Date()).getTime();
|
||||
}
|
||||
|
||||
PhantomReporter.prototype.suites = function() {
|
||||
return this.suites_;
|
||||
};
|
||||
@ -90,24 +82,15 @@ phantom.sendMessage = function() {
|
||||
return result;
|
||||
}
|
||||
|
||||
PhantomReporter.prototype.reportRunnerResults = function(runner) {
|
||||
PhantomReporter.prototype.jasmineDone = function() {
|
||||
this.finished = true;
|
||||
var specIds = map(runner.specs(), function(a){return a.id;});
|
||||
var summary = this.resultsForSpecs(specIds);
|
||||
phantom.sendMessage('jasmine.reportRunnerResults',summary);
|
||||
phantom.sendMessage('jasmine.reportJUnitResults', this.generateJUnitSummary(runner));
|
||||
phantom.sendMessage('jasmine.reportRunnerResults');
|
||||
//phantom.sendMessage('jasmine.reportJUnitResults', this.generateJUnitSummary(runner));
|
||||
phantom.sendMessage('jasmine.done.PhantomReporter');
|
||||
};
|
||||
|
||||
PhantomReporter.prototype.reportSuiteResults = function(suite) {
|
||||
if (suite.specs().length) {
|
||||
suite.timestamp = new Date();
|
||||
suite.duration = suite.timestamp.getTime() - suite.specs()[0].startTime;
|
||||
phantom.sendMessage('jasmine.reportSuiteResults',{
|
||||
description : suite.description,
|
||||
results : suite.results()
|
||||
});
|
||||
}
|
||||
PhantomReporter.prototype.suiteDone = function(suiteMetadata) {
|
||||
suiteMetadata.duration = (new Date()).getTime() - suiteMetadata.startTime;
|
||||
};
|
||||
|
||||
function stringify(obj) {
|
||||
@ -147,24 +130,13 @@ phantom.sendMessage = function() {
|
||||
return string;
|
||||
}
|
||||
|
||||
PhantomReporter.prototype.reportSpecResults = function(spec) {
|
||||
spec.duration = (new Date()).getTime() - spec.startTime;
|
||||
var _results = spec.results();
|
||||
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;
|
||||
PhantomReporter.prototype.specDone = function(specMetadata) {
|
||||
specMetadata.duration = (new Date()).getTime() - specMetadata.startTime;
|
||||
this.results_[specMetadata.id] = specMetadata;
|
||||
|
||||
// Quick hack to alleviate cyclical object breaking JSONification.
|
||||
for (var ii = 0; ii < results.messages.length; ii++) {
|
||||
var item = results.messages[ii];
|
||||
for (var ii = 0; ii < specMetadata.failedExpectations.length; ii++) {
|
||||
var item = specMetadata.failedExpectations[ii];
|
||||
if (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) {
|
||||
|
Loading…
Reference in New Issue
Block a user