aboutsummaryrefslogtreecommitdiffstats
path: root/build
diff options
context:
space:
mode:
authorMichał Gołębiowski <m.goleb@gmail.com>2015-07-28 12:58:44 +0200
committerMichał Gołębiowski <m.goleb@gmail.com>2015-08-16 22:29:42 +0200
commit04ec688e806660107a0b5823fabe2fe213f63b92 (patch)
tree5d5274314b342459d3cf6de70438b1d1d15ebda5 /build
parent9b04201ff21b6e5932dc21679774f398d6940cfa (diff)
downloadjquery-04ec688e806660107a0b5823fabe2fe213f63b92.tar.gz
jquery-04ec688e806660107a0b5823fabe2fe213f63b92.zip
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 842958e7aecd0d75a7ee9e2aaec83457701aa2f3
Diffstat (limited to 'build')
-rw-r--r--build/tasks/install_jsdom.js27
-rw-r--r--build/tasks/lib/spawn_test.js16
-rw-r--r--build/tasks/node_smoke_tests.js32
-rw-r--r--build/tasks/promises_aplus_tests.js13
4 files changed, 88 insertions, 0 deletions
diff --git a/build/tasks/install_jsdom.js b/build/tasks/install_jsdom.js
new file mode 100644
index 000000000..21d67eb0e
--- /dev/null
+++ b/build/tasks/install_jsdom.js
@@ -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() );
+ });
+};
diff --git a/build/tasks/lib/spawn_test.js b/build/tasks/lib/spawn_test.js
new file mode 100644
index 000000000..6c4596a3d
--- /dev/null
+++ b/build/tasks/lib/spawn_test.js
@@ -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 );
+ } );
+} ;
diff --git a/build/tasks/node_smoke_tests.js b/build/tasks/node_smoke_tests.js
new file mode 100644
index 000000000..9334516d9
--- /dev/null
+++ b/build/tasks/node_smoke_tests.js
@@ -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 );
+};
diff --git a/build/tasks/promises_aplus_tests.js b/build/tasks/promises_aplus_tests.js
new file mode 100644
index 000000000..3e770a079
--- /dev/null
+++ b/build/tasks/promises_aplus_tests.js
@@ -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"
+ );
+ } );
+};