Skip to content

Commit

Permalink
Support when 1.8 in addition to when 2.0
Browse files Browse the repository at this point in the history
when 2.0 is perferred. Some unit test will fail with when 1.8, but the
code should be compatible. This change is mostly being made for
dependency resolution with libs that require when ~1.
  • Loading branch information
scothis committed Apr 30, 2013
1 parent 21a26cf commit 17c629f
Show file tree
Hide file tree
Showing 26 changed files with 434 additions and 425 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ Change Log

.next
- add Node 0.10 as a tested environment
- restore when 1.8 compat, when 2.0 is still preferred

0.9.0
- moving from the 's2js' to the 'cujojs' organization
Expand Down
2 changes: 1 addition & 1 deletion component.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"version": "0.9.0-next",
"main": "./rest.js",
"dependencies": {
"when": "~2"
"when": ">1.8.0 <=3.0.0"
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
}
],
"dependencies": {
"when": "~2"
"when": ">1.8.0 <=3.0.0"
},
"devDependencies": {
"wire": "~0.9",
Expand Down
34 changes: 18 additions & 16 deletions test/client/jsonp-test-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,56 +24,58 @@
rest = require('rest');

buster.testCase('rest/client/jsonp', {
'should make a GET by default': function (done) {
'should make a GET by default': function () {
var request = { path: 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0', params: { q: 'javascript' } };
client(request).then(function (response) {
return client(request).then(function (response) {
assert(response.entity.responseData);
assert.same(request, response.request);
refute(request.canceled);
refute(response.raw.parentNode);
}).otherwise(fail).ensure(done);
}).otherwise(fail);
},
'should use the jsonp client from the jsonp interceptor by default': function (done) {
'should use the jsonp client from the jsonp interceptor by default': function () {
var request = { path: 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0', params: { q: 'html5' } };
jsonpInterceptor()(request).then(function (response) {
return jsonpInterceptor()(request).then(function (response) {
assert(response.entity.responseData);
assert.same(request, response.request);
refute(request.canceled);
refute(response.raw.parentNode);
}).otherwise(fail).ensure(done);
}).otherwise(fail);
},
'should abort the request if canceled': function (done) {
var request = { path: 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0', params: { q: 'html5' } };
client(request).then(
'should abort the request if canceled': function () {
var request, response;
request = { path: 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0', params: { q: 'html5' } };
response = client(request).then(
fail,
failOnThrow(function (response) {
assert.same(request, response.request);
assert(request.canceled);
refute(response.raw.parentNode);
})
).ensure(done);
);
refute(request.canceled);
request.cancel();
return response;
},
'should propogate request errors': function (done) {
'should propogate request errors': function () {
var request = { path: 'http://localhost:1234' };
client(request).then(
return client(request).then(
fail,
failOnThrow(function (response) {
assert.same('loaderror', response.error);
})
).ensure(done);
);
},
'should not make a request that has already been canceled': function (done) {
'should not make a request that has already been canceled': function () {
var request = { canceled: true, path: 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0', params: { q: 'javascript' } };
client(request).then(
return client(request).then(
fail,
failOnThrow(function (response) {
assert.same(request, response.request);
assert(request.canceled);
assert.same('precanceled', response.error);
})
).ensure(done);
);
},
'should not be the default client': function () {
refute.same(client, rest);
Expand Down
44 changes: 23 additions & 21 deletions test/client/node-test-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@
server.close();
},

'should make a GET by default': function (done) {
'should make a GET by default': function () {
var request = { path: 'http://localhost:8080/' };
client(request).then(function (response) {
return client(request).then(function (response) {
assert(response.raw.request instanceof http.ClientRequest);
// assert(response.raw.response instanceof http.ClientResponse);
assert(response.raw.response);
Expand All @@ -64,69 +64,71 @@
assert.equals('text/plain', response.headers['Content-Type']);
assert.equals(response.entity.length, parseInt(response.headers['Content-Length'], 10));
refute(request.canceled);
}).otherwise(fail).ensure(done);
}).otherwise(fail);
},
'should make an explicit GET': function (done) {
'should make an explicit GET': function () {
var request = { path: 'http://localhost:8080/', method: 'GET' };
client(request).then(function (response) {
return client(request).then(function (response) {
assert.same(request, response.request);
assert.equals(response.request.method, 'GET');
assert.equals(response.entity, 'hello world');
assert.equals(response.status.code, 200);
refute(request.canceled);
}).otherwise(fail).ensure(done);
}).otherwise(fail);
},
'should make a POST with an entity': function (done) {
'should make a POST with an entity': function () {
var request = { path: 'http://localhost:8080/', entity: 'echo' };
client(request).then(function (response) {
return client(request).then(function (response) {
assert.same(request, response.request);
assert.equals(response.request.method, 'POST');
assert.equals(response.entity, 'echo');
assert.equals(response.status.code, 200);
assert.equals('text/plain', response.headers['Content-Type']);
assert.equals(response.entity.length, parseInt(response.headers['Content-Length'], 10));
refute(request.canceled);
}).otherwise(fail).ensure(done);
}).otherwise(fail);
},
'should make an explicit POST with an entity': function (done) {
'should make an explicit POST with an entity': function () {
var request = { path: 'http://localhost:8080/', entity: 'echo', method: 'POST' };
client(request).then(function (response) {
return client(request).then(function (response) {
assert.same(request, response.request);
assert.equals(response.request.method, 'POST');
assert.equals(response.entity, 'echo');
refute(request.canceled);
}).otherwise(fail).ensure(done);
}).otherwise(fail);
},
'should abort the request if canceled': function (done) {
var request = { path: 'http://localhost:8080/' };
'should abort the request if canceled': function () {
var request, response;
request = { path: 'http://localhost:8080/' };
client(request).then(
fail,
failOnThrow(function (/* response */) {
assert(request.canceled);
})
).ensure(done);
);
refute(request.canceled);
request.cancel();
return response;
},
'should propogate request errors': function (done) {
'should propogate request errors': function () {
var request = { path: 'http://localhost:1234' };
client(request).then(
return client(request).then(
fail,
failOnThrow(function (response) {
assert(response.error);
})
).ensure(done);
);
},
'should not make a request that has already been canceled': function (done) {
'should not make a request that has already been canceled': function () {
var request = { canceled: true, path: 'http://localhost:1234' };
client(request).then(
return client(request).then(
fail,
failOnThrow(function (response) {
assert.same(request, response.request);
assert(request.canceled);
assert.same('precanceled', response.error);
})
).ensure(done);
);
},
'should be the default client': function () {
assert.same(client, rest);
Expand Down
46 changes: 24 additions & 22 deletions test/client/xdr-test-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,80 +27,82 @@
buster.testCase('rest/client/xdr', {
'': {
requiresSupportFor: { xdr: 'XDomainRequest' in window },
'should make a GET by default': function (done) {
'should make a GET by default': function () {
var request = { path: flickrUrl };
client(request).then(function (response) {
return client(request).then(function (response) {
var xdr;
xdr = response.raw;
assert.same(request, response.request);
assert.equals(response.request.method, 'GET');
refute(request.canceled);
}).otherwise(fail).ensure(done);
}).otherwise(fail);
},
'should make an explicit GET': function (done) {
'should make an explicit GET': function () {
var request = { path: flickrUrl, method: 'GET' };
client(request).then(function (response) {
return client(request).then(function (response) {
var xdr;
xdr = response.raw;
assert.same(request, response.request);
assert.equals(response.request.method, 'GET');
assert.equals(xdr.responseText, response.entity);
refute(request.canceled);
}).otherwise(fail).ensure(done);
}).otherwise(fail);
},
'should make a POST with an entity': function (done) {
'should make a POST with an entity': function () {
var request = { path: flickrUrl, entity: 'hello world' };
client(request).then(function (response) {
return client(request).then(function (response) {
var xdr;
xdr = response.raw;
assert.same(request, response.request);
assert.equals(response.request.method, 'POST');
assert.equals(xdr.responseText, response.entity);
refute(request.canceled);
}).otherwise(fail).ensure(done);
}).otherwise(fail);
},
'should make an explicit POST with an entity': function (done) {
'should make an explicit POST with an entity': function () {
var request = { path: flickrUrl, entity: 'hello world', method: 'POST' };
client(request).then(function (response) {
return client(request).then(function (response) {
var xdr;
xdr = response.raw;
assert.same(request, response.request);
assert.equals(response.request.method, 'POST');
assert.equals(xdr.responseText, response.entity);
refute(request.canceled);
}).otherwise(fail).ensure(done);
}).otherwise(fail);
},
'should abort the request if canceled': function (done) {
'should abort the request if canceled': function () {
// TDOO find an endpoint that takes a bit to respond, cached files may return synchronously
var request = { path: flickrUrl, params: { q: Date.now() } };
client(request).then(
var request, response;
request = { path: flickrUrl, params: { q: Date.now() } };
response = client(request).then(
fail,
failOnThrow(function (response) {
assert(response.request.canceled);
})
).ensure(done);
);
refute(request.canceled);
request.cancel();
return response;
},
'should propogate request errors': function (done) {
'should propogate request errors': function () {
var request = { path: 'http://localhost:1234' };
client(request).then(
return client(request).then(
fail,
failOnThrow(function (response) {
assert.same('loaderror', response.error);
})
).ensure(done);
);
},
'should not make a request that has already been canceled': function (done) {
'should not make a request that has already been canceled': function () {
var request = { canceled: true, path: '/' };
client(request).then(
return client(request).then(
fail,
failOnThrow(function (response) {
assert.same(request, response.request);
assert(request.canceled);
assert.same('precanceled', response.error);
})
).ensure(done);
);
}
},
'should not be the default client': function () {
Expand Down
Loading

0 comments on commit 17c629f

Please sign in to comment.