Skip to content

Commit

Permalink
Build: Don't assume the browser environment; smoke test on Node w/ jsdom
Browse files Browse the repository at this point in the history
  • Loading branch information
mgol committed Dec 18, 2014
1 parent d6c97ab commit 8acd10f
Show file tree
Hide file tree
Showing 22 changed files with 68 additions and 26 deletions.
15 changes: 14 additions & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,22 @@ module.exports = function( grunt ) {

grunt.registerTask( "lint", [ "jshint", "jscs" ] );

grunt.registerTask( "node-smoke-test", function() {
var done = this.async();
require( "jsdom" ).env( "", function( errors, window ) {
if ( errors ) {
console.error( errors );
done( false );
}
require( "./" )( window );
done();
});
});

// Short list as a high frequency watch task
grunt.registerTask( "dev", [ "build:*:*", "lint" ] );

// Default grunt
grunt.registerTask( "default", [ "jsonlint", "dev", "uglify", "dist:*", "compare_size" ] );
grunt.registerTask( "default",
[ "jsonlint", "dev", "uglify", "dist:*", "compare_size", "node-smoke-test" ] );
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"grunt-jsonlint": "1.0.4",
"grunt-npmcopy": "0.1.0",
"gzip-js": "0.3.2",
"jsdom": "1.5.0",
"load-grunt-tasks": "1.0.0",
"npm": "2.1.12",
"qunitjs": "1.16.0",
Expand Down
8 changes: 6 additions & 2 deletions src/.jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@

"sub": true,

"browser": true,

"globals": {
"window": true,
"setTimeout": true,
"clearTimeout": true,
"setInterval": true,
"clearInterval": true,

"jQuery": true,
"define": true,
"module": true,
Expand Down
4 changes: 3 additions & 1 deletion src/ajax.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
define([
"./core",
"./var/document",
"./var/rnotwhite",
"./ajax/var/location",
"./ajax/var/nonce",
"./ajax/var/rquery",
"./core/init",
"./ajax/parseJSON",
"./ajax/parseXML",
"./deferred"
], function( jQuery, rnotwhite, nonce, rquery ) {
], function( jQuery, document, rnotwhite, location, nonce, rquery ) {

var
rhash = /#.*$/,
Expand Down
2 changes: 1 addition & 1 deletion src/ajax/parseXML.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jQuery.parseXML = function( data ) {

// Support: IE9
try {
tmp = new DOMParser();
tmp = new window.DOMParser();
xml = tmp.parseFromString( data, "text/xml" );
} catch ( e ) {
xml = undefined;
Expand Down
3 changes: 2 additions & 1 deletion src/ajax/script.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
define([
"../core",
"../var/document",
"../ajax"
], function( jQuery ) {
], function( jQuery, document ) {

// Install script dataType
jQuery.ajaxSetup({
Expand Down
3 changes: 3 additions & 0 deletions src/ajax/var/location.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
define(function() {
return window.location;
});
2 changes: 1 addition & 1 deletion src/ajax/xhr.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ define([

jQuery.ajaxSettings.xhr = function() {
try {
return new XMLHttpRequest();
return new window.XMLHttpRequest();
} catch ( e ) {}
};

Expand Down
3 changes: 2 additions & 1 deletion src/attributes/support.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
define([
"../var/document",
"../var/support"
], function( support ) {
], function( document, support ) {

(function() {
var input = document.createElement( "input" ),
Expand Down
6 changes: 2 additions & 4 deletions src/core.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
define([
"./var/arr",
"./var/document",
"./var/slice",
"./var/concat",
"./var/push",
Expand All @@ -8,12 +9,9 @@ define([
"./var/toString",
"./var/hasOwn",
"./var/support"
], function( arr, slice, concat, push, indexOf, class2type, toString, hasOwn, support ) {
], function( arr, document, slice, concat, push, indexOf, class2type, toString, hasOwn, support ) {

var
// Use the correct document accordingly with window argument (sandbox)
document = window.document,

version = "@VERSION",

// Define a local copy of jQuery
Expand Down
3 changes: 2 additions & 1 deletion src/core/init.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// Initialize a jQuery object
define([
"../core",
"../var/document",
"./var/rsingleTag",
"../traversing/findFilter"
], function( jQuery, rsingleTag ) {
], function( jQuery, document, rsingleTag ) {

// A central reference to the root jQuery(document)
var rootjQuery,
Expand Down
3 changes: 2 additions & 1 deletion src/core/parseHTML.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
define([
"../core",
"../var/document",
"./var/rsingleTag",

// This is the only module that needs core/support
"./support",

// buildFragment
"../manipulation"
], function( jQuery, rsingleTag, support ) {
], function( jQuery, document, rsingleTag, support ) {

// data: string of html
// context (optional): If specified, the fragment will be created in this context,
Expand Down
3 changes: 2 additions & 1 deletion src/core/ready.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
define([
"../core",
"../var/document",
"../core/init",
"../deferred"
], function( jQuery ) {
], function( jQuery, document ) {

// The deferred used on DOM ready
var readyList;
Expand Down
8 changes: 7 additions & 1 deletion src/core/support.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
define([
"../var/document",
"../var/support"
], function( support ) {
], function( document, support ) {

support.createHTMLDocument = (function() {
var doc = document.implementation.createHTMLDocument( "" );
// Support: Node with jsdom<=1.5.0+
// jsdom's document created via the above method doesn't contain the body
if ( !doc.body ) {
return false;
}
doc.body.innerHTML = "<form></form><form></form>";
return doc.body.childNodes.length === 2;
})();
Expand Down
3 changes: 2 additions & 1 deletion src/css/defaultDisplay.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
define([
"../core",
"../var/document",
"../manipulation" // appendTo
], function( jQuery ) {
], function( jQuery, document ) {

var iframe,
elemdisplay = {
Expand Down
3 changes: 2 additions & 1 deletion src/css/support.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
define([
"../core",
"../var/document",
"../var/support"
], function( jQuery, support ) {
], function( jQuery, document, support ) {

(function() {
var pixelPositionVal, boxSizingReliableVal,
Expand Down
3 changes: 2 additions & 1 deletion src/effects.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
define([
"./core",
"./var/document",
"./var/pnum",
"./css/var/cssExpand",
"./css/var/isHidden",
Expand All @@ -12,7 +13,7 @@ define([
"./css",
"./deferred",
"./traversing"
], function( jQuery, pnum, cssExpand, isHidden, defaultDisplay, dataPriv ) {
], function( jQuery, document, pnum, cssExpand, isHidden, defaultDisplay, dataPriv ) {

var
fxNow, timerId,
Expand Down
3 changes: 2 additions & 1 deletion src/event.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
define([
"./core",
"./var/document",
"./var/rnotwhite",
"./var/hasOwn",
"./var/slice",
Expand All @@ -9,7 +10,7 @@ define([
"./core/init",
"./data/accepts",
"./selector"
], function( jQuery, rnotwhite, hasOwn, slice, support, dataPriv ) {
], function( jQuery, document, rnotwhite, hasOwn, slice, support, dataPriv ) {

var
rkeyEvent = /^key/,
Expand Down
3 changes: 2 additions & 1 deletion src/manipulation/support.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
define([
"../var/document",
"../var/support"
], function( support ) {
], function( document, support ) {

(function() {
var fragment = document.createDocumentFragment(),
Expand Down
5 changes: 3 additions & 2 deletions src/offset.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
define([
"./core",
"./core/access",
"./var/document",
"./css/var/rnumnonpx",
"./css/curCSS",
"./css/addGetHookIf",
Expand All @@ -9,9 +10,9 @@ define([
"./core/init",
"./css",
"./selector" // contains
], function( jQuery, access, rnumnonpx, curCSS, addGetHookIf, support ) {
], function( jQuery, access, document, rnumnonpx, curCSS, addGetHookIf, support ) {

var docElem = window.document.documentElement;
var docElem = document.documentElement;

/**
* Gets a window from an element
Expand Down
7 changes: 4 additions & 3 deletions src/selector-native.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
define([
"./core"
], function( jQuery ) {
"./core",
"./var/document"
], function( jQuery, document ) {

/*
* Optional (non-Sizzle) selector module for custom builds.
Expand Down Expand Up @@ -28,7 +29,7 @@ define([
*/

var hasDuplicate,
docElem = window.document.documentElement,
docElem = document.documentElement,
matches = docElem.matches ||
docElem.webkitMatchesSelector ||
docElem.mozMatchesSelector ||
Expand Down
3 changes: 3 additions & 0 deletions src/var/document.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
define(function() {
return window.document;
});

0 comments on commit 8acd10f

Please sign in to comment.