Skip to content

Commit 76df9e4

Browse files
committedDec 26, 2014
Build: Don't assume the browser environment; smoke test on Node w/ jsdom
Fixes gh-1950 Closes gh-1949
1 parent ab20d9d commit 76df9e4

23 files changed

+88
-40
lines changed
 

‎Gruntfile.js

+16-1
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,24 @@ module.exports = function( grunt ) {
157157

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

160+
grunt.registerTask( "node_smoke_test", function() {
161+
var done = this.async();
162+
require( "jsdom" ).env( "", function( errors, window ) {
163+
if ( errors ) {
164+
console.error( errors );
165+
done( false );
166+
}
167+
require( "./" )( window );
168+
done();
169+
});
170+
});
171+
160172
// Short list as a high frequency watch task
161173
grunt.registerTask( "dev", [ "build:*:*", "lint" ] );
162174

163-
// Default grunt
175+
grunt.registerTask( "test_fast", [ "node_smoke_test" ] );
176+
177+
grunt.registerTask( "test", [ "default", "test_fast" ] );
178+
164179
grunt.registerTask( "default", [ "jsonlint", "dev", "uglify", "dist:*", "compare_size" ] );
165180
};

‎package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"grunt-jsonlint": "1.0.4",
4444
"grunt-npmcopy": "0.1.0",
4545
"gzip-js": "0.3.2",
46+
"jsdom": "1.5.0",
4647
"load-grunt-tasks": "1.0.0",
4748
"npm": "2.1.12",
4849
"qunitjs": "1.16.0",
@@ -54,6 +55,6 @@
5455
"scripts": {
5556
"build": "npm install && grunt",
5657
"start": "grunt watch",
57-
"test": "grunt"
58+
"test": "grunt test"
5859
}
5960
}

‎src/.jshintrc

+6-2
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,13 @@
1515

1616
"sub": true,
1717

