Skip to content

Commit

Permalink
Allow setting a custom promise implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
forivall committed May 17, 2016
1 parent 62c941d commit b477ee9
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ function TestServer(app) {
return new TestServer;
}

// allow custom promise
if (!TestServer.Promise) {
throw new Error('native promise missing, set Fetch.Promise to your favorite alternative');
}

this.server = http.createServer(app);

['delete', 'get', 'head', 'options', 'patch', 'post', 'put'].forEach((method) => {
Expand Down Expand Up @@ -60,6 +65,14 @@ TestServer.prototype.fetch = function fetch(path, opts) {
});
};

TestServer.setPromiseImplementation = function setPromiseImplementation(Promise) {
nodeFetch.Promise = Promise;
TestServer.Promise = Promise;
};

if (typeof Promise !== 'undefined') {
TestServer.Promise = Promise;
}
TestServer.Fetch = nodeFetch;

module.exports = TestServer;

0 comments on commit b477ee9

Please sign in to comment.