From 17c629f12a86bb9606d8de26a7d2d87750d25025 Mon Sep 17 00:00:00 2001 From: Scott Andrews Date: Tue, 30 Apr 2013 16:07:31 -0400 Subject: [PATCH] Support when 1.8 in addition to when 2.0 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. --- README.md | 1 + component.json | 2 +- package.json | 2 +- test/client/jsonp-test-browser.js | 34 ++--- test/client/node-test-node.js | 44 +++--- test/client/xdr-test-browser.js | 46 +++--- test/client/xhr-test-browser.js | 44 +++--- test/dojo/RestStore-test-browser.js | 60 ++++---- test/dojo/wire-test-browser.js | 18 +-- test/interceptor-test.js | 150 ++++++++++---------- test/interceptor/basicAuth-test.js | 18 +-- test/interceptor/defaultRequest-test.js | 66 ++++----- test/interceptor/entity-test.js | 12 +- test/interceptor/errorCode-test.js | 18 +-- test/interceptor/hateoas-test.js | 24 ++-- test/interceptor/ie/xdomain-test-browser.js | 24 ++-- test/interceptor/ie/xhr-test-browser.js | 12 +- test/interceptor/jsonp-test.js | 12 +- test/interceptor/location-test.js | 12 +- test/interceptor/mime-test.js | 42 +++--- test/interceptor/oAuth-test.js | 12 +- test/interceptor/pathPrefix-test.js | 24 ++-- test/interceptor/retry-test.js | 23 +-- test/interceptor/timeout-test.js | 45 +++--- test/mime/registry-test.js | 36 ++--- test/wire-test.js | 78 +++++----- 26 files changed, 434 insertions(+), 425 deletions(-) diff --git a/README.md b/README.md index f37c36b..c30d222 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/component.json b/component.json index f0957dc..2298fed 100644 --- a/component.json +++ b/component.json @@ -3,6 +3,6 @@ "version": "0.9.0-next", "main": "./rest.js", "dependencies": { - "when": "~2" + "when": ">1.8.0 <=3.0.0" } } diff --git a/package.json b/package.json index d4eb1cd..c75c291 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ } ], "dependencies": { - "when": "~2" + "when": ">1.8.0 <=3.0.0" }, "devDependencies": { "wire": "~0.9", diff --git a/test/client/jsonp-test-browser.js b/test/client/jsonp-test-browser.js index b29afae..4f9622a 100644 --- a/test/client/jsonp-test-browser.js +++ b/test/client/jsonp-test-browser.js @@ -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); diff --git a/test/client/node-test-node.js b/test/client/node-test-node.js index fa2c13c..b459b0a 100644 --- a/test/client/node-test-node.js +++ b/test/client/node-test-node.js @@ -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); @@ -64,21 +64,21 @@ 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'); @@ -86,47 +86,49 @@ 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); diff --git a/test/client/xdr-test-browser.js b/test/client/xdr-test-browser.js index 8fb705a..dfbb183 100644 --- a/test/client/xdr-test-browser.js +++ b/test/client/xdr-test-browser.js @@ -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 () { diff --git a/test/client/xhr-test-browser.js b/test/client/xhr-test-browser.js index 6ef8f77..a15e7bd 100644 --- a/test/client/xhr-test-browser.js +++ b/test/client/xhr-test-browser.js @@ -28,9 +28,9 @@ client = !XMLHttpRequest ? xhr.chain(xhrFallback) : xhr; buster.testCase('rest/client/xhr', { - 'should make a GET by default': function (done) { + 'should make a GET by default': function () { var request = { path: '/' }; - client(request).then(function (response) { + return client(request).then(function (response) { var xhr, name; xhr = response.raw; assert.same(request, response.request); @@ -43,11 +43,11 @@ assert.equals(xhr.getResponseHeader(name), response.headers[name]); } 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: '/', method: 'GET' }; - client(request).then(function (response) { + return client(request).then(function (response) { var xhr, name; xhr = response.raw; assert.same(request, response.request); @@ -60,11 +60,11 @@ assert.equals(xhr.getResponseHeader(name), response.headers[name]); } 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: '/', entity: 'hello world' }; - client(request).then(function (response) { + return client(request).then(function (response) { var xhr, name; xhr = response.raw; assert.same(request, response.request); @@ -77,11 +77,11 @@ assert.equals(xhr.getResponseHeader(name), response.headers[name]); } 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: '/', entity: 'hello world', method: 'POST' }; - client(request).then(function (response) { + return client(request).then(function (response) { var xhr, name; xhr = response.raw; assert.same(request, response.request); @@ -94,7 +94,7 @@ assert.equals(xhr.getResponseHeader(name), response.headers[name]); } refute(request.canceled); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, 'should abort the request if canceled': function (done) { // TDOO find an endpoint that takes a bit to respond, cached files may return synchronously @@ -122,41 +122,41 @@ refute(request.canceled); request.cancel(); }) - ]).ensure(done); + ]).always(done); }, - '//should propogate request errors': function (done) { + '//should propogate request errors': function () { // TODO follow up with Sauce Labs // this test is valid, but fails with sauce as their proxy returns a 400 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 reject if an XHR impl is not available': { requiresSupportFor: { 'no-xhr': !window.XMLHttpRequest }, - '': function (done) { + '': function () { var request = { path: '/' }; - xhr(request).then( + return xhr(request).then( fail, failOnThrow(function (response) { assert.same(request, response.request); assert.same('xhr-not-available', response.error); }) - ).ensure(done); + ); } }, 'should be the default client': function () { diff --git a/test/dojo/RestStore-test-browser.js b/test/dojo/RestStore-test-browser.js index 64c2a36..39ada7c 100644 --- a/test/dojo/RestStore-test-browser.js +++ b/test/dojo/RestStore-test-browser.js @@ -39,89 +39,89 @@ assert.equals('key', store.idProperty); assert.equals(42, store.getIdentity({ key: 42 })); }, - 'should apply query params to the query string': function (done) { + 'should apply query params to the query string': function () { var store = new RestStore({ client: client }); - store.query({ q: 'what is the meaning of life?' }).then(function (response) { + return store.query({ q: 'what is the meaning of life?' }).then(function (response) { assert.equals('what is the meaning of life?', response.request.params.q); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, - 'should get based on the id': function (done) { + 'should get based on the id': function () { var store = new RestStore({ client: client }); - store.get(42).then(function (response) { + return store.get(42).then(function (response) { assert.equals('42', response.request.path); refute(response.request.method); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, - 'should remove based on the id': function (done) { + 'should remove based on the id': function () { var store = new RestStore({ client: client }); - store.remove(42).then(function (response) { + return store.remove(42).then(function (response) { assert.equals('42', response.request.path); assert.equals('delete', response.request.method); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, - 'should add a record without an ID': function (done) { + 'should add a record without an ID': function () { var store = new RestStore({ client: client }); - store.add({ foo: 'bar' }).then(function (response) { + return store.add({ foo: 'bar' }).then(function (response) { assert.equals('', response.request.path); assert.equals('post', response.request.method); assert.equals('*', response.request.headers['If-None-Match']); assert.equals('bar', response.request.entity.foo); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, - 'should add a record with an explicit ID': function (done) { + 'should add a record with an explicit ID': function () { var store = new RestStore({ client: client }); - store.add({ foo: 'bar' }, { id: 42 }).then(function (response) { + return store.add({ foo: 'bar' }, { id: 42 }).then(function (response) { assert.equals('42', response.request.path); assert.equals('put', response.request.method); assert.equals('*', response.request.headers['If-None-Match']); assert.equals('bar', response.request.entity.foo); refute.equals('42', response.request.entity.id); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, - 'should add a record with an implicit ID': function (done) { + 'should add a record with an implicit ID': function () { var store = new RestStore({ client: client }); - store.add({ foo: 'bar', id: 42 }).then(function (response) { + return store.add({ foo: 'bar', id: 42 }).then(function (response) { assert.equals('42', response.request.path); assert.equals('put', response.request.method); assert.equals('*', response.request.headers['If-None-Match']); assert.equals('bar', response.request.entity.foo); assert.equals('42', response.request.entity.id); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, - 'should add a record ignoring the ID': function (done) { + 'should add a record ignoring the ID': function () { var store = new RestStore({ client: client, ignoreId: true }); - store.add({ foo: 'bar', id: 42 }).then(function (response) { + return store.add({ foo: 'bar', id: 42 }).then(function (response) { assert.equals('', response.request.path); assert.equals('post', response.request.method); assert.equals('*', response.request.headers['If-None-Match']); assert.equals('bar', response.request.entity.foo); assert.equals('42', response.request.entity.id); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, - 'should put overwriting target': function (done) { + 'should put overwriting target': function () { var store = new RestStore({ client: client }); - store.put({ foo: 'bar', id: 42 }, { overwrite: true }).then(function (response) { + return store.put({ foo: 'bar', id: 42 }, { overwrite: true }).then(function (response) { assert.equals('42', response.request.path); assert.equals('put', response.request.method); assert.equals('*', response.request.headers['If-Match']); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, - 'should put without overwriting target': function (done) { + 'should put without overwriting target': function () { var store = new RestStore({ client: client }); - store.put({ foo: 'bar', id: 42 }, { overwrite: false }).then(function (response) { + return store.put({ foo: 'bar', id: 42 }, { overwrite: false }).then(function (response) { assert.equals('42', response.request.path); assert.equals('put', response.request.method); assert.equals('*', response.request.headers['If-None-Match']); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, - 'should put with default config': function (done) { + 'should put with default config': function () { var store = new RestStore({ client: client }); - store.put({ foo: 'bar', id: 42 }).then(function (response) { + return store.put({ foo: 'bar', id: 42 }).then(function (response) { assert.equals('42', response.request.path); assert.equals('put', response.request.method); refute(response.request.headers['If-None-Match']); refute(response.request.headers['If-Match']); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, 'should have a proper prototype chain': function () { assert(new RestStore() instanceof RestStore); diff --git a/test/dojo/wire-test-browser.js b/test/dojo/wire-test-browser.js index 9ae68f1..d1ce3d0 100644 --- a/test/dojo/wire-test-browser.js +++ b/test/dojo/wire-test-browser.js @@ -35,38 +35,38 @@ } buster.testCase('rest/dojo/wire', { - 'should create a RestStore for resource!': function (done) { + 'should create a RestStore for resource!': function () { var spec; spec = { store: { $ref: 'resource!', client: client }, plugins: [{ module: 'rest/dojo/wire' }] }; - wire(spec).then(function (spec) { + return wire(spec).then(function (spec) { assert(spec.store instanceof RestStore); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, - 'should get with resource! waiting for data': function (done) { + 'should get with resource! waiting for data': function () { var spec; spec = { resource: { $ref: 'resource!test/dojo', get: 'hello.json', entity: false, client: client }, plugins: [{ module: 'rest/dojo/wire' }] }; - wire(spec).then(function (spec) { + return wire(spec).then(function (spec) { assert.equals('bar', spec.resource.entity.foo); assert.equals('test/dojo/hello.json', spec.resource.request.path); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, - 'should support client!': function (done) { + 'should support client!': function () { var spec; spec = { client: { $ref: 'client!', client: client }, plugins: [{ module: 'rest/dojo/wire' }] }; - wire(spec).then(function (spec) { + return wire(spec).then(function (spec) { return spec.client({}).then(function (response) { assert.equals('bar', response.foo); }); - }).otherwise(fail).ensure(done); + }).otherwise(fail); } }); diff --git a/test/interceptor-test.js b/test/interceptor-test.js index 109941e..6e8ec97 100644 --- a/test/interceptor-test.js +++ b/test/interceptor-test.js @@ -42,38 +42,38 @@ } buster.testCase('rest/interceptor', { - 'should set the originator client on the request for the, but do not overwrite': function (done) { + 'should set the originator client on the request for the, but do not overwrite': function () { var theInterceptor, client; theInterceptor = interceptor(); client = theInterceptor(defaultClient).chain(theInterceptor); - client().then(function (response) { + return client().then(function (response) { assert.same('default', response.id); assert.same(client, response.request.originator); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, - 'should use the client configured into the interceptor by default': function (done) { + 'should use the client configured into the interceptor by default': function () { var theInterceptor, client; theInterceptor = interceptor({ client: defaultClient }); client = theInterceptor(); - client().then(function (response) { + return client().then(function (response) { assert.same('default', response.id); assert.same(client, response.request.originator); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, - 'should override the client configured into the interceptor by default': function (done) { + 'should override the client configured into the interceptor by default': function () { var theInterceptor, client; theInterceptor = interceptor({ client: defaultClient }); client = theInterceptor(otherClient); - client().then(function (response) { + return client().then(function (response) { assert.same('other', response.id); assert.same(client, response.request.originator); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, - 'should intercept the request phase': function (done) { + 'should intercept the request phase': function () { var theInterceptor, client; theInterceptor = interceptor({ request: function (request) { @@ -82,11 +82,11 @@ } }); client = theInterceptor(defaultClient); - client().then(function (response) { + return client().then(function (response) { assert.same('request', response.request.phase); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, - 'should intercept the request phase and handle a promise': function (done) { + 'should intercept the request phase and handle a promise': function () { var theInterceptor, client; theInterceptor = interceptor({ request: function (request) { @@ -97,12 +97,12 @@ } }); client = theInterceptor(defaultClient); - client().then(function (response) { + return client().then(function (response) { assert.same('default', response.id); assert.same('request', response.request.phase); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, - 'should intercept the request phase and handle a rejected promise': function (done) { + 'should intercept the request phase and handle a rejected promise': function () { var theInterceptor, client; theInterceptor = interceptor({ request: function (request) { @@ -111,7 +111,7 @@ } }); client = theInterceptor(defaultClient); - client().then( + return client().then( fail, failOnThrow(function (response) { // request never makes it to the root client @@ -119,9 +119,9 @@ assert.same('request', response.request.phase); assert.same('rejected request', response.error); }) - ).ensure(done); + ); }, - 'should intercept the response phase': function (done) { + 'should intercept the response phase': function () { var theInterceptor, client; theInterceptor = interceptor({ response: function (response) { @@ -130,11 +130,11 @@ } }); client = theInterceptor(defaultClient); - client().then(function (response) { + return client().then(function (response) { assert.same('response', response.phase); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, - 'should intercept the response phase and handle a promise': function (done) { + 'should intercept the response phase and handle a promise': function () { var theInterceptor, client; theInterceptor = interceptor({ response: function (response) { @@ -145,11 +145,11 @@ } }); client = theInterceptor(defaultClient); - client().then(function (response) { + return client().then(function (response) { assert.same('response', response.phase); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, - 'should intercept the response phase and handle a rejceted promise': function (done) { + 'should intercept the response phase and handle a rejceted promise': function () { var theInterceptor, client; theInterceptor = interceptor({ response: function (response) { @@ -158,14 +158,14 @@ } }); client = theInterceptor(defaultClient); - client().then( + return client().then( fail, failOnThrow(function (response) { assert.same('response', response.phase); }) - ).ensure(done); + ); }, - 'should intercept the response phase for an error': function (done) { + 'should intercept the response phase for an error': function () { var theInterceptor, client; theInterceptor = interceptor({ response: function (response) { @@ -174,14 +174,14 @@ } }); client = theInterceptor(errorClient); - client().then( + return client().then( fail, failOnThrow(function (response) { assert.same('response', response.phase); }) - ).ensure(done); + ); }, - 'should intercept the response phase for an error and handle a promise maintaining the error': function (done) { + 'should intercept the response phase for an error and handle a promise maintaining the error': function () { var theInterceptor, client; theInterceptor = interceptor({ response: function (response) { @@ -190,14 +190,14 @@ } }); client = theInterceptor(errorClient); - client().then( + return client().then( fail, failOnThrow(function (response) { assert.same('response', response.phase); }) - ).ensure(done); + ); }, - 'should intercept the response phase for an error and handle a rejected promise maintaining the error': function (done) { + 'should intercept the response phase for an error and handle a rejected promise maintaining the error': function () { var theInterceptor, client; theInterceptor = interceptor({ response: function (response) { @@ -206,14 +206,14 @@ } }); client = theInterceptor(errorClient); - client().then( + return client().then( fail, failOnThrow(function (response) { assert.same('response', response.phase); }) - ).ensure(done); + ); }, - 'should intercept the success phase': function (done) { + 'should intercept the success phase': function () { var theInterceptor, client; theInterceptor = interceptor({ response: fail, @@ -223,11 +223,11 @@ } }); client = theInterceptor(defaultClient); - client().then(function (response) { + return client().then(function (response) { assert.same('success', response.phase); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, - 'should intercept the success phase and handle a promise': function (done) { + 'should intercept the success phase and handle a promise': function () { var theInterceptor, client; theInterceptor = interceptor({ response: fail, @@ -239,11 +239,11 @@ } }); client = theInterceptor(defaultClient); - client().then(function (response) { + return client().then(function (response) { assert.same('success', response.phase); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, - 'should intercept the success phase and handle a rejceted promise': function (done) { + 'should intercept the success phase and handle a rejceted promise': function () { var theInterceptor, client; theInterceptor = interceptor({ response: fail, @@ -253,14 +253,14 @@ } }); client = theInterceptor(defaultClient); - client().then( + return client().then( fail, failOnThrow(function (response) { assert.same('success', response.phase); }) - ).ensure(done); + ); }, - 'should intercept the error phase': function (done) { + 'should intercept the error phase': function () { var theInterceptor, client; theInterceptor = interceptor({ response: fail, @@ -270,11 +270,11 @@ } }); client = theInterceptor(errorClient); - client().then(function (response) { + return client().then(function (response) { assert.same('error', response.phase); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, - 'should intercept the error phase and handle a promise': function (done) { + 'should intercept the error phase and handle a promise': function () { var theInterceptor, client; theInterceptor = interceptor({ response: fail, @@ -284,11 +284,11 @@ } }); client = theInterceptor(errorClient); - client().then(function (response) { + return client().then(function (response) { assert.same('error', response.phase); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, - 'should intercept the error phase and handle a rejceted promise': function (done) { + 'should intercept the error phase and handle a rejceted promise': function () { var theInterceptor, client; theInterceptor = interceptor({ response: fail, @@ -298,14 +298,14 @@ } }); client = theInterceptor(errorClient); - client().then( + return client().then( fail, failOnThrow(function (response) { assert.same('error', response.phase); }) - ).ensure(done); + ); }, - 'should pass interceptor config to handlers': function (done) { + 'should pass interceptor config to handlers': function () { var theInterceptor, client, theConfig; theConfig = { foo: 'bar' }; theInterceptor = interceptor({ @@ -323,12 +323,12 @@ } }); client = theInterceptor(defaultClient, theConfig); - client().then(function (response) { + return client().then(function (response) { assert.same('request', response.request.phase); assert.same('response', response.phase); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, - 'should share context between handlers that is unique per request': function (done) { + 'should share context between handlers that is unique per request': function () { var theInterceptor, client, count, counted; count = 0; counted = []; @@ -346,16 +346,16 @@ } }); client = theInterceptor(defaultClient); - when.all([client(), client(), client()]).then(function () { + return when.all([client(), client(), client()]).then(function () { assert.same(3, counted.length); assert(counted.indexOf(1) >= 0); // if 'this' was shared between requests, we'd have 1 twice and no undef assert(counted.indexOf(2) === -1); assert(counted.indexOf(undef) >= 0); assert(counted.indexOf(3) >= 0); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, - 'should use the client provided by a ComplexRequest': function (done) { + 'should use the client provided by a ComplexRequest': function () { var theInterceptor, client; theInterceptor = interceptor({ request: function (request) { @@ -366,12 +366,12 @@ } }); client = theInterceptor(); - client().then(function (response) { + return client().then(function (response) { assert.same('default', response.id); assert.same(client, response.request.originator); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, - 'should use the repsponse provided by a ComplexRequest': function (done) { + 'should use the repsponse provided by a ComplexRequest': function () { var theInterceptor, client; theInterceptor = interceptor({ request: function (request) { @@ -381,12 +381,12 @@ } }); client = theInterceptor(); - client().then(function (response) { + return client().then(function (response) { assert.same('complex-response', response.id); assert.same(client, response.request.originator); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, - 'should cancel requests with the abort trigger provided by a ComplexRequest': function (done) { + 'should cancel requests with the abort trigger provided by a ComplexRequest': function () { var theInterceptor, client; theInterceptor = interceptor({ request: function (request) { @@ -398,15 +398,15 @@ } }); client = theInterceptor(unresponsiveClient); - client().then( + return client().then( fail, failOnThrow(function (response) { assert.same('abort', response.id); assert.same('unresponsive', response.request.id); }) - ).ensure(done); + ); }, - 'should have access to the client in the response handlers for subsequent requests': function (done) { + 'should have access to the client in the response handlers for subsequent requests': function () { var theInterceptor, client; theInterceptor = interceptor({ response: function (response, config, client) { @@ -415,12 +415,12 @@ } }); client = theInterceptor(defaultClient); - client().then(function (response) { + return client().then(function (response) { assert.same(client, response.client); assert.same('default', response.id); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, - 'should initialize the config object, without modifying the provided object': function (done) { + 'should initialize the config object, without modifying the provided object': function () { var theConfig, theInterceptor, client; theConfig = { foo: 'bar' }; theInterceptor = interceptor({ @@ -446,11 +446,11 @@ } }); client = theInterceptor(defaultClient, theConfig); - client().then(function (response) { + return client().then(function (response) { assert.same('request', response.request.phase); assert.same('response', response.phase); assert.same('default', response.id); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, 'should have the default client as the parent by default': function () { var theInterceptor = interceptor(); diff --git a/test/interceptor/basicAuth-test.js b/test/interceptor/basicAuth-test.js index 60015e3..c9194fc 100644 --- a/test/interceptor/basicAuth-test.js +++ b/test/interceptor/basicAuth-test.js @@ -22,30 +22,30 @@ rest = require('rest'); buster.testCase('rest/interceptor/basicAuth', { - 'should authenticate the requst from the config': function (done) { + 'should authenticate the requst from the config': function () { var client = basicAuth( function (request) { return { request: request }; }, { username: 'user', password: 'pass'} ); - client({}).then(function (response) { + return client({}).then(function (response) { assert.equals('Basic dXNlcjpwYXNz', response.request.headers.Authorization); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, - 'should authenticate the requst from the request': function (done) { + 'should authenticate the requst from the request': function () { var client = basicAuth( function (request) { return { request: request }; } ); - client({ username: 'user', password: 'pass'}).then(function (response) { + return client({ username: 'user', password: 'pass'}).then(function (response) { assert.equals('Basic dXNlcjpwYXNz', response.request.headers.Authorization); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, - 'should not authenticate without a username': function (done) { + 'should not authenticate without a username': function () { var client = basicAuth( function (request) { return { request: request }; } ); - client({}).then(function (response) { + return client({}).then(function (response) { refute.defined(response.request.headers.Authorization); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, 'should have the default client as the parent by default': function () { assert.same(rest, basicAuth().skip()); diff --git a/test/interceptor/defaultRequest-test.js b/test/interceptor/defaultRequest-test.js index 9f2282c..ec9af48 100644 --- a/test/interceptor/defaultRequest-test.js +++ b/test/interceptor/defaultRequest-test.js @@ -26,79 +26,79 @@ } buster.testCase('rest/interceptor/defaultRequest', { - 'should do nothing by default': function (done) { + 'should do nothing by default': function () { var client = defaultRequest(defaultClient); - client({}).then(function (response) { + return client({}).then(function (response) { assert.same(client, response.request.originator); delete response.request.originator; assert.equals({}, response.request); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, - 'should default the method': function (done) { + 'should default the method': function () { var client = defaultRequest(defaultClient, { method: 'PUT' }); - client({}).then(function (response) { + return client({}).then(function (response) { assert.equals('PUT', response.request.method); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, - 'should not overwrite the method': function (done) { + 'should not overwrite the method': function () { var client = defaultRequest(defaultClient, { method: 'PUT' }); - client({ method: 'GET' }).then(function (response) { + return client({ method: 'GET' }).then(function (response) { assert.equals('GET', response.request.method); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, - 'should default the path': function (done) { + 'should default the path': function () { var client = defaultRequest(defaultClient, { path: '/foo' }); - client({}).then(function (response) { + return client({}).then(function (response) { assert.equals('/foo', response.request.path); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, - 'should not overwrite the path': function (done) { + 'should not overwrite the path': function () { var client = defaultRequest(defaultClient, { path: '/foo' }); - client({ path: '/bar' }).then(function (response) { + return client({ path: '/bar' }).then(function (response) { assert.equals('/bar', response.request.path); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, - 'should default params': function (done) { + 'should default params': function () { var client = defaultRequest(defaultClient, { params: { foo: 'bar', bool: 'false' } }); - client({}).then(function (response) { + return client({}).then(function (response) { assert.equals('bar', response.request.params.foo); assert.equals('false', response.request.params.bool); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, - 'should merge params': function (done) { + 'should merge params': function () { var client = defaultRequest(defaultClient, { params: { foo: 'bar', bool: 'false' } }); - client({ params: { bool: 'true', bleep: 'bloop' } }).then(function (response) { + return client({ params: { bool: 'true', bleep: 'bloop' } }).then(function (response) { assert.equals('bar', response.request.params.foo); assert.equals('true', response.request.params.bool); assert.equals('bloop', response.request.params.bleep); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, - 'should default headers': function (done) { + 'should default headers': function () { var client = defaultRequest(defaultClient, { headers: { foo: 'bar', bool: 'false' } }); - client({}).then(function (response) { + return client({}).then(function (response) { assert.equals('bar', response.request.headers.foo); assert.equals('false', response.request.headers.bool); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, - 'should merge headers': function (done) { + 'should merge headers': function () { var client = defaultRequest(defaultClient, { headers: { foo: 'bar', bool: 'false' } }); - client({ headers: { bool: 'true', bleep: 'bloop' } }).then(function (response) { + return client({ headers: { bool: 'true', bleep: 'bloop' } }).then(function (response) { assert.equals('bar', response.request.headers.foo); assert.equals('true', response.request.headers.bool); assert.equals('bloop', response.request.headers.bleep); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, - 'should default the entity': function (done) { + 'should default the entity': function () { var client = defaultRequest(defaultClient, { entity: Math }); - client({}).then(function (response) { + return client({}).then(function (response) { assert.same(Math, response.request.entity); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, - 'should not overwrite the entity': function (done) { + 'should not overwrite the entity': function () { var client = defaultRequest(defaultClient, { entity: Math }); - client({ entity: Date }).then(function (response) { + return client({ entity: Date }).then(function (response) { assert.same(Date, response.request.entity); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, 'should have the default client as the parent by default': function () { assert.same(rest, defaultRequest().skip()); diff --git a/test/interceptor/entity-test.js b/test/interceptor/entity-test.js index 27eab01..1f91308 100644 --- a/test/interceptor/entity-test.js +++ b/test/interceptor/entity-test.js @@ -22,25 +22,25 @@ rest = require('rest'); buster.testCase('rest/interceptor/entity', { - 'should return the response entity': function (done) { + 'should return the response entity': function () { var client, body; body = {}; client = entity(function () { return { entity: body }; }); - client().then(function (response) { + return client().then(function (response) { assert.same(body, response); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, - 'should return the whole response if there is no entity': function (done) { + 'should return the whole response if there is no entity': function () { var client, response; response = {}; client = entity(function () { return response; }); - client().then(function (r) { + return client().then(function (r) { assert.same(response, r); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, 'should have the default client as the parent by default': function () { assert.same(rest, entity().skip()); diff --git a/test/interceptor/errorCode-test.js b/test/interceptor/errorCode-test.js index 9b74f20..37bca31 100644 --- a/test/interceptor/errorCode-test.js +++ b/test/interceptor/errorCode-test.js @@ -23,36 +23,36 @@ rest = require('rest'); buster.testCase('rest/interceptor/errorCode', { - 'should resolve for less than 400 by default': function (done) { + 'should resolve for less than 400 by default': function () { var client = errorCode( function () { return { status: { code: 399 } }; } ); - client({}).then(function (response) { + return client({}).then(function (response) { assert.equals(399, response.status.code); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, - 'should reject for 400 or greater by default': function (done) { + 'should reject for 400 or greater by default': function () { var client = errorCode( function () { return { status: { code: 400 } }; } ); - client({}).then( + return client({}).then( fail, failOnThrow(function (response) { assert.equals(400, response.status.code); }) - ).ensure(done); + ); }, - 'should reject lower then 400 with a custom code': function (done) { + 'should reject lower then 400 with a custom code': function () { var client = errorCode( function () { return { status: { code: 300 } }; }, { code: 300 } ); - client({}).then( + return client({}).then( fail, failOnThrow(function (response) { assert.equals(300, response.status.code); }) - ).ensure(done); + ); }, 'should have the default client as the parent by default': function () { assert.same(rest, errorCode().skip()); diff --git a/test/interceptor/hateoas-test.js b/test/interceptor/hateoas-test.js index 4592ac3..dea5137 100644 --- a/test/interceptor/hateoas-test.js +++ b/test/interceptor/hateoas-test.js @@ -48,7 +48,7 @@ buster.testCase('rest/interceptor/hateoas', { requiresSupportFor: { 'Object.defineProperty': supports['Object.defineProperty'] }, - 'should parse links in the entity': function (done) { + 'should parse links in the entity': function () { var client, body, parent, self; parent = { rel: 'parent', href: '/' }; @@ -57,12 +57,12 @@ body = { links: [ parent, self ]}; client = hateoas(function () { return { entity: body }; }); - client().then(function (response) { + return client().then(function (response) { assert.same(parent, response.entity._links.parentLink); assert.same(self, response.entity._links.selfLink); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, - 'should parse links in the entity into the entity': function (done) { + 'should parse links in the entity into the entity': function () { var client, body, parent, self; parent = { rel: 'parent', href: '/' }; @@ -71,12 +71,12 @@ body = { links: [ parent, self ]}; client = hateoas(function () { return { entity: body }; }, { target: '' }); - client().then(function (response) { + return client().then(function (response) { assert.same(parent, response.entity.parentLink); assert.same(self, response.entity.selfLink); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, - 'should create a client for the related resource': function (done) { + 'should create a client for the related resource': function () { var client, body, parent, self; parent = { rel: 'parent', href: '/' }; @@ -85,16 +85,16 @@ body = { links: [ parent, self ]}; client = hateoas(function () { return { entity: body }; }); - client().then(function (response) { + return client().then(function (response) { var parentClient = response.entity._links.clientFor('parent', function (request) { return { request: request }; }); return parentClient().then(function (response) { assert.same(parent.href, response.request.path); }); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, 'should fetch a related resource': { requiresSupportFor: { 'ES5 getters': supports['ES5 getters'] }, - '': function (done) { + '': function () { var client, parentClient; parentClient = function (request) { @@ -104,14 +104,14 @@ }; client = hateoas(parentClient); - client({ path: '/' }).then(function (response) { + return client({ path: '/' }).then(function (response) { assert.same('/', response.request.path); assert.same('/', response.entity._links.selfLink.href); return response.entity._links.child.then(function (response) { assert.same('/resource', response.request.path); assert.same('/resource', response.entity._links.selfLink.href); }); - }).otherwise(fail).ensure(done); + }).otherwise(fail); } }, 'should have the default client as the parent by default': function () { diff --git a/test/interceptor/ie/xdomain-test-browser.js b/test/interceptor/ie/xdomain-test-browser.js index 78f1e0d..d6a350b 100644 --- a/test/interceptor/ie/xdomain-test-browser.js +++ b/test/interceptor/ie/xdomain-test-browser.js @@ -37,28 +37,28 @@ buster.testCase('rest/interceptor/ie/xdomain', { 'for XDomainRequest enabled browsers': { requiresSupportFor: { 'xdr': xdr, 'not-xhrCors': !xhrCors }, - 'should use the XDomainRequest engine for cross domain requests': function (done) { - client({ path: 'http://example.com' }).then(function (response) { + 'should use the XDomainRequest engine for cross domain requests': function () { + return client({ path: 'http://example.com' }).then(function (response) { assert.same('xdr', response.client); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, - 'should use the standard engine for same domain requests, with absolute paths': function (done) { - client({ path: window.location.toString() }).then(function (response) { + 'should use the standard engine for same domain requests, with absolute paths': function () { + return client({ path: window.location.toString() }).then(function (response) { assert.same('default', response.client); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, - 'should use the standard engine for same domain requests, with relative paths': function (done) { - client({ path: '/' }).then(function (response) { + 'should use the standard engine for same domain requests, with relative paths': function () { + return client({ path: '/' }).then(function (response) { assert.same('default', response.client); - }).otherwise(fail).ensure(done); + }).otherwise(fail); } }, 'for non-XDomainRequest enabled browsers': { requiresSupportForAny: { 'not-xdr': !xdr, 'xhrCors': xhrCors }, - 'should always use the standard engine': function (done) { - client({ path: 'http://example.com' }).then(function (response) { + 'should always use the standard engine': function () { + return client({ path: 'http://example.com' }).then(function (response) { assert.same('default', response.client); - }).otherwise(fail).ensure(done); + }).otherwise(fail); } }, 'should have the default client as the parent by default': function () { diff --git a/test/interceptor/ie/xhr-test-browser.js b/test/interceptor/ie/xhr-test-browser.js index 2d4db83..f2b17d4 100644 --- a/test/interceptor/ie/xhr-test-browser.js +++ b/test/interceptor/ie/xhr-test-browser.js @@ -29,22 +29,22 @@ 'should provide the native XHR object as the engine': { // native XHR requiresSupportFor: { xhr: !!XMLHttpRequest }, - '': function (done) { + '': function () { var client = xhr(defaultClient); - client({}).then(function (response) { + return client({}).then(function (response) { assert.same(XMLHttpRequest, response.request.engine); - }).otherwise(fail).ensure(done); + }).otherwise(fail); } }, 'should fall back to an ActiveX XHR-like object as the engine': { // XHR ActiveX fallback requiresSupportFor: { xhr: !XMLHttpRequest }, - '': function (done) { + '': function () { var client = xhr(defaultClient); - client({}).then(function (response) { + return client({}).then(function (response) { refute.same(XMLHttpRequest, response.request.engine); assert.same('function', typeof response.request.engine); - }).otherwise(fail).ensure(done); + }).otherwise(fail); } }, 'should have the default client as the parent by default': function () { diff --git a/test/interceptor/jsonp-test.js b/test/interceptor/jsonp-test.js index 0401e8b..32a930e 100644 --- a/test/interceptor/jsonp-test.js +++ b/test/interceptor/jsonp-test.js @@ -24,25 +24,25 @@ when = require('when'); buster.testCase('rest/interceptor/jsonp', { - 'should include callback info from config in request by default': function (done) { + 'should include callback info from config in request by default': function () { var client = jsonp( function (request) { return when({ request: request }); }, { callback: { param: 'callback', prefix: 'jsonp' } } ); - client({}).then(function (response) { + return client({}).then(function (response) { assert.equals('callback', response.request.callback.param); assert.equals('jsonp', response.request.callback.prefix); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, - 'should include callback info from request overridding config values': function (done) { + 'should include callback info from request overridding config values': function () { var client = jsonp( function (request) { return when({ request: request }); }, { callback: { param: 'callback', prefix: 'jsonp' } } ); - client({ callback: { param: 'customCallback', prefix: 'customPrefix' } }).then(function (response) { + return client({ callback: { param: 'customCallback', prefix: 'customPrefix' } }).then(function (response) { assert.equals('customCallback', response.request.callback.param); assert.equals('customPrefix', response.request.callback.prefix); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, 'should have the jsonp client as the parent by default': function () { refute.same(rest, jsonp().skip()); diff --git a/test/interceptor/location-test.js b/test/interceptor/location-test.js index 882059a..7f995ef 100644 --- a/test/interceptor/location-test.js +++ b/test/interceptor/location-test.js @@ -22,7 +22,7 @@ rest = require('rest'); buster.testCase('rest/interceptor/location', { - 'should follow the location header': function (done) { + 'should follow the location header': function () { var client, spy; spy = this.spy(function (request) { var response = { request: request, headers: { } }; @@ -32,7 +32,7 @@ return response; }); client = location(spy); - client({}).then(function (response) { + return client({}).then(function (response) { refute(response.headers.Location); assert.same(3, spy.callCount); assert.same(spy.returnValues[0].headers.Location, '/foo/1'); @@ -42,16 +42,16 @@ assert.same(spy.args[2][0].path, '/foo/2'); assert.same(spy.args[2][0].method, 'GET'); refute(spy.returnValues[2].headers.Location); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, - 'should return the response if there is no location header': function (done) { + 'should return the response if there is no location header': function () { var client, spy; spy = this.spy(function () { return { status: { code: 200 } }; }); client = location(spy); - client({}).then(function (response) { + return client({}).then(function (response) { assert.equals(200, response.status.code); assert.same(1, spy.callCount); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, 'should have the default client as the parent by default': function () { assert.same(rest, location().skip()); diff --git a/test/interceptor/mime-test.js b/test/interceptor/mime-test.js index 4adc20e..5e41919 100644 --- a/test/interceptor/mime-test.js +++ b/test/interceptor/mime-test.js @@ -24,18 +24,18 @@ rest = require('rest'); buster.testCase('rest/interceptor/mime', { - 'should return the response entity decoded': function (done) { + 'should return the response entity decoded': function () { var client; client = mime(function () { return { entity: '{}', headers: { 'Content-Type': 'application/json' } }; }); - client({}).then(function (response) { + return client({}).then(function (response) { assert.equals({}, response.entity); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, - 'should encode the request entity': function (done) { + 'should encode the request entity': function () { var client; client = mime( @@ -45,11 +45,11 @@ { mime: 'application/json' } ); - client({ entity: {} }).then(function (response) { + return client({ entity: {} }).then(function (response) { assert.equals('{}', response.request.entity); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, - 'should encode the request entity from the Content-Type of the request, ignoring the filter config': function (done) { + 'should encode the request entity from the Content-Type of the request, ignoring the filter config': function () { var client; client = mime( @@ -59,13 +59,13 @@ { mime: 'text/plain' } ); - client({ entity: {}, headers: { 'Content-Type': 'application/json' } }).then(function (response) { + return client({ entity: {}, headers: { 'Content-Type': 'application/json' } }).then(function (response) { assert.equals('{}', response.request.entity); assert.equals('application/json', response.request.headers['Content-Type']); assert.equals(0, response.request.headers.Accept.indexOf('application/json')); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, - 'should not overwrite the requests Accept header': function (done) { + 'should not overwrite the requests Accept header': function () { var client; client = mime( @@ -75,38 +75,38 @@ { mime: 'application/json' } ); - client({ entity: {}, headers: { Accept: 'foo' } }).then(function (response) { + return client({ entity: {}, headers: { Accept: 'foo' } }).then(function (response) { assert.equals('{}', response.request.entity); assert.equals('application/json', response.request.headers['Content-Type']); assert.equals('foo', response.request.headers.Accept); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, - 'should error the request if unable to find a converter for the desired mime': function (done) { + 'should error the request if unable to find a converter for the desired mime': function () { var client, request; client = mime(); request = { headers: { 'Content-Type': 'application/vnd.com.example' }, entity: {} }; - client(request).then( + return client(request).then( fail, failOnThrow(function (response) { assert.same('unknown-mime', response.error); assert.same(request, response.request); }) - ).ensure(done); + ); }, - 'should use text/plain converter for a response if unable to find a converter for the desired mime': function (done) { + 'should use text/plain converter for a response if unable to find a converter for the desired mime': function () { var client; client = mime(function () { return { entity: '{}', headers: { 'Content-Type': 'application/vnd.com.example' } }; }); - client({}).then(function (response) { + return client({}).then(function (response) { assert.same('{}', response.entity); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, - 'should use the configured mime registry': function (done) { + 'should use the configured mime registry': function () { var client, customRegistry; customRegistry = registry.child(); @@ -126,12 +126,12 @@ { mime: 'application/vnd.com.example', registry: customRegistry } ); - client({ entity: 'request entity' }).then(function (response) { + return client({ entity: 'request entity' }).then(function (response) { assert.equals('application/vnd.com.example', response.request.headers['Content-Type']); assert.equals('write: request entity', response.request.entity); assert.equals('application/vnd.com.example', response.headers['Content-Type']); assert.equals('read: response entity', response.entity); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, 'should have the default client as the parent by default': function () { assert.same(rest, mime().skip()); diff --git a/test/interceptor/oAuth-test.js b/test/interceptor/oAuth-test.js index e437ab3..e44bf9a 100644 --- a/test/interceptor/oAuth-test.js +++ b/test/interceptor/oAuth-test.js @@ -23,7 +23,7 @@ rest = require('rest'); buster.testCase('rest/interceptor/oAuth', { - 'should authenticate the request for a known token': function (done) { + 'should authenticate the request for a known token': function () { var client; client = oAuth( @@ -31,11 +31,11 @@ { token: 'bearer abcxyz' } ); - client({}).then(function (response) { + return client({}).then(function (response) { assert.equals('bearer abcxyz', response.request.headers.Authorization); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, - 'should use implicit flow to authenticate the request': function (done) { + 'should use implicit flow to authenticate the request': function () { var client, windowStrategy, windowStrategyClose, oAuthCallbackName; oAuthCallbackName = 'oAuthCallback' + Math.round(Math.random() * 100000); @@ -64,10 +64,10 @@ } ); - client({}).then(function (response) { + return client({}).then(function (response) { assert.equals('bearer abcxyz', response.request.headers.Authorization); assert.called(windowStrategyClose); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, 'should have the default client as the parent by default': function () { assert.same(rest, oAuth({ token: 'bearer abcxyz' }).skip()); diff --git a/test/interceptor/pathPrefix-test.js b/test/interceptor/pathPrefix-test.js index 638a82d..ffe00f5 100644 --- a/test/interceptor/pathPrefix-test.js +++ b/test/interceptor/pathPrefix-test.js @@ -22,41 +22,41 @@ rest = require('rest'); buster.testCase('rest/interceptor/pathPrefix', { - 'should prepend prefix before path': function (done) { + 'should prepend prefix before path': function () { var client = pathPrefix( function (request) { return { request: request }; }, { prefix: '/foo' } ); - client({ path: '/bar' }).then(function (response) { + return client({ path: '/bar' }).then(function (response) { assert.equals('/foo/bar', response.request.path); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, - 'should prepend prefix before path, adding slash between path segments': function (done) { + 'should prepend prefix before path, adding slash between path segments': function () { var client = pathPrefix( function (request) { return { request: request }; }, { prefix: '/foo' } ); - client({ path: 'bar' }).then(function (response) { + return client({ path: 'bar' }).then(function (response) { assert.equals('/foo/bar', response.request.path); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, - 'should prepend prefix before path, not adding extra slash between path segments': function (done) { + 'should prepend prefix before path, not adding extra slash between path segments': function () { var client = pathPrefix( function (request) { return { request: request }; }, { prefix: '/foo/' } ); - client({ path: 'bar' }).then(function (response) { + return client({ path: 'bar' }).then(function (response) { assert.equals('/foo/bar', response.request.path); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, - 'should not prepend prefix before a fully qualified path': function (done) { + 'should not prepend prefix before a fully qualified path': function () { var client = pathPrefix( function (request) { return { request: request }; }, { prefix: '/foo' } ); - client({ path: 'http://www.example.com/' }).then(function (response) { + return client({ path: 'http://www.example.com/' }).then(function (response) { assert.equals('http://www.example.com/', response.request.path); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, 'should have the default client as the parent by default': function () { assert.same(rest, pathPrefix().skip()); diff --git a/test/interceptor/retry-test.js b/test/interceptor/retry-test.js index 42e0659..b0460d5 100644 --- a/test/interceptor/retry-test.js +++ b/test/interceptor/retry-test.js @@ -37,7 +37,7 @@ }(setTimeout)); buster.testCase('rest/interceptor/retry', { - 'should retry until successful': function (done) { + 'should retry until successful': function () { var count = 0, client = retry( function (request) { count += 1; @@ -48,9 +48,9 @@ } } ); - client({}).then(function (response) { + return client({}).then(function (response) { assert.equals(200, response.status.code); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, 'should accept custom config': { setUp: function () { @@ -59,7 +59,7 @@ tearDown: function () { clock.restore(); }, - '': function (done) { + '': function () { var count = 0, client, start, config; start = new Date().getTime(); @@ -80,15 +80,15 @@ config ); - client({}).then(function (response) { + return client({}).then(function (response) { assert.equals(200, response.status.code); assert.equals(count, 4); assert.equals(50, new Date().getTime() - start); - }).otherwise(fail).ensure(done); + }).otherwise(fail); } }, - 'should not make propagate request if marked as canceled': function (done) { - var parent, client, request; + 'should not make propagate request if marked as canceled': function () { + var parent, client, request, response; parent = this.spy(function (request) { return when.reject({ request: request }); @@ -96,16 +96,17 @@ client = retry(parent, { initial: 10 }); request = {}; - client(request).then( + response = client(request).then( fail, failOnThrow(function (response) { assert(request.canceled); assert.equals('precanceled', response.error); assert.same(1, parent.callCount); }) - ).ensure(done); - + ); request.canceled = true; + + return response; }, 'should have the default client as the parent by default': function () { assert.same(rest, retry().skip()); diff --git a/test/interceptor/timeout-test.js b/test/interceptor/timeout-test.js index 45f5a00..8f96c65 100644 --- a/test/interceptor/timeout-test.js +++ b/test/interceptor/timeout-test.js @@ -54,88 +54,89 @@ } buster.testCase('rest/interceptor/timeout', { - 'should resolve if client responds immediately': function (done) { + 'should resolve if client responds immediately': function () { var client, request; client = timeout(immediateClient, { timeout: 20 }); request = {}; - client(request).then(function (response) { + return client(request).then(function (response) { assert.same(request, response.request); refute(response.error); return delay(40).then(function () { // delay to make sure timeout has fired, but not rejected the response refute(request.canceled); }); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, - 'should resolve if client responds before timeout': function (done) { + 'should resolve if client responds before timeout': function () { var client, request; client = timeout(delayedClient, { timeout: 100 }); request = {}; - client(request).then(function (response) { + return client(request).then(function (response) { assert.same(request, response.request); refute(response.error); refute(request.canceled); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, - 'should reject even if client responds after timeout': function (done) { + 'should reject even if client responds after timeout': function () { var client, request; client = timeout(delayedClient, { timeout: 10 }); request = {}; - client(request).then( + return client(request).then( fail, failOnThrow(function (response) { assert.same(request, response.request); assert.equals('timeout', response.error); assert(request.canceled); }) - ).ensure(done); + ); }, - 'should reject if client hanges': function (done) { + 'should reject if client hanges': function () { var client, request; client = timeout(hangClient, { timeout: 50 }); request = {}; - client(request).then( + return client(request).then( fail, failOnThrow(function (response) { assert.same(request, response.request); assert.equals('timeout', response.error); assert(request.canceled); }) - ).ensure(done); + ); }, - 'should use request timeout value in perference to interceptor value': function (done) { + 'should use request timeout value in perference to interceptor value': function () { var client, request; client = timeout(delayedClient, { timeout: 10 }); request = { timeout: 0 }; - client(request).then(function (response) { + return client(request).then(function (response) { assert.same(request, response.request); refute(response.error); refute(request.canceled); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, - 'should not reject without a configured timeout value': function (done) { + 'should not reject without a configured timeout value': function () { var client, request; client = timeout(delayedClient); request = {}; - client(request).then(function (response) { + return client(request).then(function (response) { assert.same(request, response.request); refute(response.error); refute(request.canceled); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, - 'should cancel request if client support cancelation': function (done) { - var client, request; + 'should cancel request if client support cancelation': function () { + var client, request, response; client = timeout(cancelableClient, { timeout: 11 }); request = {}; - client(request).then( + response = client(request).then( fail, failOnThrow(function (response) { assert.same(request, response.request); assert.equals('timeout', response.error); assert(request.canceled); }) - ).ensure(done); + ); refute(request.canceled); + return response; }, 'should have the default client as the parent by default': function () { assert.same(rest, timeout().skip()); diff --git a/test/mime/registry-test.js b/test/mime/registry-test.js index 2455504..fe04431 100644 --- a/test/mime/registry-test.js +++ b/test/mime/registry-test.js @@ -25,57 +25,57 @@ setUp: function () { registry = mimeRegistry.child(); }, - 'should discover unregisted converter': function (done) { - registry.lookup('text/plain').then(function (converter) { + 'should discover unregisted converter': function () { + return registry.lookup('text/plain').then(function (converter) { assert.isFunction(converter.read); assert.isFunction(converter.write); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, - 'should return registed converter': function (done) { + 'should return registed converter': function () { var converter = {}; registry.register('application/vnd.com.example', converter); - registry.lookup('application/vnd.com.example').then(function (c) { + return registry.lookup('application/vnd.com.example').then(function (c) { assert.same(converter, c); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, - 'should reject for non-existant converter': function (done) { - registry.lookup('application/bogus').then( + 'should reject for non-existant converter': function () { + return registry.lookup('application/bogus').then( fail, function () { assert(true); } - ).ensure(done); + ); }, - 'should resolve converters from parent registries': function (done) { + 'should resolve converters from parent registries': function () { var child, converter; child = registry.child(); converter = {}; registry.register('application/vnd.com.example', converter); - child.lookup('application/vnd.com.example').then(function (c) { + return child.lookup('application/vnd.com.example').then(function (c) { assert.same(converter, c); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, - 'should override parent registries when registering in a child': function (done) { + 'should override parent registries when registering in a child': function () { var child, converterParent, converterChild; child = registry.child(); converterParent = {}; converterChild = {}; registry.register('application/vnd.com.example', converterParent); child.register('application/vnd.com.example', converterChild); - child.lookup('application/vnd.com.example').then(function (c) { + return child.lookup('application/vnd.com.example').then(function (c) { assert.same(converterChild, c); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, - 'should not have any side effects in a parent registry from a child': function (done) { + 'should not have any side effects in a parent registry from a child': function () { var child, converterParent, converterChild; child = registry.child(); converterParent = {}; converterChild = {}; registry.register('application/vnd.com.example', converterParent); child.register('application/vnd.com.example', converterChild); - registry.lookup('application/vnd.com.example').then(function (c) { + return registry.lookup('application/vnd.com.example').then(function (c) { assert.same(converterParent, c); - }).otherwise(fail).ensure(done); + }).otherwise(fail); } }); diff --git a/test/wire-test.js b/test/wire-test.js index 32bb70c..fd59b56 100644 --- a/test/wire-test.js +++ b/test/wire-test.js @@ -24,7 +24,7 @@ wire = require('wire'); buster.testCase('rest/wire', { - 'should use default client! config': function (done) { + 'should use default client! config': function () { var spec, client; client = function (request) { return { request: request, status: { code: 200 }, headers: { 'Content-Type': 'application/json' }, entity: '{"foo":"bar"}' }; @@ -33,13 +33,13 @@ client: { $ref: 'client!', client: client }, plugins: [{ module: 'rest/wire' }] }; - wire(spec, { require: require }).then(function (spec) { + return wire(spec, { require: require }).then(function (spec) { return spec.client({}).then(function (response) { assert.equals('bar', response.foo); }); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, - 'should use client! config with entity interceptor disabled': function (done) { + 'should use client! config with entity interceptor disabled': function () { var spec, client; client = function (request) { return { request: request, status: { code: 200 }, headers: { 'Content-Type': 'application/json' }, entity: '{"foo":"bar"}' }; @@ -48,15 +48,15 @@ client: { $ref: 'client!path', client: client, accept: 'text/plain', entity: false }, plugins: [{ module: 'rest/wire' }] }; - wire(spec, { require: require }).then(function (spec) { + return wire(spec, { require: require }).then(function (spec) { return spec.client({ path: 'to/somewhere' }).then(function (response) { assert.equals('path/to/somewhere', response.request.path); assert.equals('text/plain', response.request.headers.Accept); assert.equals('bar', response.entity.foo); }); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, - 'should be rejected for a server error status code': function (done) { + 'should be rejected for a server error status code': function () { var spec, client; client = function (request) { return { request: request, status: { code: 500 }, headers: { 'Content-Type': 'application/json' }, entity: '{"foo":"bar"}' }; @@ -65,7 +65,7 @@ client: { $ref: 'client!', client: client }, plugins: [{ module: 'rest/wire' }] }; - wire(spec, { require: require }).then( + return wire(spec, { require: require }).then( function (spec) { return spec.client({}).then( fail, @@ -75,9 +75,9 @@ ); }, fail - ).ensure(done); + ); }, - 'should ignore status code when errorCode interceptor is disabled': function (done) { + 'should ignore status code when errorCode interceptor is disabled': function () { var spec, client; client = function (request) { return { request: request, status: { code: 500 }, headers: { 'Content-Type': 'application/json' }, entity: '{"foo":"bar"}' }; @@ -86,13 +86,13 @@ client: { $ref: 'client!', client: client, errorCode: false }, plugins: [{ module: 'rest/wire' }] }; - wire(spec, { require: require }).then(function (spec) { + return wire(spec, { require: require }).then(function (spec) { return spec.client({}).then(function (response) { assert.equals('bar', response.foo); }); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, - 'should ignore Content-Type and entity when mime interceptor is disabled': function (done) { + 'should ignore Content-Type and entity when mime interceptor is disabled': function () { var spec, client; client = function (request) { return { request: request, status: { code: 200 }, headers: { 'Content-Type': 'application/json' }, entity: '{"foo":"bar"}' }; @@ -101,13 +101,13 @@ client: { $ref: 'client!', client: client, mime: false }, plugins: [{ module: 'rest/wire' }] }; - wire(spec, { require: require }).then(function (spec) { + return wire(spec, { require: require }).then(function (spec) { return spec.client({}).then(function (response) { assert.isString(response); }); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, - 'should use x-www-form-urlencoded as the default Content-Type for POSTs': function (done) { + 'should use x-www-form-urlencoded as the default Content-Type for POSTs': function () { var spec, client; client = function (request) { return { request: request, status: { code: 200 }, headers: { 'Content-Type': 'application/json' }, entity: '{"foo":"bar"}' }; @@ -116,16 +116,16 @@ client: { $ref: 'client!', client: client, entity: false }, plugins: [{ module: 'rest/wire' }] }; - wire(spec, { require: require }).then(function (spec) { + return wire(spec, { require: require }).then(function (spec) { return spec.client({ method: 'post', entity: { bleep: 'bloop' } }).then(function (response) { assert.equals('bleep=bloop', response.request.entity); assert.equals(0, response.request.headers.Accept.indexOf('application/x-www-form-urlencoded')); assert.equals('application/x-www-form-urlencoded', response.request.headers['Content-Type']); }); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, 'should use the rest factory': { - '': function (done) { + '': function () { var spec, client; client = function (request) { return { request: request, status: { code: 200 }, headers: { 'Content-Type': 'application/json' }, entity: '{"foo":"bar"}' }; @@ -143,7 +143,7 @@ }, plugins: [{ module: 'rest/wire' }] }; - wire(spec, { require: require }).then(function (spec) { + return wire(spec, { require: require }).then(function (spec) { assert.same(client, spec.client.skip().skip().skip()); spec.client({ method: 'post', path: '/', entity: { bleep: 'bloop' } }).then(function (response) { assert.equals('http://example.com/', response.request.path); @@ -152,9 +152,9 @@ assert.equals(0, response.request.headers.Accept.indexOf('application/json')); assert.equals('application/json', response.request.headers['Content-Type']); }); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, - 'with interceptor references': function (done) { + 'with interceptor references': function () { var spec, client; client = function (request) { return { request: request, status: { code: 200 }, headers: { 'Content-Type': 'application/json' }, entity: '{"foo":"bar"}' }; @@ -175,7 +175,7 @@ errorCode: { module: 'rest/interceptor/errorCode' }, plugins: [{ module: 'rest/wire' }] }; - wire(spec, { require: require }).then(function (spec) { + return wire(spec, { require: require }).then(function (spec) { assert.same(client, spec.client.skip().skip().skip()); spec.client({ method: 'post', path: '/', entity: { bleep: 'bloop' } }).then(function (response) { assert.equals('http://example.com/', response.request.path); @@ -184,9 +184,9 @@ assert.equals(0, response.request.headers.Accept.indexOf('application/json')); assert.equals('application/json', response.request.headers['Content-Type']); }); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, - 'with interceptor string shortcuts': function (done) { + 'with interceptor string shortcuts': function () { var spec, client; client = function () {}; spec = { @@ -202,11 +202,11 @@ }, plugins: [{ module: 'rest/wire' }] }; - wire(spec, { require: require }).then(function (spec) { + return wire(spec, { require: require }).then(function (spec) { assert.same(client, spec.client.skip().skip().skip()); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, - 'with concrete interceptors': function (done) { + 'with concrete interceptors': function () { var spec, client; client = function (request) { return { request: request }; @@ -222,14 +222,14 @@ }, plugins: [{ module: 'rest/wire' }] }; - wire(spec, { require: require }).then(function (spec) { + return wire(spec, { require: require }).then(function (spec) { assert.same(client, spec.client.skip()); spec.client().then(function (response) { assert.equals('thePrefix', response.request.path); }); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, - 'using the default client': function (done) { + 'using the default client': function () { var spec; spec = { client: { @@ -239,11 +239,11 @@ }, plugins: [{ module: 'rest/wire' }] }; - wire(spec, { require: require }).then(function (spec) { + return wire(spec, { require: require }).then(function (spec) { assert.same(rest, spec.client.skip()); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, - 'using a referenced parent client': function (done) { + 'using a referenced parent client': function () { var spec, client; client = function (request) { return { request: request }; @@ -260,11 +260,11 @@ parentClient: client, plugins: [{ module: 'rest/wire' }] }; - wire(spec, { require: require }).then(function (spec) { + return wire(spec, { require: require }).then(function (spec) { assert.same(client, spec.client.skip()); - }).otherwise(fail).ensure(done); + }).otherwise(fail); }, - 'without wiring interceptor configurations': function (done) { + 'without wiring interceptor configurations': function () { var spec, client; client = function (request) { return { request: request }; @@ -283,12 +283,12 @@ }, plugins: [{ module: 'rest/wire' }] }; - wire(spec, { require: require }).then(function (spec) { + return wire(spec, { require: require }).then(function (spec) { assert.same(client, spec.client.skip()); spec.client().then(function (response) { assert.equals('useThisOne', response.request.path); }); - }).otherwise(fail).ensure(done); + }).otherwise(fail); } } });