From f981d37bd3b71bc59c52a001bd640728da2061ef Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Wed, 5 Apr 2017 00:52:39 +0300 Subject: [PATCH] Lint tweaks. --- Gruntfile.js | 26 +++++----- phantomjs/bridge.js | 11 +++-- tasks/qunit.js | 99 +++++++++++++++++++------------------ test/qunit_noglobal_test.js | 5 +- 4 files changed, 77 insertions(+), 64 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index ceb4eb2..b1bd65e 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -15,7 +15,7 @@ module.exports = function(grunt) { jshint: { all: [ 'Gruntfile.js', - 'tasks/**/*.js', + 'tasks/**/*.js' ], options: { jshintrc: '.jshintrc' @@ -24,21 +24,21 @@ module.exports = function(grunt) { // Create a local web server for testing http:// URIs. connect: { - root_server: { + rootServer: { options: { port: 9000, - base: '.', + base: '.' } } }, // Unit tests. qunit: { - all_tests: ['test/*{1,2}.html'], - individual_tests: { - files: [ - {src: 'test/*{1,2}.html'} - ] + allTests: ['test/*{1,2}.html'], + individualTests: { + files: [{ + src: 'test/*{1,2}.html' + }] }, urls: { options: { @@ -47,7 +47,7 @@ module.exports = function(grunt) { ] } }, - urls_and_files: { + urlsAndFiles: { options: { urls: '<%= qunit.urls.options.urls %>' }, @@ -103,7 +103,9 @@ module.exports = function(grunt) { var currentUrl; grunt.event.on('qunit.spawn', function(url) { currentUrl = url; - if (!successes[currentUrl]) { successes[currentUrl] = 0; } + if (!successes[currentUrl]) { + successes[currentUrl] = 0; + } }); grunt.event.on('qunit.done', function(failed, passed, total) { if (failed === 0 && passed === total) { @@ -122,8 +124,8 @@ module.exports = function(grunt) { 'test/qunit2.html': 3, 'http://localhost:9000/test/qunit1.html': 2, 'http://localhost:9000/test/qunit3.html?foo=bar&noglobals=true': -100, - 'http://localhost:9000/test/qunit4.html' : 1, - 'http://localhost:9000/test/qunit5.html' : 1 + 'http://localhost:9000/test/qunit4.html': 1, + 'http://localhost:9000/test/qunit5.html': 1 }; try { assert.deepEqual(actual, expected, 'Actual should match expected.'); diff --git a/phantomjs/bridge.js b/phantomjs/bridge.js index 8fcf649..f6af10f 100644 --- a/phantomjs/bridge.js +++ b/phantomjs/bridge.js @@ -6,7 +6,8 @@ * Licensed under the MIT license. */ -/*global QUnit:true, alert:true*/ +/* global QUnit:true, alert:true */ + (function (factory) { if (typeof define === 'function' && define.amd) { require(['qunit'], factory); @@ -28,10 +29,14 @@ // These methods connect QUnit to PhantomJS. QUnit.log(function(obj) { // What is this I don’t even - if (obj.message === '[object Object], undefined:undefined') { return; } + if (obj.message === '[object Object], undefined:undefined') { + return; + } // Parse some stuff before sending it. - var actual, expected; + var actual; + var expected; + if (!obj.result) { // Dumping large objects can be very slow, and the dump isn't used for // passing tests, so only dump if the test failed. diff --git a/tasks/qunit.js b/tasks/qunit.js index b7cd10f..70b7b81 100644 --- a/tasks/qunit.js +++ b/tasks/qunit.js @@ -8,18 +8,21 @@ 'use strict'; -module.exports = function(grunt) { - - // Nodejs libs. - var path = require('path'); - var url = require('url'); +// Nodejs libs. +var path = require('path'); +var url = require('url'); +module.exports = function(grunt) { // External lib. var phantomjs = require('grunt-lib-phantomjs').init(grunt); // Keep track of the last-started module and test. Additionally, keep track // of status for individual test files and the entire test suite. - var options, currentModule, currentTest, currentStatus, status; + var options; + var currentModule; + var currentTest; + var currentStatus; + var status; // Keep track of the last-started test(s). var unfinished = {}; @@ -28,22 +31,26 @@ module.exports = function(grunt) { var asset = path.join.bind(null, __dirname, '..'); // Allow an error message to retain its color when split across multiple lines. - var formatMessage = function(str) { - return String(str).split('\n').map(function(s) { return s.magenta; }).join('\n'); - }; + function formatMessage (str) { + return String(str).split('\n') + .map(function(s) { + return s.magenta; + }) + .join('\n'); + } // If options.force then log an error, otherwise exit with a warning - var warnUnlessForced = function (message) { + function warnUnlessForced (message) { if (options && options.force) { grunt.log.error(message); } else { grunt.warn(message); } - }; + } // Keep track of failed assertions for pretty-printing. var failedAssertions = []; - var logFailedAssertions = function() { + function logFailedAssertions () { var assertion; if (options && options.summaryOnly) { @@ -63,9 +70,9 @@ module.exports = function(grunt) { } grunt.log.writeln(); } - }; + } - var createStatus = function() { + function createStatus () { return { passed: 0, failed: 0, @@ -77,9 +84,9 @@ module.exports = function(grunt) { failed: 0 } }; - }; + } - var mergeStatus = function(statusA, statusB) { + function mergeStatus(statusA, statusB) { statusA.passed += statusB.passed; statusA.failed += statusB.failed; statusA.skipped += statusB.skipped; @@ -87,33 +94,33 @@ module.exports = function(grunt) { statusA.runtime += statusB.runtime; statusA.assertions.passed += statusB.assertions.passed; statusA.assertions.failed += statusB.assertions.failed; - }; + } - var generateMessage = function(status) { + function generateMessage(status) { var totalTests = status.passed + status.failed + status.skipped + status.todo; var totalAssertions = status.assertions.passed + status.assertions.failed; return [ totalTests, - " tests completed with ", + ' tests completed with ', status.failed, - " failed, " + + ' failed, ' + status.skipped, - " skipped, and ", + ' skipped, and ', status.todo, - " todo. \n" + + ' todo. \n' + totalAssertions, - " assertions (in ", + ' assertions (in ', status.runtime, - "ms), passed: " + + 'ms), passed: ' + status.assertions.passed, - ", failed: ", + ', failed: ', status.assertions.failed - ].join( "" ); - }; + ].join(''); + } // Copied from QUnit source code - var generateHash = function(module) { + function generateHash (module) { var hex; var i = 0; var hash = 0; @@ -121,7 +128,7 @@ module.exports = function(grunt) { var len = str.length; for (; i < len; i++) { - hash = ((hash << 5) - hash) + str.charCodeAt(i); + hash = ((hash << 5) - hash) + str.charCodeAt(i); hash |= 0; } @@ -134,7 +141,7 @@ module.exports = function(grunt) { } return hex.slice(-8); - }; + } // QUnit hooks. phantomjs.on('qunit.begin', function() { @@ -146,7 +153,7 @@ module.exports = function(grunt) { currentModule = name; }); - phantomjs.on('qunit.moduleDone', function(name/*, failed, passed, total*/) { + phantomjs.on('qunit.moduleDone', function(name) { delete unfinished[name]; }); @@ -181,21 +188,19 @@ module.exports = function(grunt) { } // Log errors if necessary, otherwise success. - if (!testPassed) { + if (testPassed) { + grunt.verbose.ok().or.write('.'); // list assertions or message about todo failure - if (grunt.option('verbose')) { - grunt.log.error(); + } else if (grunt.option('verbose')) { + grunt.log.error(); - if (todo) { - grunt.log.error('Expected at least one failing assertion in todo test:' + name); - } else { - logFailedAssertions(); - } + if (todo) { + grunt.log.error('Expected at least one failing assertion in todo test:' + name); } else { - grunt.log.write('F'.red); + logFailedAssertions(); } } else { - grunt.verbose.ok().or.write('.'); + grunt.log.write('F'.red); } }); @@ -230,7 +235,7 @@ module.exports = function(grunt) { phantomjs.halt(); grunt.verbose.write('...'); grunt.event.emit('qunit.fail.load', url); - grunt.log.error('PhantomJS unable to load "' + url + '" URI.'); + grunt.log.error('PhantomJS unable to load \'' + url + '\' URI.'); status.failed += 1; }); @@ -270,7 +275,7 @@ module.exports = function(grunt) { var urls; if (options.httpBase) { - //If URLs are explicitly referenced, use them still + // If URLs are explicitly referenced, use them still urls = options.urls; // Then create URLs for the src files this.filesSrc.forEach(function(testFile) { @@ -281,7 +286,7 @@ module.exports = function(grunt) { urls = options.urls.concat(this.filesSrc); } - var appendToUrls = function(queryParam, value) { + function appendToUrls (queryParam, value) { // Append the query param to all urls urls = urls.map(function(testUrl) { var parsed = url.parse(testUrl, true); @@ -289,7 +294,7 @@ module.exports = function(grunt) { delete parsed.search; return url.format(parsed); }); - }; + } if (options.noGlobals) { // Append a noglobal query string param to all urls @@ -317,7 +322,7 @@ module.exports = function(grunt) { status = createStatus(); // Pass-through console.log statements. - if(options.console) { + if (options.console) { phantomjs.on('console', console.log.bind(console)); } @@ -342,7 +347,7 @@ module.exports = function(grunt) { // Otherwise, process next url. next(); } - }, + } }); }, // All tests have been run. diff --git a/test/qunit_noglobal_test.js b/test/qunit_noglobal_test.js index afdeebf..5664b99 100644 --- a/test/qunit_noglobal_test.js +++ b/test/qunit_noglobal_test.js @@ -1,7 +1,8 @@ var failures = []; -QUnit.log(function( details ) { - if (details.result === false) +QUnit.log(function(details) { + if (details.result === false) { failures.push(details.message); + } }); QUnit.todo('global pollution', function(assert) {