parent
82d37dffe9
commit
b74dcac449
@ -11,11 +11,11 @@ module.exports = function(grunt) {
|
|||||||
|
|
||||||
// node api
|
// node api
|
||||||
var fs = require('fs'),
|
var fs = require('fs'),
|
||||||
path = require('path');
|
path = require('path'),
|
||||||
|
chalk = require('chalk');
|
||||||
|
|
||||||
// npm lib
|
// npm lib
|
||||||
var phantomjs = require('grunt-lib-phantomjs').init(grunt);
|
var phantomjs = require('grunt-lib-phantomjs').init(grunt);
|
||||||
var chalk = require('chalk');
|
|
||||||
|
|
||||||
// local lib
|
// local lib
|
||||||
var jasmine = require('./lib/jasmine').init(grunt, phantomjs);
|
var jasmine = require('./lib/jasmine').init(grunt, phantomjs);
|
||||||
@ -24,6 +24,17 @@ module.exports = function(grunt) {
|
|||||||
|
|
||||||
var status = {};
|
var status = {};
|
||||||
|
|
||||||
|
|
||||||
|
var checkmark = '✓';
|
||||||
|
var errormark = '✖';
|
||||||
|
|
||||||
|
//With node.js on Windows: use symbols available in terminal default fonts
|
||||||
|
//https://github.com/visionmedia/mocha/pull/641
|
||||||
|
if (process && process.platform === 'win32') {
|
||||||
|
checkmark = '\u221A';
|
||||||
|
errormark = '\u00D7';
|
||||||
|
}
|
||||||
|
|
||||||
grunt.registerMultiTask('jasmine', 'Run jasmine specs headlessly through PhantomJS.', function() {
|
grunt.registerMultiTask('jasmine', 'Run jasmine specs headlessly through PhantomJS.', function() {
|
||||||
|
|
||||||
// Merge task-specific options with these defaults.
|
// Merge task-specific options with these defaults.
|
||||||
@ -77,12 +88,6 @@ module.exports = function(grunt) {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
function logWrite(text, isInline) {
|
|
||||||
text += (isInline ? '' : '\n');
|
|
||||||
status.log += text;
|
|
||||||
grunt.verbose.write(text);
|
|
||||||
}
|
|
||||||
|
|
||||||
function phantomRunner(options,cb){
|
function phantomRunner(options,cb){
|
||||||
var file = options.outfile;
|
var file = options.outfile;
|
||||||
|
|
||||||
@ -92,6 +97,7 @@ module.exports = function(grunt) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
grunt.verbose.subhead('Testing jasmine specs via phantom').or.writeln('Testing jasmine specs via phantom');
|
grunt.verbose.subhead('Testing jasmine specs via phantom').or.writeln('Testing jasmine specs via phantom');
|
||||||
|
grunt.log.writeln('');
|
||||||
|
|
||||||
phantomjs.spawn(file, {
|
phantomjs.spawn(file, {
|
||||||
failCode : 90,
|
failCode : 90,
|
||||||
@ -167,39 +173,56 @@ module.exports = function(grunt) {
|
|||||||
thisRun.passed_specs = 0;
|
thisRun.passed_specs = 0;
|
||||||
});
|
});
|
||||||
|
|
||||||
phantomjs.on('jasmine.reportSpecStarting',function(spec) {
|
var indent = function(times) {
|
||||||
|
var val = '';
|
||||||
|
for (var i = 0; i < times; i++) {
|
||||||
|
val += ' ';
|
||||||
|
}
|
||||||
|
return val;
|
||||||
|
};
|
||||||
|
|
||||||
|
var currentSuiteList = [];
|
||||||
|
|
||||||
|
phantomjs.on('jasmine.reportSpecStarting',function(description, suiteList) {
|
||||||
thisRun.executed_specs++;
|
thisRun.executed_specs++;
|
||||||
grunt.verbose.write(spec.suite.description + ':' + spec.description + '...');
|
|
||||||
|
var suiteListDifferent = false;
|
||||||
|
for (var i = 0; i < suiteList.length; i++) {
|
||||||
|
if (suiteListDifferent || currentSuiteList[i] !== suiteList[i]) {
|
||||||
|
suiteListDifferent = true;
|
||||||
|
grunt.log.writeln(indent(i + 1) + chalk.bold(suiteList[i]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
currentSuiteList = suiteList;
|
||||||
|
|
||||||
|
grunt.log.write(indent(currentSuiteList.length + 1) + '- ' + chalk.grey(description));
|
||||||
});
|
});
|
||||||
|
|
||||||
phantomjs.on('jasmine.reportSuiteResults',function(suite){
|
phantomjs.on('jasmine.reportSpecResults',function(specId, result, suiteList) {
|
||||||
//grunt.verbose.writeln(suite.description + ": " + suite.results.passedCount + " of " + suite.results.totalCount + " passed.");
|
|
||||||
});
|
|
||||||
|
|
||||||
phantomjs.on('jasmine.reportSpecResults',function(specId, result, fullName) {
|
|
||||||
if (result.passed) thisRun.passed_specs++;
|
if (result.passed) thisRun.passed_specs++;
|
||||||
|
|
||||||
if (!result.passed) {
|
process.stdout.clearLine();
|
||||||
if (grunt.option('verbose'))
|
process.stdout.cursorTo(0);
|
||||||
grunt.verbose.writeln(result.description + ': ' + chalk.red(result.msg));
|
|
||||||
else {
|
grunt.log.write(indent(currentSuiteList.length + 1));
|
||||||
logWrite(fullName + ': ' + chalk.red(result.msg));
|
|
||||||
grunt.log.write(chalk.red('x'));
|
if (result.passed) {
|
||||||
}
|
grunt.log.write(chalk.green.bold(checkmark));
|
||||||
} else {
|
} else {
|
||||||
grunt.verbose.writeln(result.description + ': ' + chalk.green(result.msg));
|
grunt.log.write(chalk.red('X'));
|
||||||
if (!grunt.option('verbose'))
|
|
||||||
grunt.log.write('.');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
grunt.log.writeln(' ' + chalk.grey(result.description));
|
||||||
|
|
||||||
for (var i = 0; i < result.messages.length; i++) {
|
for (var i = 0; i < result.messages.length; i++) {
|
||||||
var item = result.messages[i];
|
var item = result.messages[i];
|
||||||
|
|
||||||
if (item.type === 'log') {
|
if (item.type === 'log') {
|
||||||
grunt.verbose.writeln(item.toString());
|
grunt.log.writeln(indent(currentSuiteList.length + 3) + item.toString());
|
||||||
} else if (item.type === 'expect' && !item.passed_) {
|
} else if (item.type === 'expect' && !item.passed_) {
|
||||||
var specIndex = ' ('+(i+1)+')';
|
var specIndex = ' (' + (i + 1) + ')';
|
||||||
logWrite(' ' + chalk.red(item.message + specIndex));
|
grunt.log.writeln(indent(currentSuiteList.length + 3) + chalk.red(item.message + specIndex));
|
||||||
phantomjs.emit('onError', item.message, item.trace);
|
phantomjs.emit('onError', item.message, item.trace);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,13 +43,7 @@ phantom.sendMessage = function() {
|
|||||||
|
|
||||||
PhantomReporter.prototype.reportSpecStarting = function(spec) {
|
PhantomReporter.prototype.reportSpecStarting = function(spec) {
|
||||||
spec.startTime = (new Date()).getTime();
|
spec.startTime = (new Date()).getTime();
|
||||||
var message = {
|
phantom.sendMessage('jasmine.reportSpecStarting', spec.description, this.getSuiteNames(spec));
|
||||||
suite : {
|
|
||||||
description : spec.suite.description
|
|
||||||
},
|
|
||||||
description : spec.description
|
|
||||||
};
|
|
||||||
phantom.sendMessage('jasmine.reportSpecStarting', message);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
PhantomReporter.prototype.suites = function() {
|
PhantomReporter.prototype.suites = function() {
|
||||||
@ -173,11 +167,17 @@ phantom.sendMessage = function() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
phantom.sendMessage( 'jasmine.reportSpecResults', spec.id, results, this.getFullName(spec));
|
phantom.sendMessage( 'jasmine.reportSpecResults', spec.id, results, this.getSuiteNames(spec));
|
||||||
};
|
};
|
||||||
|
|
||||||
PhantomReporter.prototype.getFullName = function(spec) {
|
PhantomReporter.prototype.getSuiteNames = function(spec) {
|
||||||
return getNestedSuiteName(spec.suite, ':: ') + ':: ' + spec.description;
|
var suiteNames = [];
|
||||||
|
var suite = spec.suite;
|
||||||
|
while (suite) {
|
||||||
|
suiteNames.unshift(suite.description);
|
||||||
|
suite = suite.parentSuite;
|
||||||
|
}
|
||||||
|
return suiteNames;
|
||||||
};
|
};
|
||||||
|
|
||||||
PhantomReporter.prototype.resultsForSpecs = function(specIds){
|
PhantomReporter.prototype.resultsForSpecs = function(specIds){
|
||||||
|
Loading…
Reference in New Issue
Block a user