Assorted lint fixes.
This commit is contained in:
parent
d127b402d8
commit
f5ac86edf2
@ -8,7 +8,6 @@
|
|||||||
"newcap": true,
|
"newcap": true,
|
||||||
"noarg": true,
|
"noarg": true,
|
||||||
"node": true,
|
"node": true,
|
||||||
"sub": true,
|
|
||||||
"undef": true,
|
"undef": true,
|
||||||
"unused": "vars"
|
"unused": "vars"
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,9 @@ module.exports = function(grunt) {
|
|||||||
jshint: {
|
jshint: {
|
||||||
all: [
|
all: [
|
||||||
'Gruntfile.js',
|
'Gruntfile.js',
|
||||||
'tasks/**/*.js'
|
'tasks/**/*.js',
|
||||||
|
'test/*.js',
|
||||||
|
'test/selfTest/*.js'
|
||||||
],
|
],
|
||||||
options: {
|
options: {
|
||||||
jshintrc: '.jshintrc'
|
jshintrc: '.jshintrc'
|
||||||
|
174
tasks/jasmine.js
174
tasks/jasmine.js
@ -22,25 +22,25 @@ module.exports = function(grunt) {
|
|||||||
// local lib
|
// local lib
|
||||||
var jasmine = require('./lib/jasmine').init(grunt, phantomjs);
|
var jasmine = require('./lib/jasmine').init(grunt, phantomjs);
|
||||||
|
|
||||||
var junitTemplate = __dirname + '/jasmine/templates/JUnit.tmpl';
|
var junitTemplate = path.join(__dirname, '/jasmine/templates/JUnit.tmpl');
|
||||||
|
|
||||||
var status = {};
|
var status = {};
|
||||||
|
|
||||||
var symbols = {
|
var symbols = {
|
||||||
none : {
|
none: {
|
||||||
check : '',
|
check: '',
|
||||||
error : '',
|
error: '',
|
||||||
splat : ''
|
splat: ''
|
||||||
},
|
},
|
||||||
short : {
|
short: {
|
||||||
check : '.',
|
check: '.',
|
||||||
error : 'X',
|
error: 'X',
|
||||||
splat : '*'
|
splat: '*'
|
||||||
},
|
},
|
||||||
full : {
|
full: {
|
||||||
check : '✓',
|
check: '✓',
|
||||||
error : 'X',
|
error: 'X',
|
||||||
splat : '*'
|
splat: '*'
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -48,20 +48,20 @@ module.exports = function(grunt) {
|
|||||||
//https://github.com/visionmedia/mocha/pull/641
|
//https://github.com/visionmedia/mocha/pull/641
|
||||||
if (process && process.platform === 'win32') {
|
if (process && process.platform === 'win32') {
|
||||||
symbols = {
|
symbols = {
|
||||||
none : {
|
none: {
|
||||||
check : '',
|
check: '',
|
||||||
error : '',
|
error: '',
|
||||||
splat : ''
|
splat: ''
|
||||||
},
|
},
|
||||||
short : {
|
short: {
|
||||||
check : '.',
|
check: '.',
|
||||||
error : '\u00D7',
|
error: '\u00D7',
|
||||||
splat : '*'
|
splat: '*'
|
||||||
},
|
},
|
||||||
full : {
|
full: {
|
||||||
check : '\u221A',
|
check: '\u221A',
|
||||||
error : '\u00D7',
|
error: '\u00D7',
|
||||||
splat : '*'
|
splat: '*'
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -70,21 +70,21 @@ module.exports = function(grunt) {
|
|||||||
|
|
||||||
// Merge task-specific options with these defaults.
|
// Merge task-specific options with these defaults.
|
||||||
var options = this.options({
|
var options = this.options({
|
||||||
version : '2.0.1',
|
version: '2.0.1',
|
||||||
timeout : 10000,
|
timeout: 10000,
|
||||||
styles : [],
|
styles: [],
|
||||||
specs : [],
|
specs: [],
|
||||||
helpers : [],
|
helpers: [],
|
||||||
vendor : [],
|
vendor: [],
|
||||||
polyfills : [],
|
polyfills: [],
|
||||||
outfile : '_SpecRunner.html',
|
outfile: '_SpecRunner.html',
|
||||||
host : '',
|
host: '',
|
||||||
template : __dirname + '/jasmine/templates/DefaultRunner.tmpl',
|
template: path.join(__dirname, '/jasmine/templates/DefaultRunner.tmpl'),
|
||||||
templateOptions : {},
|
templateOptions: {},
|
||||||
junit : {},
|
junit: {},
|
||||||
ignoreEmpty: grunt.option('force') === true,
|
ignoreEmpty: grunt.option('force') === true,
|
||||||
display: 'full',
|
display: 'full',
|
||||||
summary: false,
|
summary: false
|
||||||
});
|
});
|
||||||
|
|
||||||
if (grunt.option('debug')) {
|
if (grunt.option('debug')) {
|
||||||
@ -124,12 +124,12 @@ module.exports = function(grunt) {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
function phantomRunner(options, cb){
|
function phantomRunner(options, cb) {
|
||||||
var file = options.outfile;
|
var file = options.outfile;
|
||||||
|
|
||||||
if (options.host) {
|
if (options.host) {
|
||||||
if (!(/\/$/).test(options.host)) {
|
if (!(/\/$/).test(options.host)) {
|
||||||
options.host = options.host + '/';
|
options.host += '/';
|
||||||
}
|
}
|
||||||
file = options.host + options.outfile;
|
file = options.host + options.outfile;
|
||||||
}
|
}
|
||||||
@ -138,10 +138,10 @@ module.exports = function(grunt) {
|
|||||||
grunt.log.writeln('');
|
grunt.log.writeln('');
|
||||||
|
|
||||||
phantomjs.spawn(file, {
|
phantomjs.spawn(file, {
|
||||||
failCode : 90,
|
failCode: 90,
|
||||||
options : options,
|
options: options,
|
||||||
done : function(err){
|
done: function(err) {
|
||||||
cb(err,status);
|
cb(err, status);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -173,7 +173,7 @@ module.exports = function(grunt) {
|
|||||||
currentSuite;
|
currentSuite;
|
||||||
|
|
||||||
status = {
|
status = {
|
||||||
failed : 0
|
failed: 0
|
||||||
};
|
};
|
||||||
|
|
||||||
function indent(times) {
|
function indent(times) {
|
||||||
@ -192,21 +192,21 @@ module.exports = function(grunt) {
|
|||||||
|
|
||||||
phantomjs.on('console', function(msg) {
|
phantomjs.on('console', function(msg) {
|
||||||
thisRun.cleanConsole = false;
|
thisRun.cleanConsole = false;
|
||||||
if(options.display === 'full') {
|
if (options.display === 'full') {
|
||||||
grunt.log.writeln('\n' + chalk.yellow('log: ') + msg);
|
grunt.log.writeln('\n' + chalk.yellow('log: ') + msg);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
phantomjs.on('error.onError', function(string, trace){
|
phantomjs.on('error.onError', function(string, trace) {
|
||||||
if (trace && trace.length) {
|
if (trace && trace.length) {
|
||||||
grunt.log.error(chalk.red(string) + ' at ');
|
grunt.log.error(chalk.red(string) + ' at ');
|
||||||
trace.forEach(function(line) {
|
trace.forEach(function(line) {
|
||||||
var file = line.file.replace(/^file:/,'');
|
var file = line.file.replace(/^file:/, '');
|
||||||
var message = grunt.util._('%s:%d %s').sprintf(path.relative('.',file), line.line, line.function);
|
var message = grunt.util._('%s:%d %s').sprintf(path.relative('.', file), line.line, line.function);
|
||||||
grunt.log.error(chalk.red(message));
|
grunt.log.error(chalk.red(message));
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
grunt.log.error("Error caught from PhantomJS. More info can be found by opening the Spec Runner in a browser.");
|
grunt.log.error('Error caught from PhantomJS. More info can be found by opening the Spec Runner in a browser.');
|
||||||
grunt.warn(string);
|
grunt.warn(string);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -229,14 +229,14 @@ module.exports = function(grunt) {
|
|||||||
phantomjs.on('jasmine.suiteStarted', function(suiteMetaData) {
|
phantomjs.on('jasmine.suiteStarted', function(suiteMetaData) {
|
||||||
currentSuite = suiteMetaData.id;
|
currentSuite = suiteMetaData.id;
|
||||||
suites[currentSuite] = {
|
suites[currentSuite] = {
|
||||||
name : suiteMetaData.fullName,
|
name: suiteMetaData.fullName,
|
||||||
timestamp : new Date(suiteMetaData.startTime),
|
timestamp: new Date(suiteMetaData.startTime),
|
||||||
errors : 0,
|
errors: 0,
|
||||||
tests : 0,
|
tests: 0,
|
||||||
failures : 0,
|
failures: 0,
|
||||||
testcases : []
|
testcases: []
|
||||||
};
|
};
|
||||||
if(options.display === 'full') {
|
if (options.display === 'full') {
|
||||||
grunt.log.write(indent(indentLevel++));
|
grunt.log.write(indent(indentLevel++));
|
||||||
grunt.log.writeln(chalk.bold(suiteMetaData.description));
|
grunt.log.writeln(chalk.bold(suiteMetaData.description));
|
||||||
}
|
}
|
||||||
@ -245,7 +245,7 @@ module.exports = function(grunt) {
|
|||||||
phantomjs.on('jasmine.suiteDone', function(suiteMetaData) {
|
phantomjs.on('jasmine.suiteDone', function(suiteMetaData) {
|
||||||
suites[suiteMetaData.id].time = suiteMetaData.duration / 1000;
|
suites[suiteMetaData.id].time = suiteMetaData.duration / 1000;
|
||||||
|
|
||||||
if(indentLevel > 1) {
|
if (indentLevel > 1) {
|
||||||
indentLevel--;
|
indentLevel--;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -253,44 +253,44 @@ module.exports = function(grunt) {
|
|||||||
phantomjs.on('jasmine.specStarted', function(specMetaData) {
|
phantomjs.on('jasmine.specStarted', function(specMetaData) {
|
||||||
thisRun.executedSpecs++;
|
thisRun.executedSpecs++;
|
||||||
thisRun.cleanConsole = true;
|
thisRun.cleanConsole = true;
|
||||||
if(options.display === 'full') {
|
if (options.display === 'full') {
|
||||||
grunt.log.write(indent(indentLevel) + '- ' + chalk.grey(specMetaData.description) + '...');
|
grunt.log.write(indent(indentLevel) + '- ' + chalk.grey(specMetaData.description) + '...');
|
||||||
} else if(options.display === 'short' ) {
|
} else if (options.display === 'short') {
|
||||||
grunt.log.write(chalk.grey('.'));
|
grunt.log.write(chalk.grey('.'));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
phantomjs.on('jasmine.specDone', function(specMetaData) {
|
phantomjs.on('jasmine.specDone', function(specMetaData) {
|
||||||
var specSummary = {
|
var specSummary = {
|
||||||
assertions : 0,
|
assertions: 0,
|
||||||
classname : suites[currentSuite].name,
|
classname: suites[currentSuite].name,
|
||||||
name : specMetaData.description,
|
name: specMetaData.description,
|
||||||
time : specMetaData.duration / 1000,
|
time: specMetaData.duration / 1000,
|
||||||
failureMessages : []
|
failureMessages: []
|
||||||
};
|
};
|
||||||
|
|
||||||
suites[currentSuite].tests++;
|
suites[currentSuite].tests++;
|
||||||
|
|
||||||
var color = 'yellow',
|
var color = 'yellow',
|
||||||
symbol = 'splat';
|
symbol = 'splat';
|
||||||
if (specMetaData.status === "passed") {
|
if (specMetaData.status === 'passed') {
|
||||||
thisRun.passedSpecs++;
|
thisRun.passedSpecs++;
|
||||||
color = 'green';
|
color = 'green';
|
||||||
symbol = 'check';
|
symbol = 'check';
|
||||||
} else if (specMetaData.status === "failed") {
|
} else if (specMetaData.status === 'failed') {
|
||||||
thisRun.failedSpecs++;
|
thisRun.failedSpecs++;
|
||||||
status.failed++;
|
status.failed++;
|
||||||
color = 'red';
|
color = 'red';
|
||||||
symbol = 'error';
|
symbol = 'error';
|
||||||
suites[currentSuite].failures++;
|
suites[currentSuite].failures++;
|
||||||
suites[currentSuite].errors += specMetaData.failedExpectations.length;
|
suites[currentSuite].errors += specMetaData.failedExpectations.length;
|
||||||
specSummary.failureMessages = specMetaData.failedExpectations.map(function(error){
|
specSummary.failureMessages = specMetaData.failedExpectations.map(function(error) {
|
||||||
return error.message;
|
return error.message;
|
||||||
});
|
});
|
||||||
thisRun.summary.push({
|
thisRun.summary.push({
|
||||||
suite: suites[currentSuite].name,
|
suite: suites[currentSuite].name,
|
||||||
name: specMetaData.description,
|
name: specMetaData.description,
|
||||||
errors: specMetaData.failedExpectations.map(function(error){
|
errors: specMetaData.failedExpectations.map(function(error) {
|
||||||
return {
|
return {
|
||||||
message: error.message,
|
message: error.message,
|
||||||
stack: error.stack
|
stack: error.stack
|
||||||
@ -305,7 +305,7 @@ module.exports = function(grunt) {
|
|||||||
|
|
||||||
// If we're writing to a proper terminal, make it fancy.
|
// If we're writing to a proper terminal, make it fancy.
|
||||||
if (process.stdout.clearLine) {
|
if (process.stdout.clearLine) {
|
||||||
if(options.display === 'full') {
|
if (options.display === 'full') {
|
||||||
process.stdout.clearLine();
|
process.stdout.clearLine();
|
||||||
process.stdout.cursorTo(0);
|
process.stdout.cursorTo(0);
|
||||||
grunt.log.writeln(
|
grunt.log.writeln(
|
||||||
@ -313,7 +313,7 @@ module.exports = function(grunt) {
|
|||||||
chalk[color].bold(symbols.full[symbol]) + ' ' +
|
chalk[color].bold(symbols.full[symbol]) + ' ' +
|
||||||
chalk.grey(specMetaData.description)
|
chalk.grey(specMetaData.description)
|
||||||
);
|
);
|
||||||
} else if(options.display === 'short') {
|
} else if (options.display === 'short') {
|
||||||
process.stdout.moveCursor(-1);
|
process.stdout.moveCursor(-1);
|
||||||
grunt.log.write(chalk[color].bold(symbols.short[symbol]));
|
grunt.log.write(chalk[color].bold(symbols.short[symbol]));
|
||||||
}
|
}
|
||||||
@ -336,9 +336,9 @@ module.exports = function(grunt) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
specMetaData.failedExpectations.forEach(function(error, i){
|
specMetaData.failedExpectations.forEach(function(error, i) {
|
||||||
var specIndex = ' ('+(i+1)+')';
|
var specIndex = ' (' + (i + 1) + ')';
|
||||||
if(options.display === 'full') {
|
if (options.display === 'full') {
|
||||||
grunt.log.writeln(indent(indentLevel + 1) + chalk.red(error.message + specIndex));
|
grunt.log.writeln(indent(indentLevel + 1) + chalk.red(error.message + specIndex));
|
||||||
}
|
}
|
||||||
phantomjs.emit('onError', error.message, error.stack);
|
phantomjs.emit('onError', error.message, error.stack);
|
||||||
@ -346,24 +346,24 @@ module.exports = function(grunt) {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
phantomjs.on('jasmine.jasmineDone', function(){
|
phantomjs.on('jasmine.jasmineDone', function() {
|
||||||
var dur = (new Date()).getTime() - thisRun.startTime;
|
var dur = (new Date()).getTime() - thisRun.startTime;
|
||||||
var specQuantity = thisRun.executedSpecs + (thisRun.executedSpecs === 1 ? " spec " : " specs ");
|
var specQuantity = thisRun.executedSpecs + (thisRun.executedSpecs === 1 ? ' spec ' : ' specs ');
|
||||||
|
|
||||||
grunt.verbose.writeln('Jasmine runner finished');
|
grunt.verbose.writeln('Jasmine runner finished');
|
||||||
|
|
||||||
if (thisRun.executedSpecs === 0) {
|
if (thisRun.executedSpecs === 0) {
|
||||||
// log.error will print the message but not fail the task, warn will do both.
|
// log.error will print the message but not fail the task, warn will do both.
|
||||||
var log = (options.ignoreEmpty) ? grunt.log.error : grunt.warn;
|
var log = options.ignoreEmpty ? grunt.log.error : grunt.warn;
|
||||||
|
|
||||||
log('No specs executed, is there a configuration error?');
|
log('No specs executed, is there a configuration error?');
|
||||||
}
|
}
|
||||||
|
|
||||||
if(options.display === 'short') {
|
if (options.display === 'short') {
|
||||||
grunt.log.writeln();
|
grunt.log.writeln();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(options.summary && thisRun.summary.length) {
|
if (options.summary && thisRun.summary.length) {
|
||||||
grunt.log.writeln();
|
grunt.log.writeln();
|
||||||
logSummary(thisRun.summary);
|
logSummary(thisRun.summary);
|
||||||
}
|
}
|
||||||
@ -372,14 +372,14 @@ module.exports = function(grunt) {
|
|||||||
writeJunitXml(suites);
|
writeJunitXml(suites);
|
||||||
}
|
}
|
||||||
|
|
||||||
grunt.log.writeln('\n' + specQuantity + 'in ' + (dur / 1000) + "s.");
|
grunt.log.writeln('\n' + specQuantity + 'in ' + (dur / 1000) + 's.');
|
||||||
});
|
});
|
||||||
|
|
||||||
function logSummary(tests) {
|
function logSummary(tests) {
|
||||||
grunt.log.writeln('Summary (' + tests.length + ' tests failed)');
|
grunt.log.writeln('Summary (' + tests.length + ' tests failed)');
|
||||||
_.forEach(tests, function(test){
|
_.forEach(tests, function(test) {
|
||||||
grunt.log.writeln(chalk.red(symbols[options.display]['error']) + ' ' + test.suite + ' ' + test.name);
|
grunt.log.writeln(chalk.red(symbols.options.display.error) + ' ' + test.suite + ' ' + test.name);
|
||||||
_.forEach(test.errors, function(error){
|
_.forEach(test.errors, function(error) {
|
||||||
grunt.log.writeln(indent(2) + chalk.red(error.message));
|
grunt.log.writeln(indent(2) + chalk.red(error.message));
|
||||||
logStack(error.stack, 2);
|
logStack(error.stack, 2);
|
||||||
});
|
});
|
||||||
@ -389,24 +389,24 @@ module.exports = function(grunt) {
|
|||||||
function logStack(stack, indentLevel) {
|
function logStack(stack, indentLevel) {
|
||||||
var lines = (stack || '').split('\n');
|
var lines = (stack || '').split('\n');
|
||||||
for (var i = 0; i < lines.length && i < 11; i++) {
|
for (var i = 0; i < lines.length && i < 11; i++) {
|
||||||
grunt.log.writeln((indent(indentLevel) + lines[i]));
|
grunt.log.writeln(indent(indentLevel) + lines[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function writeJunitXml(testsuites){
|
function writeJunitXml(testsuites) {
|
||||||
var template = grunt.file.read(options.junit.template || junitTemplate);
|
var template = grunt.file.read(options.junit.template || junitTemplate);
|
||||||
if (options.junit.consolidate) {
|
if (options.junit.consolidate) {
|
||||||
var xmlFile = path.join(options.junit.path, 'TEST-' + testsuites.suite1.name.replace(/[^\w]/g, '') + '.xml');
|
var xmlFile = path.join(options.junit.path, 'TEST-' + testsuites.suite1.name.replace(/[^\w]/g, '') + '.xml');
|
||||||
grunt.file.write(xmlFile, grunt.util._.template(template, { testsuites: _.values(testsuites)}));
|
grunt.file.write(xmlFile, grunt.util._.template(template, { testsuites: _.values(testsuites)}));
|
||||||
} else {
|
} else {
|
||||||
_.forEach(testsuites, function(suiteData){
|
_.forEach(testsuites, function(suiteData) {
|
||||||
var xmlFile = path.join(options.junit.path, 'TEST-' + suiteData.name.replace(/[^\w]/g, '') + '.xml');
|
var xmlFile = path.join(options.junit.path, 'TEST-' + suiteData.name.replace(/[^\w]/g, '') + '.xml');
|
||||||
grunt.file.write(xmlFile, _.template(template, { testsuites: [suiteData] }));
|
grunt.file.write(xmlFile, _.template(template, { testsuites: [suiteData] }));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
phantomjs.on('jasmine.done', function(elapsed) {
|
phantomjs.on('jasmine.done', function() {
|
||||||
phantomjs.halt();
|
phantomjs.halt();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1,24 +1,23 @@
|
|||||||
/*global window:false, alert:false, jasmine:false, Node:false */
|
/* global window:true, alert:true, jasmine:true, Node:true */
|
||||||
/*jshint curly:false*/
|
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var phantom = {};
|
var phantom = {};
|
||||||
|
|
||||||
if (window._phantom) {
|
if (window._phantom) {
|
||||||
console.log = function(){
|
console.log = function() {
|
||||||
phantom.sendMessage('console', Array.prototype.slice.apply(arguments).join(', '));
|
phantom.sendMessage('console', Array.prototype.slice.apply(arguments).join(', '));
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
(function(){
|
(function() {
|
||||||
phantom.sendMessage = function() {
|
phantom.sendMessage = function() {
|
||||||
var args = [].slice.call( arguments );
|
var args = [].slice.call(arguments);
|
||||||
var payload = stringify( args );
|
var payload = stringify(args);
|
||||||
if (window._phantom) {
|
if (window._phantom) {
|
||||||
// alerts are the communication bridge to grunt
|
// alerts are the communication bridge to grunt
|
||||||
alert( payload );
|
alert(payload);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -71,36 +70,50 @@ if (window._phantom) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
phantom.sendMessage( 'jasmine.specDone', specMetadata);
|
phantom.sendMessage('jasmine.specDone', specMetadata);
|
||||||
};
|
};
|
||||||
|
|
||||||
function stringify(obj) {
|
function stringify(obj) {
|
||||||
if (typeof obj !== 'object') return obj;
|
if (typeof obj !== 'object') {
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
var cache = [], keyMap = [], index;
|
var cache = [], keyMap = [];
|
||||||
|
|
||||||
var string = JSON.stringify(obj, function(key, value) {
|
var string = JSON.stringify(obj, function(key, value) {
|
||||||
// Let json stringify falsy values
|
// Let json stringify falsy values
|
||||||
if (!value) return value;
|
if (!value) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// If we're a node
|
// If we're a node
|
||||||
if (typeof(Node) !== 'undefined' && value instanceof Node) return '[ Node ]';
|
if (typeof Node !== 'undefined' && value instanceof Node) {
|
||||||
|
return '[ Node ]';
|
||||||
|
}
|
||||||
|
|
||||||
// jasmine-given has expectations on Specs. We intercept to return a
|
// jasmine-given has expectations on Specs. We intercept to return a
|
||||||
// String to avoid stringifying the entire Jasmine environment, which
|
// String to avoid stringifying the entire Jasmine environment, which
|
||||||
// results in exponential string growth
|
// results in exponential string growth
|
||||||
if (value instanceof jasmine.Spec) return '[ Spec: ' + value.description + ' ]';
|
if (value instanceof jasmine.Spec) {
|
||||||
|
return '[ Spec: ' + value.description + ' ]';
|
||||||
|
}
|
||||||
|
|
||||||
// If we're a window (logic stolen from jQuery)
|
// If we're a window (logic stolen from jQuery)
|
||||||
if (value.window && value.window === value.window.window) return '[ Window ]';
|
if (value.window && value.window === value.window.window) {
|
||||||
|
return '[ Window ]';
|
||||||
|
}
|
||||||
|
|
||||||
// Simple function reporting
|
// Simple function reporting
|
||||||
if (typeof value === 'function') return '[ Function ]';
|
if (typeof value === 'function') {
|
||||||
|
return '[ Function ]';
|
||||||
|
}
|
||||||
|
|
||||||
if (typeof value === 'object' && value !== null) {
|
if (typeof value === 'object' && value !== null) {
|
||||||
|
|
||||||
if (index = cache.indexOf(value) !== -1) {
|
var index = cache.indexOf(value);
|
||||||
|
|
||||||
|
if (index !== -1) {
|
||||||
// If we have it in cache, report the circle with the key we first found it in
|
// If we have it in cache, report the circle with the key we first found it in
|
||||||
return '[ Circular {' + (keyMap[index] || 'root') + '} ]';
|
return '[ Circular {' + (keyMap[index] || 'root') + '} ]';
|
||||||
}
|
}
|
||||||
@ -108,12 +121,12 @@ if (window._phantom) {
|
|||||||
keyMap.push(key);
|
keyMap.push(key);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return "[Object]";
|
return '[Object]';
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
});
|
});
|
||||||
return string;
|
return string;
|
||||||
}
|
}
|
||||||
|
|
||||||
jasmine.getEnv().addReporter( new PhantomReporter() );
|
jasmine.getEnv().addReporter(new PhantomReporter());
|
||||||
}());
|
}());
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
exports.init = function(grunt, phantomjs) {
|
exports.init = function(grunt, phantomjs) {
|
||||||
@ -17,28 +16,28 @@ exports.init = function(grunt, phantomjs) {
|
|||||||
var exports = {};
|
var exports = {};
|
||||||
|
|
||||||
exports.writeTempFile = function(dest, contents) {
|
exports.writeTempFile = function(dest, contents) {
|
||||||
var file = path.join(tempDir,dest);
|
var file = path.join(tempDir, dest);
|
||||||
grunt.file.write(file, contents);
|
grunt.file.write(file, contents);
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.copyTempFile = function(src, dest) {
|
exports.copyTempFile = function(src, dest) {
|
||||||
var file = path.join(tempDir,dest);
|
var file = path.join(tempDir, dest);
|
||||||
grunt.file.copy(src, file);
|
grunt.file.copy(src, file);
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.cleanTemp = function(cb) {
|
exports.cleanTemp = function(cb) {
|
||||||
rimraf(tempDir, function(){
|
rimraf(tempDir, function() {
|
||||||
// if this fails, then ./.grunt isn't empty and that's ok.
|
// if this fails, then ./.grunt isn't empty and that's ok.
|
||||||
fs.rmdir('.grunt', cb);
|
fs.rmdir('.grunt', cb);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.buildSpecrunner = function (src, options){
|
exports.buildSpecrunner = function(src, options) {
|
||||||
var source = '',
|
var source = '',
|
||||||
outfile = options.outfile,
|
outfile = options.outfile,
|
||||||
specrunner = path.join(baseDir,outfile),
|
specrunner = path.join(baseDir, outfile),
|
||||||
outdir = path.dirname(outfile),
|
outdir = path.dirname(outfile),
|
||||||
gruntfilter = grunt.option("filter"),
|
gruntfilter = grunt.option('filter'),
|
||||||
filteredSpecs = exports.getRelativeFileList(outdir, options.specs);
|
filteredSpecs = exports.getRelativeFileList(outdir, options.specs);
|
||||||
|
|
||||||
// Let's filter through the spec files here,
|
// Let's filter through the spec files here,
|
||||||
@ -46,13 +45,13 @@ exports.init = function(grunt, phantomjs) {
|
|||||||
if (gruntfilter) {
|
if (gruntfilter) {
|
||||||
filteredSpecs = specFilter(gruntfilter, filteredSpecs);
|
filteredSpecs = specFilter(gruntfilter, filteredSpecs);
|
||||||
|
|
||||||
if(filteredSpecs.length === 0) {
|
if (filteredSpecs.length === 0) {
|
||||||
grunt.log.warn("the --filter flag did not match any spec within " + grunt.task.current.target);
|
grunt.log.warn('the --filter flag did not match any spec within ' + grunt.task.current.target);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.copyTempFile(__dirname + '/../jasmine/reporters/PhantomReporter.js', 'reporter.js');
|
exports.copyTempFile(path.join(__dirname, '/../jasmine/reporters/PhantomReporter.js'), 'reporter.js');
|
||||||
|
|
||||||
[].concat(jasmineRequire.files.cssFiles, jasmineRequire.files.jsFiles).forEach(function(name) {
|
[].concat(jasmineRequire.files.cssFiles, jasmineRequire.files.jsFiles).forEach(function(name) {
|
||||||
var srcPath = path.join(jasmineRequire.files.path, name);
|
var srcPath = path.join(jasmineRequire.files.path, name);
|
||||||
@ -66,7 +65,7 @@ exports.init = function(grunt, phantomjs) {
|
|||||||
|
|
||||||
exports.copyTempFile(path.join(jasmineRequire.files.imagesDir, 'jasmine_favicon.png'), 'jasmine_favicon.png');
|
exports.copyTempFile(path.join(jasmineRequire.files.imagesDir, 'jasmine_favicon.png'), 'jasmine_favicon.png');
|
||||||
|
|
||||||
exports.copyTempFile(__dirname + '/../../node_modules/es5-shim/es5-shim.js', 'es5-shim.js');
|
exports.copyTempFile(path.join(__dirname, '/../../node_modules/es5-shim/es5-shim.js'), 'es5-shim.js');
|
||||||
|
|
||||||
var reporters = [
|
var reporters = [
|
||||||
tempDir + '/reporter.js'
|
tempDir + '/reporter.js'
|
||||||
@ -87,33 +86,33 @@ exports.init = function(grunt, phantomjs) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
var context = {
|
var context = {
|
||||||
temp : tempDir,
|
temp: tempDir,
|
||||||
outfile: outfile,
|
outfile: outfile,
|
||||||
css : exports.getRelativeFileList(outdir, jasmineCss, { nonull : true }),
|
css: exports.getRelativeFileList(outdir, jasmineCss, { nonull: true }),
|
||||||
scripts : {
|
scripts: {
|
||||||
polyfills : exports.getRelativeFileList(outdir, polyfills),
|
polyfills: exports.getRelativeFileList(outdir, polyfills),
|
||||||
jasmine : exports.getRelativeFileList(outdir, jasmineCore),
|
jasmine: exports.getRelativeFileList(outdir, jasmineCore),
|
||||||
helpers : exports.getRelativeFileList(outdir, options.helpers, { nonull : true }),
|
helpers: exports.getRelativeFileList(outdir, options.helpers, { nonull: true }),
|
||||||
specs : filteredSpecs,
|
specs: filteredSpecs,
|
||||||
src : exports.getRelativeFileList(outdir, src, { nonull : true }),
|
src: exports.getRelativeFileList(outdir, src, { nonull: true }),
|
||||||
vendor : exports.getRelativeFileList(outdir, options.vendor, { nonull : true }),
|
vendor: exports.getRelativeFileList(outdir, options.vendor, { nonull: true }),
|
||||||
reporters : exports.getRelativeFileList(outdir, reporters),
|
reporters: exports.getRelativeFileList(outdir, reporters),
|
||||||
boot : exports.getRelativeFileList(outdir, tempDir + '/boot.js')
|
boot: exports.getRelativeFileList(outdir, tempDir + '/boot.js')
|
||||||
},
|
},
|
||||||
options : options.templateOptions || {}
|
options: options.templateOptions || {}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (options.template.process) {
|
if (options.template.process) {
|
||||||
var task = {
|
var task = {
|
||||||
writeTempFile : exports.writeTempFile,
|
writeTempFile: exports.writeTempFile,
|
||||||
copyTempFile : exports.copyTempFile,
|
copyTempFile: exports.copyTempFile,
|
||||||
phantomjs : phantomjs
|
phantomjs: phantomjs
|
||||||
};
|
};
|
||||||
source = options.template.process(grunt, task, context);
|
source = options.template.process(grunt, task, context);
|
||||||
grunt.file.write(specrunner, source);
|
grunt.file.write(specrunner, source);
|
||||||
} else {
|
} else {
|
||||||
grunt.file.copy(options.template, specrunner, {
|
grunt.file.copy(options.template, specrunner, {
|
||||||
process : function(src) {
|
process: function(src) {
|
||||||
source = _.template(src, context);
|
source = _.template(src, context);
|
||||||
return source;
|
return source;
|
||||||
}
|
}
|
||||||
@ -128,7 +127,7 @@ exports.init = function(grunt, phantomjs) {
|
|||||||
options = options || {};
|
options = options || {};
|
||||||
|
|
||||||
var files = grunt.file.expand(options, grunt.util._(patterns).compact());
|
var files = grunt.file.expand(options, grunt.util._(patterns).compact());
|
||||||
files = grunt.util._(files).map(function(file){
|
files = grunt.util._(files).map(function(file) {
|
||||||
return (/^https?:/).test(file) ? file : path.relative(outdir, file).replace(/\\/g, '/');
|
return (/^https?:/).test(file) ? file : path.relative(outdir, file).replace(/\\/g, '/');
|
||||||
});
|
});
|
||||||
return files;
|
return files;
|
||||||
@ -144,22 +143,22 @@ exports.init = function(grunt, phantomjs) {
|
|||||||
return !!path.match(specPattern);
|
return !!path.match(specPattern);
|
||||||
};
|
};
|
||||||
|
|
||||||
if(pattern) {
|
if (pattern) {
|
||||||
// For '*' to work as a wildcard.
|
// For '*' to work as a wildcard.
|
||||||
pattern = pattern.split("*").join("[\\S]*").replace(/\./g, "\\.");
|
pattern = pattern.split('*').join('[\\S]*').replace(/\./g, '\\.');
|
||||||
// This allows for comma separated strings to which we can match the spec files.
|
// This allows for comma separated strings to which we can match the spec files.
|
||||||
patternArray = pattern.split(",");
|
patternArray = pattern.split(',');
|
||||||
|
|
||||||
while(patternArray.length > 0) {
|
while (patternArray.length > 0) {
|
||||||
pattern = (patternArray.splice(0, 1)[0]);
|
pattern = patternArray.splice(0, 1)[0];
|
||||||
|
|
||||||
if(pattern.length > 0) {
|
if (pattern.length > 0) {
|
||||||
if(pattern.indexOf('/') === -1) {
|
if (pattern.indexOf('/') === -1) {
|
||||||
specPattern = new RegExp("("+pattern+"[^/]*)(?!/)$", "ig");
|
specPattern = new RegExp('(' + pattern + '[^/]*)(?!/)$', 'ig');
|
||||||
} else if(pattern.indexOf('/') === 0) {
|
} else if (pattern.indexOf('/') === 0) {
|
||||||
specPattern = new RegExp("("+pattern+"[^/]*)(?=/)", "ig");
|
specPattern = new RegExp('(' + pattern + '[^/]*)(?=/)', 'ig');
|
||||||
} else {
|
} else {
|
||||||
throw new TypeError("--filter flag seems to be in the wrong format.");
|
throw new TypeError('--filter flag seems to be in the wrong format.');
|
||||||
}
|
}
|
||||||
|
|
||||||
// push is usually faster than concat.
|
// push is usually faster than concat.
|
||||||
|
@ -6,7 +6,7 @@ var grunt = require('grunt'),
|
|||||||
|
|
||||||
// Majority of test benefit comes from running the task itself.
|
// Majority of test benefit comes from running the task itself.
|
||||||
|
|
||||||
function runTemplate(src,context) {
|
function runTemplate(src, context) {
|
||||||
var source = grunt.file.read(src);
|
var source = grunt.file.read(src);
|
||||||
return grunt.util._.template(source, context);
|
return grunt.util._.template(source, context);
|
||||||
}
|
}
|
||||||
@ -14,7 +14,7 @@ function runTemplate(src,context) {
|
|||||||
// Just strips whitespace for now. Should do a proper min of everything
|
// Just strips whitespace for now. Should do a proper min of everything
|
||||||
// but this is working well enough for now.
|
// but this is working well enough for now.
|
||||||
function normalize(html) {
|
function normalize(html) {
|
||||||
return html.replace(/\s*/g,'');
|
return html.replace(/\s*/g, '');
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.jasmine = {
|
exports.jasmine = {
|
||||||
@ -22,33 +22,33 @@ exports.jasmine = {
|
|||||||
test.expect(1);
|
test.expect(1);
|
||||||
|
|
||||||
var context = {
|
var context = {
|
||||||
css : ['css/a.css'],
|
css: ['css/a.css'],
|
||||||
scripts : {
|
scripts: {
|
||||||
polyfills : ['p1.js'],
|
polyfills: ['p1.js'],
|
||||||
jasmine : ['J1.js','J2.js'],
|
jasmine: ['J1.js', 'J2.js'],
|
||||||
helpers : ['H1.js','H2.js'],
|
helpers: ['H1.js', 'H2.js'],
|
||||||
specs : ['SPEC1.js','SPEC2.js'],
|
specs: ['SPEC1.js', 'SPEC2.js'],
|
||||||
src : ['SRC1.js','SRC2.js'],
|
src: ['SRC1.js', 'SRC2.js'],
|
||||||
vendor : ['V1.js','V2.js'],
|
vendor: ['V1.js', 'V2.js'],
|
||||||
reporters : ['R1.js'],
|
reporters: ['R1.js'],
|
||||||
boot : ['BOOT.js']
|
boot: ['BOOT.js']
|
||||||
},
|
},
|
||||||
temp: 'path/to/temp/folder',
|
temp: 'path/to/temp/folder',
|
||||||
options : {}
|
options: {}
|
||||||
};
|
};
|
||||||
|
|
||||||
var actual = runTemplate('./tasks/jasmine/templates/DefaultRunner.tmpl', context);
|
var actual = runTemplate('./tasks/jasmine/templates/DefaultRunner.tmpl', context);
|
||||||
var expected = grunt.file.read('./test/expected/defaultTemplate.html');
|
var expected = grunt.file.read('./test/expected/defaultTemplate.html');
|
||||||
|
|
||||||
test.equal(normalize(actual),normalize(expected), 'default test runner template');
|
test.equal(normalize(actual), normalize(expected), 'default test runner template');
|
||||||
|
|
||||||
test.done();
|
test.done();
|
||||||
},
|
},
|
||||||
|
|
||||||
fileExpand: function(test) {
|
fileExpand: function(test) {
|
||||||
var patterns = ['test/fixtures/fileExpand/src/*.js', '!test/fixtures/fileExpand/src/exclude.js']
|
var patterns = ['test/fixtures/fileExpand/src/*.js', '!test/fixtures/fileExpand/src/exclude.js'];
|
||||||
var expected = ['test/fixtures/fileExpand/src/include.js'];
|
var expected = ['test/fixtures/fileExpand/src/include.js'];
|
||||||
test.deepEqual(jasmine.getRelativeFileList('', patterns, {}), expected, 'should properly expand file list')
|
test.deepEqual(jasmine.getRelativeFileList('', patterns, {}), expected, 'should properly expand file list');
|
||||||
test.done();
|
test.done();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -1,28 +1,29 @@
|
|||||||
describe("Task", function() {
|
/* jshint strict:false, mocha:true */
|
||||||
|
/* globals document:true, iframe:true, expect:true */
|
||||||
|
|
||||||
/*
|
describe('Task', function() {
|
||||||
when running this test with `grunt jasmine:selfTest -d` you got this output
|
|
||||||
|
|
||||||
[D] ["phantomjs","onLoadFinished","success"]
|
/*
|
||||||
[D] ["phantomjs","onResourceRequested","http://httpbin.org/status/500"]
|
when running this test with `grunt jasmine:selfTest -d` you got this output
|
||||||
[D] ["phantomjs","onResourceReceived","http://httpbin.org/status/500"]
|
|
||||||
[D] ["phantomjs","onLoadFinished","fail"]
|
|
||||||
[D] ["phantomjs","fail.load","_SpecRunner.html"]
|
|
||||||
|
|
||||||
phantomjs.page.onLoadFinished seems to be called for iframes, too.
|
[D] ['phantomjs','onLoadFinished','success']
|
||||||
A failing onLoadFinished caused this grunt taks to hang.
|
[D] ['phantomjs','onResourceRequested','http://httpbin.org/status/500']
|
||||||
Now, after removing the event handler, this following test should work as expected
|
[D] ['phantomjs','onResourceReceived','http://httpbin.org/status/500']
|
||||||
*/
|
[D] ['phantomjs','onLoadFinished','fail']
|
||||||
it("can handle fail on iframe", function(done){
|
[D] ['phantomjs','fail.load','_SpecRunner.html']
|
||||||
var waitedLongEnough;
|
|
||||||
iframe = document.createElement("iframe");
|
phantomjs.page.onLoadFinished seems to be called for iframes, too.
|
||||||
iframe.src = "http://localhost:9000";
|
A failing onLoadFinished caused this grunt taks to hang.
|
||||||
|
Now, after removing the event handler, this following test should work as expected
|
||||||
|
*/
|
||||||
|
it('can handle fail on iframe', function(done) {
|
||||||
|
iframe = document.createElement('iframe');
|
||||||
|
iframe.src = 'http://localhost:9000';
|
||||||
document.body.appendChild(iframe);
|
document.body.appendChild(iframe);
|
||||||
|
|
||||||
setTimeout(function(){
|
setTimeout(function() {
|
||||||
waitedLongEnough = true;
|
expect(true).toBeTruthy('testing iframes');
|
||||||
expect(true).toBeTruthy("testing iframes");
|
|
||||||
done();
|
done();
|
||||||
}, 50);
|
}, 50);
|
||||||
});
|
});
|
||||||
});
|
});
|
Loading…
Reference in New Issue
Block a user