Permalink
Browse files

Core: Support non-browser environments

Fixes gh-2133
Fixes gh-2501
Closes gh-2504
Refs gh-1950
Refs gh-1949
Refs gh-2397
Refs gh-1537
Refs gh-2504
Refs 842958e
  • Loading branch information...
mgol committed Jul 28, 2015
1 parent 9b04201 commit 04ec688e806660107a0b5823fabe2fe213f63b92
Showing with 363 additions and 68 deletions.
  1. +2 −0 .gitignore
  2. +2 −1 .jscsrc
  3. +1 −0 .jshintignore
  4. +14 −4 Gruntfile.js
  5. +27 −0 build/tasks/install_jsdom.js
  6. +16 −0 build/tasks/lib/spawn_test.js
  7. +32 −0 build/tasks/node_smoke_tests.js
  8. +13 −0 build/tasks/promises_aplus_tests.js
  9. +8 −1 package.json
  10. +2 −2 src/.jshintrc
  11. +5 −3 src/ajax.js
  12. +2 −2 src/ajax/parseXML.js
  13. +2 −1 src/ajax/script.js
  14. +3 −0 src/ajax/var/location.js
  15. +2 −1 src/ajax/xhr.js
  16. +14 −10 src/attributes/support.js
  17. +3 −1 src/core.js
  18. +2 −4 src/core/init.js
  19. +2 −1 src/core/parseHTML.js
  20. +4 −3 src/core/ready.js
  21. +2 −1 src/core/support.js
  22. +4 −3 src/css.js
  23. +3 −2 src/css/curCSS.js
  24. +11 −13 src/css/support.js
  25. +2 −1 src/data/support.js
  26. +1 −1 src/deferred.js
  27. +6 −4 src/effects.js
  28. +2 −1 src/event.js
  29. +2 −1 src/event/support.js
  30. +2 −1 src/manipulation.js
  31. +11 −3 src/manipulation/support.js
  32. +3 −1 src/offset.js
  33. +2 −2 src/queue/delay.js
  34. +3 −0 src/var/document.js
  35. +5 −0 src/var/documentElement.js
  36. +14 −0 test/node_smoke_tests/.jshintrc
  37. +11 −0 test/node_smoke_tests/document_missing.js
  38. +14 −0 test/node_smoke_tests/document_passed.js
  39. +17 −0 test/node_smoke_tests/document_present_originally.js
  40. +8 −0 test/node_smoke_tests/iterable_with_native_symbol.js
  41. +13 −0 test/node_smoke_tests/iterable_with_symbol_polyfill.js
  42. +15 −0 test/node_smoke_tests/lib/ensure_global_not_created.js
  43. +25 −0 test/node_smoke_tests/lib/ensure_iterability_es6.js
  44. +9 −0 test/node_smoke_tests/lib/ensure_jquery.js
  45. +22 −0 test/promises_aplus_adapter.js
