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