Skip to content
This repository has been archived by the owner on Feb 16, 2021. It is now read-only.

Commit

Permalink
Hardening the JSHint config for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesMGreene committed May 2, 2014
1 parent faadacc commit 7702ca7
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 59 deletions.
9 changes: 2 additions & 7 deletions Gruntfile.js
Expand Up @@ -22,16 +22,11 @@ module.exports = function(grunt) {
// Task configuration
jshint: {
options: {
jshintrc: ".jshintrc"
jshintrc: true
},
Gruntfile: ["Gruntfile.js"],
js: ["src/javascript/ZeroClipboard/**/*.js"],
test: {
options: {
jshintrc: "test/.jshintrc"
},
src: ["test/*.js"]
}
test: ["test/*.js"]
},
flexpmd: {
flash: {
Expand Down
62 changes: 55 additions & 7 deletions test/.jshintrc
@@ -1,20 +1,68 @@
{
"boss": true,
"browser": true,
/* Enforcing options */
"bitwise": true,
"camelcase": true,
"curly": true,
"eqeqeq": true,
"eqnull": true,
"es3": true,
"es5": false,
"evil": true,
"globalstrict": true,
"forin": true,
"freeze": true,
"immed": true,
"indent": 2,
"multistr": true,
"latedef": true,
"newcap": true,
"noarg": true,
"noempty": true,
"nonbsp": true,
"nonew": true,
"plusplus": false,
"quotmark": "double",
"undef": true,
"unused": true,
"strict": true,
"trailing": true,
"maxparams": 2,
"maxdepth": 3,
"maxstatements": false,
"maxlen": false, /* IDEAL: 120? */


/* Relaxing options */
"asi": false,
"boss": false,
"debug": false,
"eqnull": true,
"esnext": false,
"evil": false,
"expr": false,
"funcscope": false,
"gcl": false,
"globalstrict": false,
"iterator": false,
"lastsemic": false,
"laxbreak": false,
"laxcomma": false,
"loopfunc": false,
"maxerr": 50,
"moz": false,
"multistr": false,
"notypeof": false,
"proto": false,
"scripturl": false,
"smarttabs": false,
"shadow": false,
"sub": false,
"supernew": false,
"validthis": false,
"noyield": false,

/* Environments */
"browser": true,

/* Global variables */
"globals": {
"$": false,
"QUnit": false
}
}
}
6 changes: 3 additions & 3 deletions test/ZeroClipboard.js
@@ -1,8 +1,7 @@
/*global ZeroClipboard */

"use strict";

(function(module, test) {
"use strict";

// Helper functions
var TestUtils = {
Expand Down Expand Up @@ -208,7 +207,8 @@

// Assert, arrange, assert, act, assert
assert.equal(TestUtils.getHtmlBridge(), null, "The bridge does not exist before creating a client");
var client = new ZeroClipboard();
/*jshint nonew:false */
new ZeroClipboard();
assert.notEqual(TestUtils.getHtmlBridge(), null, "The bridge does exist after creating a client");
ZeroClipboard.destroy();
assert.equal(TestUtils.getHtmlBridge(), null, "The bridge does not exist after calling `destroy`");
Expand Down
21 changes: 11 additions & 10 deletions test/client.js
@@ -1,8 +1,7 @@
/*global ZeroClipboard, _clipData, _clipDataFormatMap, _flashState */

"use strict";

(function(module, test) {
"use strict";

// Helper functions
var TestUtils = {
Expand Down Expand Up @@ -334,8 +333,8 @@
var pendingText = ZeroClipboard.emit("copy");

// Assert
assert.strictEqual(_clipData["text/plain"].replace(/\r\n/g, '\n'), expectedText);
assert.strictEqual(pendingText.text.replace(/\r\n/g, '\n'), expectedText);
assert.strictEqual(_clipData["text/plain"].replace(/\r\n/g, "\n"), expectedText);
assert.strictEqual(pendingText.text.replace(/\r\n/g, "\n"), expectedText);
assert.deepEqual(_clipDataFormatMap, { "text": "text/plain" });

// Revert
Expand Down Expand Up @@ -372,17 +371,17 @@
var pendingText = ZeroClipboard.emit("copy");

// Assert
assert.strictEqual(_clipData["text/plain"].replace(/\r\n/g, '\n'), expectedText);
assert.strictEqual(_clipData["text/plain"].replace(/\r\n/g, "\n"), expectedText);
assert.strictEqual(
_clipData["text/html"]
.replace(/\r\n/g, '\n')
.replace(/\r\n/g, "\n")
.replace(/<\/?pre(?:\s+[^>]*)?>/gi, function($0) { return $0.toLowerCase(); }),
expectedHtml
);
assert.strictEqual(pendingText.text.replace(/\r\n/g, '\n'), expectedText);
assert.strictEqual(pendingText.text.replace(/\r\n/g, "\n"), expectedText);
assert.strictEqual(
pendingText.html
.replace(/\r\n/g, '\n')
.replace(/\r\n/g, "\n")
.replace(/<\/?pre(?:\s+[^>]*)?>/gi, function($0) { return $0.toLowerCase(); }),
expectedHtml
);
Expand Down Expand Up @@ -517,7 +516,8 @@
// Assert, arrange, assert, act, assert
assert.ok(!ZeroClipboard.prototype._singleton, "The client singleton does not exist before creating a client");
assert.equal(document.getElementById("global-zeroclipboard-html-bridge"), null, "The HTML bridge does not exist before creating a client");
var client = new ZeroClipboard();
/*jshint nonew:false */
new ZeroClipboard();
assert.ok(!ZeroClipboard.prototype._singleton, "The client singleton does exist after creating a client");
assert.notEqual(document.getElementById("global-zeroclipboard-html-bridge"), null, "The HTML bridge does exist after creating a client");
ZeroClipboard.destroy();
Expand Down Expand Up @@ -552,7 +552,8 @@
ZeroClipboard.isFlashUnusable = function() {
return false;
};
var client = new ZeroClipboard();
/*jshint nonew:false */
new ZeroClipboard();

// Assert, act, assert
assert.strictEqual(_flashState.ready, false);
Expand Down
3 changes: 1 addition & 2 deletions test/core.js
@@ -1,8 +1,7 @@
/*global ZeroClipboard, _globalConfig:true, _clipData, _objectKeys, _deleteOwnProperties */

"use strict";

(function(module, test) {
"use strict";

var originalConfig;

Expand Down
45 changes: 21 additions & 24 deletions test/event.js
@@ -1,8 +1,7 @@
/*global ZeroClipboard, _currentElement:true, _flashState:true, _extend, _clipData, _importClipDataFromFlash, _exportClipDataForFlash */

"use strict";
/*global ZeroClipboard, _currentElement:true, _flashState:true, _extend, _clipData */

(function(module, test) {
"use strict";

var originalFlashState, originalConfig;

Expand Down Expand Up @@ -475,7 +474,7 @@
var id = client.id;

// Act (should auto-fire immediately but the handler will be invoked asynchronously)
client.on( 'error', function(event) {
client.on( "error", function(event) {
// Assert
assert.strictEqual(this, client);
assert.strictEqual(this.id, id);
Expand All @@ -499,10 +498,10 @@
var id = client.id;

// Act
client.on( 'ready', function(event) {
assert.ok(false, 'The `ready` event should NOT have fired!');
client.on( "ready", function(/* event */) {
assert.ok(false, "The `ready` event should NOT have fired!");
} );
client.on( 'error', function(event) {
client.on( "error", function(event) {
// Assert
assert.strictEqual(this, client);
assert.strictEqual(this.id, id);
Expand All @@ -527,10 +526,10 @@
ZeroClipboard.config({ flashLoadTimeout: 2000 });
var client = new ZeroClipboard();
var id = client.id;
client.on( 'ready', function(event) {
assert.ok(false, 'The `ready` event should NOT have fired!');
client.on( "ready", function(/* event */) {
assert.ok(false, "The `ready` event should NOT have fired!");
} );
client.on( 'error', function(event) {
client.on( "error", function(event) {
// Assert
assert.strictEqual(this, client);
assert.strictEqual(this.id, id);
Expand Down Expand Up @@ -561,12 +560,11 @@
_flashState.version = "11.0.0";
_flashState.deactivated = true;
var client = new ZeroClipboard();
var currentEl = document.getElementById("d_clip_button");
var id = client.id;
client.on( 'ready', function(event) {
assert.ok(false, 'The `ready` event should NOT have fired!');
client.on( "ready", function(/* event */) {
assert.ok(false, "The `ready` event should NOT have fired!");
} );
client.on( 'error', function(event) {
client.on( "error", function(event) {
// Assert
assert.strictEqual(this, client);
assert.strictEqual(this.id, id);
Expand Down Expand Up @@ -595,7 +593,7 @@
var currentEl = document.getElementById("d_clip_button");
var id = client.id;
client.clip(currentEl);
client.on( 'ready', function(event) {
client.on( "ready", function(event) {
// Assert
assert.strictEqual(this, client);
assert.strictEqual(this.id, id);
Expand Down Expand Up @@ -647,12 +645,11 @@
_flashState.version = "11.0.0";
_flashState.deactivated = true;
var client = new ZeroClipboard();
var currentEl = document.getElementById("d_clip_button");
var id = client.id;
client.on( 'ready', function(event) {
assert.ok(false, 'The `ready` event should NOT have fired!');
client.on( "ready", function(/* event */) {
assert.ok(false, "The `ready` event should NOT have fired!");
} );
client.on( 'error', function(event) {
client.on( "error", function(event) {
// Assert
assert.strictEqual(this, client);
assert.strictEqual(this.id, id);
Expand Down Expand Up @@ -800,25 +797,25 @@
client.clip(currentEl);
ZeroClipboard.activate(currentEl);

client.on( 'ready error', function(event) {
client.on( "ready error", function(/* event */) {
// Assert
assert.strictEqual(this, client);
} );
client.on( 'mousedown mouseover mouseup beforecopy', function(event) {
client.on( "mousedown mouseover mouseup beforecopy", function(event) {
// Assert
assert.strictEqual(event.target, currentEl);
} );
client.on( 'copy', function(event) {
client.on( "copy", function(event) {
// Assert
assert.strictEqual(event.target, currentEl);
assert.ok(_clipData["text/plain"]);
} );
client.on( 'aftercopy', function(event) {
client.on( "aftercopy", function(event) {
// Assert
assert.strictEqual(event.target, currentEl);
assert.ok(!_clipData["text/plain"]);
} );
client.on( 'mouseout', function(event) {
client.on( "mouseout", function(event) {
// Assert
assert.strictEqual(event.target, currentEl);
QUnit.start();
Expand Down
3 changes: 1 addition & 2 deletions test/flash.js
@@ -1,8 +1,7 @@
/*global _flashState, _detectFlashSupport */

"use strict";

(function(module, test) {
"use strict";

var mimeType, ax;

Expand Down
7 changes: 3 additions & 4 deletions test/utils.js
@@ -1,8 +1,7 @@
/*global _camelizeCssPropName, _getStyle, _removeClass, _addClass, _vars, _cacheBust, _inArray, _dispatchCallback, _extend, _extractDomain, _determineScriptAccess, _objectKeys, _deleteOwnProperties, _pick, _omit, _mapClipDataToFlash, _mapClipResultsFromFlash, _args */

"use strict";

(function(module, test) {
"use strict";

module("utils.js");

Expand Down Expand Up @@ -671,11 +670,11 @@
var fn = function() {};
var expectedOutput1 = [1, 2, 3];
var expectedOutput2 = [fn];
var expectedOutput3 = [{ foo: 'bar' }];
var expectedOutput3 = [{ foo: "bar" }];
var expectedOutput4 = [[1, 2, 3]];
var inputArgs1 = _arguments(1, 2, 3);
var inputArgs2 = _arguments(fn);
var inputArgs3 = _arguments({ foo: 'bar' });
var inputArgs3 = _arguments({ foo: "bar" });
var inputArgs4 = _arguments([1, 2, 3]);

// Act
Expand Down

0 comments on commit 7702ca7

Please sign in to comment.