Skip to content

Commit

Permalink
Lint tweaks.
Browse files Browse the repository at this point in the history
  • Loading branch information
XhmikosR committed Apr 4, 2017
1 parent b9522f4 commit f981d37
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 64 deletions.
26 changes: 14 additions & 12 deletions Gruntfile.js
Expand Up @@ -15,7 +15,7 @@ module.exports = function(grunt) {
jshint: {
all: [
'Gruntfile.js',
'tasks/**/*.js',
'tasks/**/*.js'
],
options: {
jshintrc: '.jshintrc'
Expand All @@ -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: {
Expand All @@ -47,7 +47,7 @@ module.exports = function(grunt) {
]
}
},
urls_and_files: {
urlsAndFiles: {
options: {
urls: '<%= qunit.urls.options.urls %>'
},
Expand Down Expand Up @@ -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) {
Expand All @@ -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.');
Expand Down
11 changes: 8 additions & 3 deletions phantomjs/bridge.js
Expand Up @@ -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);
Expand All @@ -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.
Expand Down
99 changes: 52 additions & 47 deletions tasks/qunit.js
Expand Up @@ -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 = {};
Expand All @@ -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) {
Expand All @@ -63,9 +70,9 @@ module.exports = function(grunt) {
}
grunt.log.writeln();
}
};
}

var createStatus = function() {
function createStatus () {
return {
passed: 0,
failed: 0,
Expand All @@ -77,51 +84,51 @@ 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;
statusA.todo += statusB.todo;
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;
var str = module + '\x1C' + undefined;
var len = str.length;

for (; i < len; i++) {
hash = ((hash << 5) - hash) + str.charCodeAt(i);
hash = ((hash << 5) - hash) + str.charCodeAt(i);
hash |= 0;
}

Expand All @@ -134,7 +141,7 @@ module.exports = function(grunt) {
}

return hex.slice(-8);
};
}

// QUnit hooks.
phantomjs.on('qunit.begin', function() {
Expand All @@ -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];
});

Expand Down Expand Up @@ -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);
}
});

Expand Down Expand Up @@ -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;
});
Expand Down Expand Up @@ -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) {
Expand All @@ -281,15 +286,15 @@ 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);
parsed.query[queryParam] = value;
delete parsed.search;
return url.format(parsed);
});
};
}

if (options.noGlobals) {
// Append a noglobal query string param to all urls
Expand Down Expand Up @@ -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));
}

Expand All @@ -342,7 +347,7 @@ module.exports = function(grunt) {
// Otherwise, process next url.
next();
}
},
}
});
},
// All tests have been run.
Expand Down
5 changes: 3 additions & 2 deletions 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) {
Expand Down

0 comments on commit f981d37

Please sign in to comment.