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'
|
||||||
|
@ -22,7 +22,7 @@ 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 = {};
|
||||||
|
|
||||||
@ -79,12 +79,12 @@ module.exports = function(grunt) {
|
|||||||
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')) {
|
||||||
@ -129,7 +129,7 @@ module.exports = function(grunt) {
|
|||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
@ -206,7 +206,7 @@ module.exports = function(grunt) {
|
|||||||
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);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -273,11 +273,11 @@ module.exports = function(grunt) {
|
|||||||
|
|
||||||
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';
|
||||||
@ -348,13 +348,13 @@ 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?');
|
||||||
}
|
}
|
||||||
@ -372,13 +372,13 @@ 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,7 +389,7 @@ 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]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -406,7 +406,7 @@ module.exports = function(grunt) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
phantomjs.on('jasmine.done', function(elapsed) {
|
phantomjs.on('jasmine.done', function() {
|
||||||
phantomjs.halt();
|
phantomjs.halt();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
/*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';
|
||||||
|
|
||||||
@ -75,32 +74,46 @@ if (window._phantom) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
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,7 +121,7 @@ if (window._phantom) {
|
|||||||
keyMap.push(key);
|
keyMap.push(key);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return "[Object]";
|
return '[Object]';
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
});
|
});
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
exports.init = function(grunt, phantomjs) {
|
exports.init = function(grunt, phantomjs) {
|
||||||
@ -38,7 +37,7 @@ exports.init = function(grunt, phantomjs) {
|
|||||||
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,
|
||||||
@ -47,12 +46,12 @@ exports.init = function(grunt, phantomjs) {
|
|||||||
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'
|
||||||
@ -146,20 +145,20 @@ exports.init = function(grunt, phantomjs) {
|
|||||||
|
|
||||||
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.
|
||||||
|
@ -46,9 +46,9 @@ exports.jasmine = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
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,27 +1,28 @@
|
|||||||
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
|
when running this test with `grunt jasmine:selfTest -d` you got this output
|
||||||
|
|
||||||
[D] ["phantomjs","onLoadFinished","success"]
|
[D] ['phantomjs','onLoadFinished','success']
|
||||||
[D] ["phantomjs","onResourceRequested","http://httpbin.org/status/500"]
|
[D] ['phantomjs','onResourceRequested','http://httpbin.org/status/500']
|
||||||
[D] ["phantomjs","onResourceReceived","http://httpbin.org/status/500"]
|
[D] ['phantomjs','onResourceReceived','http://httpbin.org/status/500']
|
||||||
[D] ["phantomjs","onLoadFinished","fail"]
|
[D] ['phantomjs','onLoadFinished','fail']
|
||||||
[D] ["phantomjs","fail.load","_SpecRunner.html"]
|
[D] ['phantomjs','fail.load','_SpecRunner.html']
|
||||||
|
|
||||||
phantomjs.page.onLoadFinished seems to be called for iframes, too.
|
phantomjs.page.onLoadFinished seems to be called for iframes, too.
|
||||||
A failing onLoadFinished caused this grunt taks to hang.
|
A failing onLoadFinished caused this grunt taks to hang.
|
||||||
Now, after removing the event handler, this following test should work as expected
|
Now, after removing the event handler, this following test should work as expected
|
||||||
*/
|
*/
|
||||||
it("can handle fail on iframe", function(done){
|
it('can handle fail on iframe', function(done) {
|
||||||
var waitedLongEnough;
|
iframe = document.createElement('iframe');
|
||||||
iframe = document.createElement("iframe");
|
iframe.src = 'http://localhost:9000';
|
||||||
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