Skip to content

Commit

Permalink
Cleanup lint warnings from recent testing changes
Browse files Browse the repository at this point in the history
Also, relaxed a rule for dot notation (and unrelaxed it in src).
  • Loading branch information
zpao committed Nov 14, 2013
1 parent b61eacd commit d1fa53c
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 46 deletions.
1 change: 1 addition & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"noempty": true,
"nonstandard": true,
"onecase": true,
"sub": true,
"regexdash": true,
"trailing": true,
"undef": true,
Expand Down
9 changes: 3 additions & 6 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,9 @@ module.exports = function(grunt) {
grunt.config.set('compress', require('./grunt/config/compress'));

Object.keys(grunt.file.readJSON('package.json').devDependencies)
.filter(function(npmTaskName){ return npmTaskName.indexOf('grunt-') === 0;})
.filter(function(npmTaskName){ return npmTaskName != 'grunt-cli' })
.forEach(function(npmTaskName){
grunt.loadNpmTasks(npmTaskName);
})
;
.filter(function(npmTaskName) { return npmTaskName.indexOf('grunt-') === 0; })
.filter(function(npmTaskName) { return npmTaskName != 'grunt-cli'; })
.forEach(function(npmTaskName) { grunt.loadNpmTasks(npmTaskName); });

// Alias 'jshint' to 'lint' to better match the workflow we know
grunt.registerTask('lint', ['jshint']);
Expand Down
36 changes: 23 additions & 13 deletions grunt/config/server.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
module.exports = function(grunt){
'use strict';

module.exports = function(grunt) {

function testResultLoggerMiddleware(req, res, next) {
if (!(req.method == 'POST' && req._parsedUrl.pathname.indexOf('/reportTestResults') === 0)) return next();
if (!(req.method == 'POST' && req._parsedUrl.pathname.indexOf('/reportTestResults') === 0)) {
return next();
}
var logType = 'writeln';
var message = req.body;

if (req.body.type && req.body.message){
if (req.body.type == 'error') logType = 'error';
else if (req.body.message.indexOf('ok') === 0) logType = 'ok';
else if (req.body.message.indexOf('not ok') === 0) logType = 'error';
if (req.body.type == 'error') {
logType = 'error';
} else if (req.body.message.indexOf('ok') === 0) {
logType = 'ok';
} else if (req.body.message.indexOf('not ok') === 0) {
logType = 'error';
}
message = req.body.message;
}
if (typeof message != 'string') message = JSON.stringify(message, null, 2);
if (typeof message != 'string') {
message = JSON.stringify(message, null, 2);
}
grunt.log[logType]('[%s][%s]', req.headers['user-agent'], Date.now(), message);
res.write('<!doctype html><meta charset=utf-8>');
res.end('Got it, thanks!');
Expand All @@ -24,20 +34,20 @@ module.exports = function(grunt){
hostname: '*',
port: 9999,
middleware: function(connect, options) {
connect.logger.token('user-agent', function(req, res){ return req.headers['user-agent']; });
connect.logger.token('timestamp', function(req, res){ return Date.now(); });

connect.logger.token('user-agent', function(req, res) { return req.headers['user-agent']; });
connect.logger.token('timestamp', function(req, res) { return Date.now(); });

return [
connect.json(),
testResultLoggerMiddleware,

connect.logger({format:'[:user-agent][:timestamp] :method :url', stream:grunt.verbose}),
connect.static(options.base),
connect.directory(options.base)
];
},
}
}
}
}
};
};
12 changes: 8 additions & 4 deletions grunt/config/webdriver-jasmine.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

var grunt = require('grunt');


Expand All @@ -14,9 +16,11 @@ exports.local = {
onError: function(error){
grunt.fatal(error);
}
}
};

if (grunt.option('debug')) exports.local.url += '?debug=' + grunt.option('debug');
if (grunt.option('debug')) {
exports.local.url += '?debug=' + grunt.option('debug');
}


exports.saucelabs = {
Expand All @@ -43,7 +47,7 @@ exports.saucelabs = {
},
onComplete: exports.local.onComplete,
onError: exports.local.onError
}
};

