Skip to content

Commit 04ec688

Browse files
committed
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
1 parent 9b04201 commit 04ec688

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+363
-68
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@
1010

1111
/dist
1212
/node_modules
13+
14+
/test/node_smoke_tests/lib/ensure_iterability.js

.jscsrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"preset": "jquery",
33

4-
"excludeFiles": [ "external", "src/intro.js", "src/outro.js" ]
4+
"excludeFiles": [ "external", "src/intro.js", "src/outro.js",
5+
"test/node_smoke_tests/lib/ensure_iterability.js" ]
56
}

.jshintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ test/data/readywaitasset.js
99
test/data/readywaitloader.js
1010
test/data/support/csp.js
1111
test/data/support/getComputedSupport.js
12+
test/node_smoke_tests/lib/ensure_iterability.js

Gruntfile.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,18 @@ module.exports = function( grunt ) {
3434
cache: "build/.sizecache.json"
3535
}
3636
},
37+
babel: {
38+
options: {
39+
sourceMap: "inline",
40+
retainLines: true
41+
},
42+
nodeSmokeTests: {
43+
files: {
44+
"test/node_smoke_tests/lib/ensure_iterability.js":
45+
"test/node_smoke_tests/lib/ensure_iterability_es6.js"
46+
}
47+
}
48+
},
3749
build: {
3850
all: {
3951
dest: "dist/jquery.js",
@@ -159,11 +171,9 @@ module.exports = function( grunt ) {
159171

160172
grunt.registerTask( "lint", [ "jsonlint", "jshint", "jscs" ] );
161173

162-
// Only defined for master at this time, but kept for cross-branch consistency
163-
grunt.registerTask( "test_fast", [] );
174+
grunt.registerTask( "test_fast", [ "node_smoke_tests" ] );
164175

165-
// gh-2133 TODO: cherry-pick 76df9e4e389d80bff410a9e5f08b848de1d21a2f for promises-aplus-tests
166-
grunt.registerTask( "test", [ "test_fast"/*, "promises-aplus-tests"*/ ] );
176+
grunt.registerTask( "test", [ "test_fast", "promises_aplus_tests" ] );
167177

168178
// Short list as a high frequency watch task
169179
grunt.registerTask( "dev", [ "build:*:*", "lint", "uglify", "remove_map_comment", "dist:*" ] );

build/tasks/install_jsdom.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
module.exports = function( grunt ) {
2+
grunt.registerTask( "jsdom", function() {
3+
var current,
4+
pkg = grunt.config( "pkg" ),
5+
version = pkg.jsdomVersions[
6+
7+
// Unfortunately, this is currently the only
8+
// way to tell the difference between Node and iojs
9+
/^v0/.test( process.version ) ? "node" : "iojs"
10+
];
11+
12+
try {
13+
current = require( "jsdom/package.json" ).version;
14+
if ( current === version ) {
15+
return;
16+
}
17+
} catch ( e ) {}
18+
19+
// Use npm on the command-line
20+
// There is no local npm
21+
grunt.util.spawn( {
22+
cmd: "npm",
23+
args: [ "install", "jsdom@" + version ],
24+
opts: { stdio: "inherit" }
25+
}, this.async() );
26+
});
27+
};

build/tasks/lib/spawn_test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/* jshint node: true */
2+
3+
"use strict";
4+
5+
// Run Node with provided parameters: the first one being the Grunt
6+
// done function and latter ones being files to be tested.
7+
// See the comment in ../node_smoke_tests.js for more information.
8+
module.exports = function spawnTest( done ) {
9+
var testPaths = [].slice.call( arguments, 1 ),
10+
spawn = require( "win-spawn" );
11+
12+
spawn( "node", testPaths, { stdio: "inherit" } )
13+
.on( "close", function( code ) {
14+
done( code === 0 );
15+
} );
16+
} ;

build/tasks/node_smoke_tests.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
module.exports = function( grunt ) {
2+
3+
"use strict";
4+
5+
var fs = require( "fs" ),
6+
spawnTest = require( "./lib/spawn_test.js" ),
7+
testsDir = "./test/node_smoke_tests/",
8+
nodeSmokeTests = [ "jsdom", "babel:nodeSmokeTests" ];
9+
10+
// Fire up all tests defined in test/node_smoke_tests/*.js in spawned sub-processes.
11+
// All the files under test/node_smoke_tests/*.js are supposed to exit with 0 code
12+
// on success or another one on failure. Spawning in sub-processes is
13+
// important so that the tests & the main process don't interfere with
14+
// each other, e.g. so that they don't share the require cache.
15+
16+
fs.readdirSync( testsDir )
17+
.filter( function( testFilePath ) {
18+
return fs.statSync( testsDir + testFilePath ).isFile() &&
19+
/\.js$/.test( testFilePath );
20+
} )
21+
.forEach( function( testFilePath ) {
22+
var taskName = "node_" + testFilePath.replace( /\.js$/, "" );
23+
24+
grunt.registerTask( taskName, function() {
25+
spawnTest( this.async(), "test/node_smoke_tests/" + testFilePath );
26+
} );
27+
28+
nodeSmokeTests.push( taskName );
29+
} );
30+
31+
grunt.registerTask( "node_smoke_tests", nodeSmokeTests );
32+
};
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module.exports = function( grunt ) {
2+
3+
"use strict";
4+
5+
var spawnTest = require( "./lib/spawn_test.js" );
6+
7+
grunt.registerTask( "promises_aplus_tests", function() {
8+
spawnTest( this.async(),
9+
"./node_modules/.bin/promises-aplus-tests",
10+
"test/promises_aplus_adapter.js"
11+
);
12+
} );
13+
};

package.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@
2626
"dependencies": {},
2727
"devDependencies": {
2828
"commitplease": "2.0.0",
29+
"core-js": "0.9.17",
2930
"grunt": "0.4.5",
31+
"grunt-babel": "5.0.1",
3032
"grunt-cli": "0.1.13",
3133
"grunt-compare-size": "0.4.0",
3234
"grunt-contrib-jshint": "0.11.2",
@@ -46,7 +48,12 @@
4648
"sinon": "1.12.2",
4749
"sizzle": "2.2.0",
4850
"strip-json-comments": "1.0.3",
49-
"testswarm": "1.1.0"
51+
"testswarm": "1.1.0",
52+
"win-spawn": "2.0.0"
53+
},
54+
"jsdomVersions": {
55+
"node": "3.1.2",
56+
"iojs": "5.3.0"
5057
},
5158
"scripts": {
5259
"build": "npm install && grunt",

src/.jshintrc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
// The above browsers are failing a lot of tests in the ES5
1717
// test suite at http://test262.ecmascript.org.
1818
"es3": true,
19-
"browser": true,
20-
"wsh": true,
2119

2220
"globals": {
21+
"window": true,
2322
"JSON": false,
23+
2424
"jQuery": true,
2525
"define": false,
2626
"module": false,

0 commit comments

Comments
 (0)