Skip to content

Commit a86ba60

Browse files
forivallamacneil
authored andcommitted
Allow setting a custom promise implementation
Closes #1
1 parent 522f12b commit a86ba60

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

index.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ function TestServer(app) {
99
return new TestServer();
1010
}
1111

12+
// allow custom promise
13+
if (!TestServer.Promise) {
14+
throw new Error('native promise missing, set TestServer.Promise to your favorite alternative');
15+
}
16+
17+
this.Promise = TestServer.Promise;
1218
this.server = http.createServer(app);
1319

1420
['delete', 'get', 'head', 'options', 'patch', 'post', 'put'].forEach((method) => {
@@ -26,7 +32,7 @@ function TestServer(app) {
2632

2733
TestServer.prototype.listen = function listen() {
2834
if (!this.listener) {
29-
this.listener = new Promise((resolve, reject) => {
35+
this.listener = new this.Promise((resolve, reject) => {
3036
this.server.listen(0, () => resolve())
3137
.on('error', (err) => reject(err));
3238
});
@@ -38,7 +44,7 @@ TestServer.prototype.listen = function listen() {
3844
TestServer.prototype.close = function close() {
3945
this.listener = null;
4046

41-
return new Promise((resolve, reject) => {
47+
return new this.Promise((resolve, reject) => {
4248
this.server.close((err) => (err ? reject(err) : resolve()));
4349
});
4450
};
@@ -60,4 +66,7 @@ TestServer.prototype.fetch = function fetch(path, opts) {
6066
});
6167
};
6268

69+
// expose Promise
70+
TestServer.Promise = global.Promise;
71+
6372
module.exports = TestServer;

0 commit comments

Comments
 (0)