/* https://saucelabs.com/docs/platforms */
exports.saucelabs_ios =
Expand Down Expand Up @@ -74,7 +78,7 @@ exports.saucelabs_ie10 = sauceItUp({ browserName: 'internet explorer', version:
exports.saucelabs_ie11 = sauceItUp({ browserName: 'internet explorer', version: 11, platform:'Windows 8.1' });


function sauceItUp(desiredCapabilities){
function sauceItUp(desiredCapabilities) {
desiredCapabilities["build"] = exports.saucelabs.desiredCapabilities["build"];
desiredCapabilities["tunnel-identifier"] = exports.saucelabs.desiredCapabilities["tunnel-identifier"];
return {
Expand Down
2 changes: 1 addition & 1 deletion grunt/tasks/populist.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

var grunt = require('grunt');
var fs = require('fs')
var fs = require('fs');

module.exports = function() {
var config = this.data;
Expand Down
15 changes: 10 additions & 5 deletions grunt/tasks/sauce-tunnel.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
'use strict';

var grunt = require('grunt');
var SauceTunnel = require('sauce-tunnel');

module.exports = function(){
module.exports = function() {
var task = this;
var config = task.data;
var shouldStayAliveForever = task.flags.keepalive;

var SAUCE_ACCESS_KEY = process.env.SAUCE_ACCESS_KEY;
if (!SAUCE_ACCESS_KEY) grunt.fatal('Requires the environment variable SAUCE_ACCESS_KEY to be set');
if (!SAUCE_ACCESS_KEY) {
grunt.fatal('Requires the environment variable SAUCE_ACCESS_KEY to be set');
}

var SAUCE_USERNAME = process.env.SAUCE_USERNAME;
if (!SAUCE_USERNAME) grunt.fatal('Requires the environment variable SAUCE_USERNAME to be set');
if (!SAUCE_USERNAME) {
grunt.fatal('Requires the environment variable SAUCE_USERNAME to be set');
}

var IDENTIFIER = process.env.TRAVIS_JOB_NUMBER || 'my awesome tunnel';

Expand All @@ -28,7 +33,7 @@ module.exports = function(){
stunnel.on('verbose:writeln', grunt.verbose.writeln.bind(grunt.verbose));

stunnel.openTunnel(function(isOpen){
if (shouldStayAliveForever && isOpen){
if (shouldStayAliveForever && isOpen) {
grunt.verbose.writeln('Keeping the sauce-tunnel open forever because you used the keepalive flag `' + task.nameArgs + '`');
return;
}
Expand Down
42 changes: 27 additions & 15 deletions grunt/tasks/webdriver-jasmine.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/* jshint evil: true */

'use strict';

var grunt = require("grunt");
var wd = require('wd');

Expand All @@ -6,10 +10,14 @@ module.exports = function(){
var taskSucceeded = this.async();

var desiredCapabilities = {};
if (config.desiredCapabilities) Object.keys(config.desiredCapabilities).forEach(function(key){
if (config.desiredCapabilities[key] === undefined) return;
desiredCapabilities[key] = config.desiredCapabilities[key];
});
if (config.desiredCapabilities) {
Object.keys(config.desiredCapabilities).forEach(function(key) {
if (config.desiredCapabilities[key] === undefined) {
return;
}
desiredCapabilities[key] = config.desiredCapabilities[key];
});
}
grunt.verbose.writeln("desiredCapabilities", JSON.stringify(desiredCapabilities));

var browser = wd.promiseChainRemote(config.webdriver.remote);
Expand Down Expand Up @@ -37,26 +45,31 @@ module.exports = function(){
return browser
.eval('document.documentElement.innerText || document.documentElement.textContent')
.then(grunt.verbose.writeln.bind(grunt.verbose))
.then(function(){throw error})
.then(function(){ throw error; })
;
})
.finally(function(){
if (grunt.option('webdriver-keep-open')) return;
if (grunt.option('webdriver-keep-open')) {
return;
}
grunt.verbose.writeln('Closing the browser window. To keep it open, pass the --webdriver-keep-open flag to grunt.');
return browser.quit();
})
.done(
function(){
if (config.onComplete) config.onComplete(results);
function() {
if (config.onComplete) {
config.onComplete(results);
}
taskSucceeded(true);
},
function(error){
if (config.onError) config.onError(error);
function(error) {
if (config.onError) {
config.onError(error);
}
taskSucceeded(false);
}
)
;
}
);
};

function getJSReport(browser){
return browser
Expand All @@ -66,6 +79,5 @@ function getJSReport(browser){
})
.waitForCondition("typeof window.jasmine.getJSReport != 'undefined'", 10e3)
.waitForCondition("window.postDataToURL.running <= 0", 30e3)
.eval("jasmine.getJSReport().passed")
;
.eval("jasmine.getJSReport().passed");
}
8 changes: 6 additions & 2 deletions grunt/tasks/webdriver-phantomjs.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

var grunt = require('grunt');

module.exports = function(){
Expand All @@ -21,7 +23,9 @@ module.exports = function(){
});
child.on('exit', function(code) {
grunt.verbose.writeln('phantomjs END');
if (code) grunt.fatal('phantomjs FAIL');
if (code) {
grunt.fatal('phantomjs FAIL');
}
});

function verboseWrite(chunk) {
Expand All @@ -34,4 +38,4 @@ module.exports = function(){
}
child.stdout.on('data', verboseWrite);
child.stderr.on('data', verboseWrite);
}
};
1 change: 1 addition & 0 deletions src/.jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"nonstandard": true,
"onecase": true,
"regexdash": true,
"sub": false,
"trailing": true,
"undef": true,
"unused": "vars",
Expand Down

0 comments on commit d1fa53c

Please sign in to comment.