diff options
author | Michał Gołębiowski <m.goleb@gmail.com> | 2014-09-11 15:18:34 -0500 |
---|---|---|
committer | Michał Gołębiowski <m.goleb@gmail.com> | 2014-12-26 13:26:46 +0100 |
commit | 76df9e4e389d80bff410a9e5f08b848de1d21a2f (patch) | |
tree | 215a453aac2f1cc5574f66173e91d391493146d3 | |
parent | ab20d9d24f0a95df382c02e9ef3dcc4adb86e4f1 (diff) | |
download | jquery-76df9e4e389d80bff410a9e5f08b848de1d21a2f.tar.gz jquery-76df9e4e389d80bff410a9e5f08b848de1d21a2f.zip |
Build: Don't assume the browser environment; smoke test on Node w/ jsdom
Fixes gh-1950
Closes gh-1949
-rw-r--r-- | Gruntfile.js | 17 | ||||
-rw-r--r-- | package.json | 3 | ||||
-rw-r--r-- | src/.jshintrc | 8 | ||||
-rw-r--r-- | src/ajax.js | 4 | ||||
-rw-r--r-- | src/ajax/parseXML.js | 2 | ||||
-rw-r--r-- | src/ajax/script.js | 3 | ||||
-rw-r--r-- | src/ajax/var/location.js | 3 | ||||
-rw-r--r-- | src/ajax/xhr.js | 2 | ||||
-rw-r--r-- | src/attributes/support.js | 3 | ||||
-rw-r--r-- | src/core.js | 6 | ||||
-rw-r--r-- | src/core/init.js | 3 | ||||
-rw-r--r-- | src/core/parseHTML.js | 3 | ||||
-rw-r--r-- | src/core/ready.js | 3 | ||||
-rw-r--r-- | src/core/support.js | 8 | ||||
-rw-r--r-- | src/css/defaultDisplay.js | 3 | ||||
-rw-r--r-- | src/css/support.js | 13 | ||||
-rw-r--r-- | src/effects.js | 3 | ||||
-rw-r--r-- | src/event.js | 3 | ||||
-rw-r--r-- | src/manipulation/support.js | 3 | ||||
-rw-r--r-- | src/offset.js | 10 | ||||
-rw-r--r-- | src/selector-native.js | 17 | ||||
-rw-r--r-- | src/var/document.js | 3 | ||||
-rw-r--r-- | src/var/documentElement.js | 5 |
23 files changed, 88 insertions, 40 deletions
diff --git a/Gruntfile.js b/Gruntfile.js index 3e9940f1c..aefc54512 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -157,9 +157,24 @@ 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( "test_fast", [ "node_smoke_test" ] ); + + grunt.registerTask( "test", [ "default", "test_fast" ] ); + grunt.registerTask( "default", [ "jsonlint", "dev", "uglify", "dist:*", "compare_size" ] ); }; diff --git a/package.json b/package.json index 950c66821..278251e07 100644 --- a/package.json +++ b/package.json @@ -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", @@ -54,6 +55,6 @@ "scripts": { "build": "npm install && grunt", "start": "grunt watch", - "test": "grunt" + "test": "grunt test" } } diff --git a/src/.jshintrc b/src/.jshintrc index 93e320246..dab1957d7 100644 --- a/src/.jshintrc +++ b/src/.jshintrc @@ -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, diff --git a/src/ajax.js b/src/ajax.js index 9765e95d6..dafbc6082 100644 --- a/src/ajax.js +++ b/src/ajax.js @@ -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 = /#.*$/, diff --git a/src/ajax/parseXML.js b/src/ajax/parseXML.js index 6a40c854a..962dc8887 100644 --- a/src/ajax/parseXML.js +++ b/src/ajax/parseXML.js @@ -11,7 +11,7 @@ jQuery.parseXML = function( data ) { // Support: IE9 try { - xml = ( new DOMParser() ).parseFromString( data, "text/xml" ); + xml = ( new window.DOMParser() ).parseFromString( data, "text/xml" ); } catch ( e ) { xml = undefined; } diff --git a/src/ajax/script.js b/src/ajax/script.js index e5ad4d8f9..bf5f91d53 100644 --- a/src/ajax/script.js +++ b/src/ajax/script.js @@ -1,7 +1,8 @@ define([ "../core", + "../var/document", "../ajax" -], function( jQuery ) { +], function( jQuery, document ) { // Install script dataType jQuery.ajaxSetup({ diff --git a/src/ajax/var/location.js b/src/ajax/var/location.js new file mode 100644 index 000000000..4c9cf4a4c --- /dev/null +++ b/src/ajax/var/location.js @@ -0,0 +1,3 @@ +define(function() { + return window.location; +}); diff --git a/src/ajax/xhr.js b/src/ajax/xhr.js index 32afd2309..c1aceaa4a 100644 --- a/src/ajax/xhr.js +++ b/src/ajax/xhr.js @@ -6,7 +6,7 @@ define([ jQuery.ajaxSettings.xhr = function() { try { - return new XMLHttpRequest(); + return new window.XMLHttpRequest(); } catch ( e ) {} }; diff --git a/src/attributes/support.js b/src/attributes/support.js index bc5eb472e..68c96492c 100644 --- a/src/attributes/support.js +++ b/src/attributes/support.js @@ -1,6 +1,7 @@ define([ + "../var/document", "../var/support" -], function( support ) { +], function( document, support ) { (function() { var input = document.createElement( "input" ), diff --git a/src/core.js b/src/core.js index fa8436a01..6ce1027a0 100644 --- a/src/core.js +++ b/src/core.js @@ -1,5 +1,6 @@ define([ "./var/arr", + "./var/document", "./var/slice", "./var/concat", "./var/push", @@ -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 diff --git a/src/core/init.js b/src/core/init.js index 9357e05a3..d261cd46b 100644 --- a/src/core/init.js +++ b/src/core/init.js @@ -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, diff --git a/src/core/parseHTML.js b/src/core/parseHTML.js index 2b638e633..b0f489536 100644 --- a/src/core/parseHTML.js +++ b/src/core/parseHTML.js @@ -1,5 +1,6 @@ define([ "../core", + "../var/document", "./var/rsingleTag", // This is the only module that needs core/support @@ -7,7 +8,7 @@ define([ // 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, diff --git a/src/core/ready.js b/src/core/ready.js index 8cef55124..cc812e6ac 100644 --- a/src/core/ready.js +++ b/src/core/ready.js @@ -1,8 +1,9 @@ define([ "../core", + "../var/document", "../core/init", "../deferred" -], function( jQuery ) { +], function( jQuery, document ) { // The deferred used on DOM ready var readyList; diff --git a/src/core/support.js b/src/core/support.js index ebed460ae..7fc1d82b2 100644 --- a/src/core/support.js +++ b/src/core/support.js @@ -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; })(); diff --git a/src/css/defaultDisplay.js b/src/css/defaultDisplay.js index a6f60d17e..3771be6d1 100644 --- a/src/css/defaultDisplay.js +++ b/src/css/defaultDisplay.js @@ -1,7 +1,8 @@ define([ "../core", + "../var/document", "../manipulation" // appendTo -], function( jQuery ) { +], function( jQuery, document ) { var iframe, elemdisplay = { diff --git a/src/css/support.js b/src/css/support.js index 0adb5f325..ffe3ed9bb 100644 --- a/src/css/support.js +++ b/src/css/support.js @@ -1,11 +1,12 @@ define([ "../core", + "../var/document", + "../var/documentElement", "../var/support" -], function( jQuery, support ) { +], function( jQuery, document, documentElement, support ) { (function() { var pixelPositionVal, boxSizingReliableVal, - docElem = document.documentElement, container = document.createElement( "div" ), div = document.createElement( "div" ); @@ -33,13 +34,13 @@ define([ "display:block;margin-top:1%;top:1%;" + "border:1px;padding:1px;width:4px;position:absolute"; div.innerHTML = ""; - docElem.appendChild( container ); + documentElement.appendChild( container ); var divStyle = window.getComputedStyle( div, null ); pixelPositionVal = divStyle.top !== "1%"; boxSizingReliableVal = divStyle.width === "4px"; - docElem.removeChild( container ); + documentElement.removeChild( container ); } // Support: node.js jsdom @@ -78,11 +79,11 @@ define([ "display:block;margin:0;border:0;padding:0"; marginDiv.style.marginRight = marginDiv.style.width = "0"; div.style.width = "1px"; - docElem.appendChild( container ); + documentElement.appendChild( container ); ret = !parseFloat( window.getComputedStyle( marginDiv, null ).marginRight ); - docElem.removeChild( container ); + documentElement.removeChild( container ); div.removeChild( marginDiv ); return ret; diff --git a/src/effects.js b/src/effects.js index 683aaa1b1..3aa408b51 100644 --- a/src/effects.js +++ b/src/effects.js @@ -1,5 +1,6 @@ define([ "./core", + "./var/document", "./var/pnum", "./css/var/cssExpand", "./css/var/isHidden", @@ -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, diff --git a/src/event.js b/src/event.js index 0dd44e244..93b68d25f 100644 --- a/src/event.js +++ b/src/event.js @@ -1,5 +1,6 @@ define([ "./core", + "./var/document", "./var/rnotwhite", "./var/hasOwn", "./var/slice", @@ -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/, diff --git a/src/manipulation/support.js b/src/manipulation/support.js index 98b752818..ddea2ff98 100644 --- a/src/manipulation/support.js +++ b/src/manipulation/support.js @@ -1,6 +1,7 @@ define([ + "../var/document", "../var/support" -], function( support ) { +], function( document, support ) { (function() { var fragment = document.createDocumentFragment(), diff --git a/src/offset.js b/src/offset.js index f4b478f10..e7cb23929 100644 --- a/src/offset.js +++ b/src/offset.js @@ -1,6 +1,8 @@ define([ "./core", "./core/access", + "./var/document", + "./var/documentElement", "./css/var/rnumnonpx", "./css/curCSS", "./css/addGetHookIf", @@ -9,9 +11,7 @@ define([ "./core/init", "./css", "./selector" // contains -], function( jQuery, access, rnumnonpx, curCSS, addGetHookIf, support ) { - -var docElem = window.document.documentElement; +], function( jQuery, access, document, documentElement, rnumnonpx, curCSS, addGetHookIf, support ) { /** * Gets a window from an element @@ -145,14 +145,14 @@ jQuery.fn.extend({ offsetParent: function() { return this.map(function() { - var offsetParent = this.offsetParent || docElem; + var offsetParent = this.offsetParent || documentElement; while ( offsetParent && ( !jQuery.nodeName( offsetParent, "html" ) && jQuery.css( offsetParent, "position" ) === "static" ) ) { offsetParent = offsetParent.offsetParent; } - return offsetParent || docElem; + return offsetParent || documentElement; }); } }); diff --git a/src/selector-native.js b/src/selector-native.js index e6854d580..1b2dd185b 100644 --- a/src/selector-native.js +++ b/src/selector-native.js @@ -1,6 +1,8 @@ define([ - "./core" -], function( jQuery ) { + "./core", + "./var/document", + "./var/documentElement" +], function( jQuery, document, documentElement ) { /* * Optional (non-Sizzle) selector module for custom builds. @@ -28,12 +30,11 @@ define([ */ var hasDuplicate, - docElem = window.document.documentElement, - matches = docElem.matches || - docElem.webkitMatchesSelector || - docElem.mozMatchesSelector || - docElem.oMatchesSelector || - docElem.msMatchesSelector, + matches = documentElement.matches || + documentElement.webkitMatchesSelector || + documentElement.mozMatchesSelector || + documentElement.oMatchesSelector || + documentElement.msMatchesSelector, sortOrder = function( a, b ) { // Flag for duplicate removal if ( a === b ) { diff --git a/src/var/document.js b/src/var/document.js new file mode 100644 index 000000000..ded014f1a --- /dev/null +++ b/src/var/document.js @@ -0,0 +1,3 @@ +define(function() { + return window.document; +}); diff --git a/src/var/documentElement.js b/src/var/documentElement.js new file mode 100644 index 000000000..c639670f1 --- /dev/null +++ b/src/var/documentElement.js @@ -0,0 +1,5 @@ +define([ + "./document" +], function( document ) { + return document.documentElement; +}); |