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'
|
||||
|
@ -22,7 +22,7 @@ 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 = {};
|
||||
|
||||
@ -79,12 +79,12 @@ module.exports = function(grunt) {
|
||||
polyfills: [],
|
||||
outfile: '_SpecRunner.html',
|
||||
host: '',
|
||||
template : __dirname + '/jasmine/templates/DefaultRunner.tmpl',
|
||||
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')) {
|
||||
@ -129,7 +129,7 @@ module.exports = function(grunt) {
|
||||
|
||||
if (options.host) {
|
||||
if (!(/\/$/).test(options.host)) {
|
||||
options.host = options.host + '/';
|
||||
options.host += '/';
|
||||
}
|
||||
file = options.host + options.outfile;
|
||||
}
|
||||
@ -206,7 +206,7 @@ module.exports = function(grunt) {
|
||||
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);
|
||||
}
|
||||
});
|
||||
@ -273,11 +273,11 @@ module.exports = function(grunt) {
|
||||
|
||||
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';
|
||||
@ -348,13 +348,13 @@ module.exports = function(grunt) {
|
||||
|
||||
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?');
|
||||
}
|
||||
@ -372,13 +372,13 @@ 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);
|
||||
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,7 +389,7 @@ 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]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -406,7 +406,7 @@ module.exports = function(grunt) {
|
||||
}
|
||||
}
|
||||
|
||||
phantomjs.on('jasmine.done', function(elapsed) {
|
||||
phantomjs.on('jasmine.done', function() {
|
||||
phantomjs.halt();
|
||||
});
|
||||
|
||||
|
@ -1,5 +1,4 @@
|
||||
/*global window:false, alert:false, jasmine:false, Node:false */
|
||||
/*jshint curly:false*/
|
||||
/* global window:true, alert:true, jasmine:true, Node:true */
|
||||
|
||||
'use strict';
|
||||
|
||||
@ -75,32 +74,46 @@ if (window._phantom) {
|
||||
};
|
||||
|
||||
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,7 +121,7 @@ if (window._phantom) {
|
||||
keyMap.push(key);
|
||||
}
|
||||
} catch (e) {
|
||||
return "[Object]";
|
||||
return '[Object]';
|
||||
}
|
||||
return value;
|
||||
});
|
||||
|
@ -1,4 +1,3 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
exports.init = function(grunt, phantomjs) {
|
||||
@ -38,7 +37,7 @@ exports.init = function(grunt, phantomjs) {
|
||||
outfile = options.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,
|
||||
@ -47,12 +46,12 @@ exports.init = function(grunt, phantomjs) {
|
||||
filteredSpecs = specFilter(gruntfilter, filteredSpecs);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
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'
|
||||
@ -146,20 +145,20 @@ exports.init = function(grunt, phantomjs) {
|
||||
|
||||
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]);
|
||||
pattern = patternArray.splice(0, 1)[0];
|
||||
|
||||
if (pattern.length > 0) {
|
||||
if (pattern.indexOf('/') === -1) {
|
||||
specPattern = new RegExp("("+pattern+"[^/]*)(?!/)$", "ig");
|
||||
specPattern = new RegExp('(' + pattern + '[^/]*)(?!/)$', 'ig');
|
||||
} else if (pattern.indexOf('/') === 0) {
|
||||
specPattern = new RegExp("("+pattern+"[^/]*)(?=/)", "ig");
|
||||
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.
|
||||
|
@ -46,9 +46,9 @@ exports.jasmine = {
|
||||
},
|
||||
|
||||
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,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
|
||||
|
||||
[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"]
|
||||
[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){
|
||||
var waitedLongEnough;
|
||||
iframe = document.createElement("iframe");
|
||||
iframe.src = "http://localhost:9000";
|
||||
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");
|
||||
expect(true).toBeTruthy('testing iframes');
|
||||
done();
|
||||
}, 50);
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user