View
@@ -10,3 +10,5 @@
/dist
/node_modules
/test/node_smoke_tests/lib/ensure_iterability.js
View
@@ -1,5 +1,6 @@
{
"preset": "jquery",
"excludeFiles": [ "external", "src/intro.js", "src/outro.js" ]
"excludeFiles": [ "external", "src/intro.js", "src/outro.js",
"test/node_smoke_tests/lib/ensure_iterability.js" ]
}
View
@@ -9,3 +9,4 @@ test/data/readywaitasset.js
test/data/readywaitloader.js
test/data/support/csp.js
test/data/support/getComputedSupport.js
test/node_smoke_tests/lib/ensure_iterability.js
View
@@ -34,6 +34,18 @@ module.exports = function( grunt ) {
cache: "build/.sizecache.json"
}
},
babel: {
options: {
sourceMap: "inline",
retainLines: true
},
nodeSmokeTests: {
files: {
"test/node_smoke_tests/lib/ensure_iterability.js":
"test/node_smoke_tests/lib/ensure_iterability_es6.js"
}
}
},
build: {
all: {
dest: "dist/jquery.js",
@@ -159,11 +171,9 @@ module.exports = function( grunt ) {
grunt.registerTask( "lint", [ "jsonlint", "jshint", "jscs" ] );
// Only defined for master at this time, but kept for cross-branch consistency
grunt.registerTask( "test_fast", [] );
grunt.registerTask( "test_fast", [ "node_smoke_tests" ] );
// gh-2133 TODO: cherry-pick 76df9e4e389d80bff410a9e5f08b848de1d21a2f for promises-aplus-tests
grunt.registerTask( "test", [ "test_fast"/*, "promises-aplus-tests"*/ ] );
grunt.registerTask( "test", [ "test_fast", "promises_aplus_tests" ] );
// Short list as a high frequency watch task
grunt.registerTask( "dev", [ "build:*:*", "lint", "uglify", "remove_map_comment", "dist:*" ] );
@@ -0,0 +1,27 @@
module.exports = function( grunt ) {
grunt.registerTask( "jsdom", function() {
var current,
pkg = grunt.config( "pkg" ),
version = pkg.jsdomVersions[
// Unfortunately, this is currently the only
// way to tell the difference between Node and iojs
/^v0/.test( process.version ) ? "node" : "iojs"
];
try {
current = require( "jsdom/package.json" ).version;
if ( current === version ) {
return;
}
} catch ( e ) {}
// Use npm on the command-line
// There is no local npm
grunt.util.spawn( {
cmd: "npm",
args: [ "install", "jsdom@" + version ],
opts: { stdio: "inherit" }
}, this.async() );
});
};
@@ -0,0 +1,16 @@
/* jshint node: true */
"use strict";
// Run Node with provided parameters: the first one being the Grunt
// done function and latter ones being files to be tested.
// See the comment in ../node_smoke_tests.js for more information.
module.exports = function spawnTest( done ) {
var testPaths = [].slice.call( arguments, 1 ),
spawn = require( "win-spawn" );
spawn( "node", testPaths, { stdio: "inherit" } )
.on( "close", function( code ) {
done( code === 0 );
} );
} ;
@@ -0,0 +1,32 @@
module.exports = function( grunt ) {
"use strict";
var fs = require( "fs" ),
spawnTest = require( "./lib/spawn_test.js" ),
testsDir = "./test/node_smoke_tests/",
nodeSmokeTests = [ "jsdom", "babel:nodeSmokeTests" ];
// Fire up all tests defined in test/node_smoke_tests/*.js in spawned sub-processes.
// All the files under test/node_smoke_tests/*.js are supposed to exit with 0 code
// on success or another one on failure. Spawning in sub-processes is
// important so that the tests & the main process don't interfere with
// each other, e.g. so that they don't share the require cache.
fs.readdirSync( testsDir )
.filter( function( testFilePath ) {
return fs.statSync( testsDir + testFilePath ).isFile() &&
/\.js$/.test( testFilePath );
} )
.forEach( function( testFilePath ) {
var taskName = "node_" + testFilePath.replace( /\.js$/, "" );
grunt.registerTask( taskName, function() {
spawnTest( this.async(), "test/node_smoke_tests/" + testFilePath );
} );
nodeSmokeTests.push( taskName );
} );
grunt.registerTask( "node_smoke_tests", nodeSmokeTests );
};
@@ -0,0 +1,13 @@
module.exports = function( grunt ) {
"use strict";
var spawnTest = require( "./lib/spawn_test.js" );
grunt.registerTask( "promises_aplus_tests", function() {
spawnTest( this.async(),
"./node_modules/.bin/promises-aplus-tests",
"test/promises_aplus_adapter.js"
);
} );
};
View
@@ -26,7 +26,9 @@
"dependencies": {},
"devDependencies": {
"commitplease": "2.0.0",
"core-js": "0.9.17",
"grunt": "0.4.5",
"grunt-babel": "5.0.1",
"grunt-cli": "0.1.13",
"grunt-compare-size": "0.4.0",
"grunt-contrib-jshint": "0.11.2",
@@ -46,7 +48,12 @@
"sinon": "1.12.2",
"sizzle": "2.2.0",
"strip-json-comments": "1.0.3",
"testswarm": "1.1.0"
"testswarm": "1.1.0",
"win-spawn": "2.0.0"
},
"jsdomVersions": {
"node": "3.1.2",
"iojs": "5.3.0"
},
"scripts": {
"build": "npm install && grunt",
View
@@ -16,11 +16,11 @@
// The above browsers are failing a lot of tests in the ES5
// test suite at http://test262.ecmascript.org.
"es3": true,
"browser": true,
"wsh": true,
"globals": {
"window": true,
"JSON": false,
"jQuery": true,
"define": false,
"module": false,
View
@@ -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 = /#.*$/,
@@ -643,7 +645,7 @@ jQuery.extend({
// Timeout
if ( s.async && s.timeout > 0 ) {
timeoutTimer = setTimeout(function() {
timeoutTimer = window.setTimeout(function() {
jqXHR.abort("timeout");
}, s.timeout );
}
@@ -677,7 +679,7 @@ jQuery.extend({
// Clear timeout if it exists
if ( timeoutTimer ) {
clearTimeout( timeoutTimer );
window.clearTimeout( timeoutTimer );
}
// Dereference transport for early garbage collection
View
@@ -10,10 +10,10 @@ jQuery.parseXML = function( data ) {
}
try {
if ( window.DOMParser ) { // Standard
tmp = new DOMParser();
tmp = new window.DOMParser();
xml = tmp.parseFromString( data, "text/xml" );
} else { // IE
xml = new ActiveXObject( "Microsoft.XMLDOM" );
xml = new window.ActiveXObject( "Microsoft.XMLDOM" );
xml.async = "false";
xml.loadXML( data );
}
View
@@ -1,7 +1,8 @@
define([
"../core",
"../var/document",
"../ajax"
], function( jQuery ) {
], function( jQuery, document ) {
// Install script dataType
jQuery.ajaxSetup({
View
@@ -0,0 +1,3 @@
define(function() {
return window.location;
});
View
@@ -1,8 +1,9 @@
define([
"../core",
"../var/document",
"../var/support",
"../ajax"
], function( jQuery, support ) {
], function( jQuery, document, support ) {
// Create the request object
// (This is still attached to ajaxSettings for backward compatibility)
View
@@ -1,21 +1,25 @@
define([
"../var/document",
"../var/support"
], function( support ) {
], function( document, support ) {
(function() {
// Minified: var a,b,c,d,e
var input, div, select, a, opt;
var a,
input = document.createElement( "input" ),
div = document.createElement( "div" ),
select = document.createElement( "select" ),
opt = select.appendChild( document.createElement( "option" ) );
// Setup
div = document.createElement( "div" );
div.innerHTML = " <link/><a href='/a'>a</a><input type='checkbox'/>";
a = div.getElementsByTagName("a")[ 0 ];
div.innerHTML = " <link/><a href='/a'>a</a>";
// Support: Windows Web Apps (WWA)
// `type` must use .setAttribute for WWA (#14901)
input.setAttribute( "type", "checkbox" );
div.appendChild( input );
// First batch of tests.
select = document.createElement("select");
opt = select.appendChild( document.createElement("option") );
input = div.getElementsByTagName("input")[ 0 ];
a = div.getElementsByTagName( "a" )[ 0 ];
// First batch of tests.
a.style.cssText = "top:1px";
// Get the style information from getAttribute
View
@@ -1,5 +1,6 @@
define([
"./var/deletedIds",
"./var/document",
"./var/slice",
"./var/concat",
"./var/push",
@@ -8,7 +9,8 @@ define([
"./var/toString",
"./var/hasOwn",
"./var/support"
], function( deletedIds, slice, concat, push, indexOf, class2type, toString, hasOwn, support ) {
], function( deletedIds, document, slice, concat, push, indexOf,
class2type, toString, hasOwn, support ) {
var
version = "@VERSION+compat",
View
@@ -1,16 +1,14 @@
// 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,
// Use the correct document accordingly with window argument (sandbox)
document = window.document,
// A simple way to check for HTML strings
// Prioritize #id over <tag> to avoid XSS via location.hash (#9521)
// Strict HTML recognition (#11290: must start with <)
View
@@ -1,11 +1,12 @@
define([
"../core",
"../var/document",
"./var/rsingleTag",
"../manipulation/buildFragment",
// This is the only module that needs core/support
"./support"
], function( jQuery, rsingleTag, buildFragment, support ) {
], function( jQuery, document, rsingleTag, buildFragment, support ) {
// data: string of html
// context (optional): If specified, the fragment will be created in this context,
View
@@ -1,7 +1,8 @@
define([
"../core",
"../var/document",
"../deferred"
], function( jQuery ) {
], function( jQuery, document ) {
// The deferred used on DOM ready
var readyList;
@@ -72,7 +73,7 @@ function detach() {
function completed() {
// readyState === "complete" is good enough for us to call the dom ready in oldIE
if ( document.addEventListener ||
event.type === "load" ||
window.event.type === "load" ||
document.readyState === "complete" ) {
detach();
@@ -93,7 +94,7 @@ jQuery.ready.promise = function( obj ) {
// http://bugs.jquery.com/ticket/12282#comment:15
if ( document.readyState === "complete" ) {
// Handle it asynchronously to allow scripts the opportunity to delay ready
setTimeout( jQuery.ready );
window.setTimeout( jQuery.ready );
// Standards-based browsers support DOMContentLoaded
} else if ( document.addEventListener ) {
View
@@ -1,6 +1,7 @@
define([
"../var/document",
"../var/support"
], function( support ) {
], function( document, support ) {
// Support: Safari 8+
// In Safari 8 documents created via document.implementation.createHTMLDocument
Oops, something went wrong.

0 comments on commit 04ec688

Please sign in to comment.