Skip to content

Commit e1303a3

Browse files
committed
Deferred: Run the Promises/A+ test suite
To run tests, invoke `grunt default promises-aplus-tests`.
1 parent b677541 commit e1303a3

File tree

4 files changed

+37
-1
lines changed

4 files changed

+37
-1
lines changed

Gruntfile.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ module.exports = function( grunt ) {
1010
}
1111

1212
var gzip = require( "gzip-js" ),
13+
spawn = require( "child_process" ).spawn,
1314
srcHintOptions = readOptionalJSON( "src/.jshintrc" );
1415

1516
// The concatenated file won't pass onevar
@@ -160,6 +161,18 @@ module.exports = function( grunt ) {
160161

161162
grunt.registerTask( "lint", [ "jshint", "jscs" ] );
162163

164+
grunt.registerTask( "promises-aplus-tests", function() {
165+
var done = this.async();
166+
spawn( "node", [
167+
"./node_modules/.bin/promises-aplus-tests",
168+
"./promises-aplus-adapter.js"
169+
], {
170+
stdio: "inherit"
171+
}).on( "close", function( code ) {
172+
done( code === 0 );
173+
});
174+
});
175+
163176
// Short list as a high frequency watch task
164177
grunt.registerTask( "dev", [ "build:*:*", "lint" ] );
165178

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,10 @@
4343
"grunt-jsonlint": "1.0.4",
4444
"grunt-npmcopy": "0.1.0",
4545
"gzip-js": "0.3.2",
46+
"jsdom": "1.0.0-pre.6",
4647
"load-grunt-tasks": "0.6.0",
4748
"npm": "1.4.21",
49+
"promises-aplus-tests": "2.0.5",
4850
"q": "1.0.1",
4951
"qunitjs": "1.14.0",
5052
"requirejs": "2.1.14",

promises-aplus-adapter.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"use strict";
2+
3+
require( "jsdom" ).env( "", function (errors, window) {
4+
if (errors) {
5+
console.error(errors);
6+
return;
7+
}
8+
var jQuery = require( "./" )( window );
9+
10+
exports.deferred = function () {
11+
var deferred = jQuery.Deferred();
12+
13+
return {
14+
get promise() {
15+
return deferred.promise();
16+
},
17+
resolve: deferred.resolve.bind(deferred),
18+
reject: deferred.reject.bind(deferred)
19+
};
20+
};
21+
});

src/ajax.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ var
4141
allTypes = "*/".concat( "*" ),
4242

4343
// Document location
44-
ajaxLocation = location.href,
44+
ajaxLocation = window.location.href,
4545

4646
// Segment location into parts
4747
ajaxLocParts = rurl.exec( ajaxLocation.toLowerCase() ) || [];

0 commit comments

Comments
 (0)