18-
"browser": true,
19-
2018
"globals": {
19+
"window": true,
20+
"setTimeout": true,
21+
"clearTimeout": true,
22+
"setInterval": true,
23+
"clearInterval": true,
24+
2125
"jQuery": true,
2226
"define": true,
2327
"module": true,

‎src/ajax.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
define([
22
"./core",
3+
"./var/document",
34
"./var/rnotwhite",
5+
"./ajax/var/location",
46
"./ajax/var/nonce",
57
"./ajax/var/rquery",
68
"./core/init",
79
"./ajax/parseJSON",
810
"./ajax/parseXML",
911
"./deferred"
10-
], function( jQuery, rnotwhite, nonce, rquery ) {
12+
], function( jQuery, document, rnotwhite, location, nonce, rquery ) {
1113

1214
var
1315
rhash = /#.*$/,

‎src/ajax/parseXML.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jQuery.parseXML = function( data ) {
1111

1212
// Support: IE9
1313
try {
14-
xml = ( new DOMParser() ).parseFromString( data, "text/xml" );
14+
xml = ( new window.DOMParser() ).parseFromString( data, "text/xml" );
1515
} catch ( e ) {
1616
xml = undefined;
1717
}

‎src/ajax/script.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
define([
22
"../core",
3+
"../var/document",
34
"../ajax"
4-
], function( jQuery ) {
5+
], function( jQuery, document ) {
56

67
// Install script dataType
78
jQuery.ajaxSetup({

‎src/ajax/var/location.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
define(function() {
2+
return window.location;
3+
});

‎src/ajax/xhr.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ define([
66

77
jQuery.ajaxSettings.xhr = function() {
88
try {
9-
return new XMLHttpRequest();
9+
return new window.XMLHttpRequest();
1010
} catch ( e ) {}
1111
};
1212

‎src/attributes/support.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
define([
2+
"../var/document",
23
"../var/support"
3-
], function( support ) {
4+
], function( document, support ) {
45

56
(function() {
67
var input = document.createElement( "input" ),

‎src/core.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
define([
22
"./var/arr",
3+
"./var/document",
34
"./var/slice",
45
"./var/concat",
56
"./var/push",
@@ -8,12 +9,9 @@ define([
89
"./var/toString",
910
"./var/hasOwn",
1011
"./var/support"
11-
], function( arr, slice, concat, push, indexOf, class2type, toString, hasOwn, support ) {
12+
], function( arr, document, slice, concat, push, indexOf, class2type, toString, hasOwn, support ) {
1213

1314
var
14-
// Use the correct document accordingly with window argument (sandbox)
15-
document = window.document,
16-
1715
version = "@VERSION",
1816

1917
// Define a local copy of jQuery

‎src/core/init.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
// Initialize a jQuery object
22
define([
33
"../core",
4+
"../var/document",
45
"./var/rsingleTag",
56
"../traversing/findFilter"
6-
], function( jQuery, rsingleTag ) {
7+
], function( jQuery, document, rsingleTag ) {
78

89
// A central reference to the root jQuery(document)
910
var rootjQuery,

‎src/core/parseHTML.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
define([
22
"../core",
3+
"../var/document",
34
"./var/rsingleTag",
45

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

89
// buildFragment
910
"../manipulation"
10-
], function( jQuery, rsingleTag, support ) {
11+
], function( jQuery, document, rsingleTag, support ) {
1112

1213
// data: string of html
1314
// context (optional): If specified, the fragment will be created in this context,

‎src/core/ready.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
define([
22
"../core",
3+
"../var/document",
34
"../core/init",
45
"../deferred"
5-
], function( jQuery ) {
6+
], function( jQuery, document ) {
67

78
// The deferred used on DOM ready
89
var readyList;

‎src/core/support.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
define([
2+
"../var/document",
23
"../var/support"
3-
], function( support ) {
4+
], function( document, support ) {
45

56
support.createHTMLDocument = (function() {
67
var doc = document.implementation.createHTMLDocument( "" );
8+
// Support: Node with jsdom<=1.5.0+
9+
// jsdom's document created via the above method doesn't contain the body
10+
if ( !doc.body ) {
11+
return false;
12+
}
713
doc.body.innerHTML = "<form></form><form></form>";
814
return doc.body.childNodes.length === 2;
915
})();

‎src/css/defaultDisplay.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
define([
22
"../core",
3+
"../var/document",
34
"../manipulation" // appendTo
4-
], function( jQuery ) {
5+
], function( jQuery, document ) {
56

67
var iframe,
78
elemdisplay = {

‎src/css/support.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
define([
22
"../core",
3+
"../var/document",
4+
"../var/documentElement",
35
"../var/support"
4-
], function( jQuery, support ) {
6+
], function( jQuery, document, documentElement, support ) {
57

68
(function() {
79
var pixelPositionVal, boxSizingReliableVal,
8-
docElem = document.documentElement,
910
container = document.createElement( "div" ),
1011
div = document.createElement( "div" );
1112

@@ -33,13 +34,13 @@ define([
3334
"display:block;margin-top:1%;top:1%;" +
3435
"border:1px;padding:1px;width:4px;position:absolute";
3536
div.innerHTML = "";
36-
docElem.appendChild( container );
37+
documentElement.appendChild( container );
3738

3839
var divStyle = window.getComputedStyle( div, null );
3940
pixelPositionVal = divStyle.top !== "1%";
4041
boxSizingReliableVal = divStyle.width === "4px";
4142

42-
docElem.removeChild( container );
43+
documentElement.removeChild( container );
4344
}
4445

4546
// Support: node.js jsdom
@@ -78,11 +79,11 @@ define([
7879
"display:block;margin:0;border:0;padding:0";
7980
marginDiv.style.marginRight = marginDiv.style.width = "0";
8081
div.style.width = "1px";
81-
docElem.appendChild( container );
82+
documentElement.appendChild( container );
8283

8384
ret = !parseFloat( window.getComputedStyle( marginDiv, null ).marginRight );
8485

85-
docElem.removeChild( container );
86+
documentElement.removeChild( container );
8687
div.removeChild( marginDiv );
8788

8889
return ret;

‎src/effects.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
define([
22
"./core",
3+
"./var/document",
34
"./var/pnum",
45
"./css/var/cssExpand",
56
"./css/var/isHidden",
@@ -12,7 +13,7 @@ define([
1213
"./css",
1314
"./deferred",
1415
"./traversing"
15-
], function( jQuery, pnum, cssExpand, isHidden, defaultDisplay, dataPriv ) {
16+
], function( jQuery, document, pnum, cssExpand, isHidden, defaultDisplay, dataPriv ) {
1617

1718
var
1819
fxNow, timerId,

‎src/event.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
define([
22
"./core",
3+
"./var/document",
34
"./var/rnotwhite",
45
"./var/hasOwn",
56
"./var/slice",
@@ -9,7 +10,7 @@ define([
910
"./core/init",
1011
"./data/accepts",
1112
"./selector"
12-
], function( jQuery, rnotwhite, hasOwn, slice, support, dataPriv ) {
13+
], function( jQuery, document, rnotwhite, hasOwn, slice, support, dataPriv ) {
1314

1415
var
1516
rkeyEvent = /^key/,

‎src/manipulation/support.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
define([
2+
"../var/document",
23
"../var/support"
3-
], function( support ) {
4+
], function( document, support ) {
45

56
(function() {
67
var fragment = document.createDocumentFragment(),

‎src/offset.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
define([
22
"./core",
33
"./core/access",
4+
"./var/document",
5+
"./var/documentElement",
46
"./css/var/rnumnonpx",
57
"./css/curCSS",
68
"./css/addGetHookIf",
@@ -9,9 +11,7 @@ define([
911
"./core/init",
1012
"./css",
1113
"./selector" // contains
12-
], function( jQuery, access, rnumnonpx, curCSS, addGetHookIf, support ) {
13-
14-
var docElem = window.document.documentElement;
14+
], function( jQuery, access, document, documentElement, rnumnonpx, curCSS, addGetHookIf, support ) {
1515

1616
/**
1717
* Gets a window from an element
@@ -145,14 +145,14 @@ jQuery.fn.extend({
145145

146146
offsetParent: function() {
147147
return this.map(function() {
148-
var offsetParent = this.offsetParent || docElem;
148+
var offsetParent = this.offsetParent || documentElement;
149149

150150
while ( offsetParent && ( !jQuery.nodeName( offsetParent, "html" ) &&
151151
jQuery.css( offsetParent, "position" ) === "static" ) ) {
152152
offsetParent = offsetParent.offsetParent;
153153
}
154154

155-
return offsetParent || docElem;
155+
return offsetParent || documentElement;
156156
});
157157
}
158158
});

‎src/selector-native.js

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
define([
2-
"./core"
3-
], function( jQuery ) {
2+
"./core",
3+
"./var/document",
4+
"./var/documentElement"
5+
], function( jQuery, document, documentElement ) {
46

57
/*
68
* Optional (non-Sizzle) selector module for custom builds.
@@ -28,12 +30,11 @@ define([
2830
*/
2931

3032
var hasDuplicate,
31-
docElem = window.document.documentElement,
32-
matches = docElem.matches ||
33-
docElem.webkitMatchesSelector ||
34-
docElem.mozMatchesSelector ||
35-
docElem.oMatchesSelector ||
36-
docElem.msMatchesSelector,
33+
matches = documentElement.matches ||
34+
documentElement.webkitMatchesSelector ||
35+
documentElement.mozMatchesSelector ||
36+
documentElement.oMatchesSelector ||
37+
documentElement.msMatchesSelector,
3738
sortOrder = function( a, b ) {
3839
// Flag for duplicate removal
3940
if ( a === b ) {

‎src/var/document.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
define(function() {
2+
return window.document;
3+
});

‎src/var/documentElement.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
define([
2+
"./document"
3+
], function( document ) {
4+
return document.documentElement;
5+
});

0 commit comments

Comments
 (0)