]> source.dussan.org Git - jquery.git/commitdiff
Build: Don't assume the browser environment; smoke test on Node w/ jsdom
authorMichał Gołębiowski <m.goleb@gmail.com>
Thu, 11 Sep 2014 20:18:34 +0000 (15:18 -0500)
committerMichał Gołębiowski <m.goleb@gmail.com>
Fri, 26 Dec 2014 12:26:46 +0000 (13:26 +0100)
Fixes gh-1950
Closes gh-1949

23 files changed:
Gruntfile.js
package.json
src/.jshintrc
src/ajax.js
src/ajax/parseXML.js
src/ajax/script.js
src/ajax/var/location.js [new file with mode: 0644]
src/ajax/xhr.js
src/attributes/support.js
src/core.js
src/core/init.js
src/core/parseHTML.js
src/core/ready.js
src/core/support.js
src/css/defaultDisplay.js
src/css/support.js
src/effects.js
src/event.js
src/manipulation/support.js
src/offset.js
src/selector-native.js
src/var/document.js [new file with mode: 0644]
src/var/documentElement.js [new file with mode: 0644]

index 3e9940f1c37fd0e7199b585dc17a3152da4877f0..aefc54512b7dc228d0515ed01e9ccadafa548287 100644 (file)
@@ -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" ] );
 };
index 950c66821849a728fca77b3ff9fec7ad337cacf1..278251e0723190e6086fefe586178589628236a7 100644 (file)
@@ -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"
   }
 }
index 93e3202469d656f193cc4888b538a83a04c17035..dab1957d72e77c057231d93524493bc27d858e74 100644 (file)
 
        "sub": true,
 
-       "browser": true,
-
        "globals": {
+               "window": true,
+               "setTimeout": true,
+               "clearTimeout": true,
+               "setInterval": true,
+               "clearInterval": true,
+
                "jQuery": true,
                "define": true,
                "module": true,
index 9765e95d61ea73eb453ae0093ebec17859f627ec..dafbc6082b386469a1c474c093f8b07f6537615a 100644 (file)
@@ -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 = /#.*$/,
index 6a40c854a6e995cefc6d3e5de706ea25bd395255..962dc88873efb5d19004fd168f0b83025f5dfab6 100644 (file)
@@ -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;
        }
index e5ad4d8f9242e19eef8a1e372a4242c459bb7e9a..bf5f91d53b8b4874c404931dc5a104bbcf49ac38 100644 (file)
@@ -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 (file)
index 0000000..4c9cf4a
--- /dev/null
@@ -0,0 +1,3 @@
+define(function() {
+       return window.location;
+});
index 32afd2309ba0c5a1c35e23aaad24b3c229eaa578..c1aceaa4a4929d9d6d9e521d86001b694ec5bafb 100644 (file)
@@ -6,7 +6,7 @@ define([
 
 jQuery.ajaxSettings.xhr = function() {
        try {
-               return new XMLHttpRequest();
+               return new window.XMLHttpRequest();
        } catch ( e ) {}
 };
 
index bc5eb472e687fde9820da657d9c30407e550abd2..68c96492c0c994c5a8cee7bcd72c06d4e310fba5 100644 (file)
@@ -1,6 +1,7 @@
 define([
+       "../var/document",
        "../var/support"
-], function( support ) {
+], function( document, support ) {
 
 (function() {
        var input = document.createElement( "input" ),
index fa8436a01220af92ad24914a4af1db0a78be30f1..6ce1027a0ba442b01af7d724f31ca6a74f446311 100644 (file)
@@ -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
index 9357e05a34f4982bb4f01caf82269bacdc0b133b..d261cd46b01c89abcbdcb1ed7b6b701c579a9bdb 100644 (file)
@@ -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,
index 2b638e6331b9b6fde5d1f5b84fdef36971a32c4c..b0f489536edf9fe6f433340054b3f5c2451c62e4 100644 (file)
@@ -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,
index 8cef55124ba776fcbeed8a7ab983b61f24dbf61c..cc812e6ac0a168fcacb30d410c8279c749354e96 100644 (file)
@@ -1,8 +1,9 @@
 define([
        "../core",
+       "../var/document",
        "../core/init",
        "../deferred"
-], function( jQuery ) {
+], function( jQuery, document ) {
 
 // The deferred used on DOM ready
 var readyList;
index ebed460aebc81ce44df98f824253d343b9a8f9fb..7fc1d82b2183fc85edded4b80ead5d3db33111e9 100644 (file)
@@ -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;
 })();
index a6f60d17e70495affd525def2f1ad169c3c2e2a5..3771be6d135b54a5f28177d08c9e9cf6dd7e862a 100644 (file)
@@ -1,7 +1,8 @@
 define([
        "../core",
+       "../var/document",
        "../manipulation" // appendTo
-], function( jQuery ) {
+], function( jQuery, document ) {
 
 var iframe,
        elemdisplay = {
index 0adb5f325b01ff2d531ae6fff4e0eda2986725bf..ffe3ed9bb53aa1fad8ed9168201f64fe81b419e0 100644 (file)
@@ -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;
index 683aaa1b1fb1e0a44d83766b67394adf3210f4c1..3aa408b51e0c99d900e97bc309e616e9d4d720f5 100644 (file)
@@ -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,
index 0dd44e2449cd4abe48fc44827aa1ac4691f5b859..93b68d25f2ff5df5c4e85e599b4f53b1d06a2361 100644 (file)
@@ -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/,
index 98b7528189dc16054346b250c851fd66f69c88f7..ddea2ff98b58f815466d8daf2d00932de9f3474c 100644 (file)
@@ -1,6 +1,7 @@
 define([
+       "../var/document",
        "../var/support"
-], function( support ) {
+], function( document, support ) {
 
 (function() {
        var fragment = document.createDocumentFragment(),
index f4b478f1004047ca40984947887d3936555f427c..e7cb23929822453383b607185932ba90d6a853a9 100644 (file)
@@ -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;
                });
        }
 });
index e6854d580ed30be4a07c2313a6e4aef3bad9ea18..1b2dd185baa5f7a8efa10acccc8fbf7df4a8d003 100644 (file)
@@ -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 (file)
index 0000000..ded014f
--- /dev/null
@@ -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 (file)
index 0000000..c639670
--- /dev/null
@@ -0,0 +1,5 @@
+define([
+       "./document"
+], function( document ) {
+       return document.documentElement;
+});