diff --git a/package.json b/package.json index 8e7f4ca..468ca0c 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "prepare": "rm -rf lib && tsc", "pretest": "tsc", "posttest": "eslint . --ext .ts", - "test": "node --experimental-vm-modules node_modules/jest/bin/jest.js" + "test": "jest" }, "types": "./lib/http.d.ts" } diff --git a/src/http.ts b/src/http.ts index f9cb53c..f44ecda 100644 --- a/src/http.ts +++ b/src/http.ts @@ -100,6 +100,7 @@ export class HTTP { raw: false, partial: false, headers: {}, + timeout: 5000, } static create(options: HTTPRequestOptions = {}): typeof HTTP { @@ -390,10 +391,10 @@ export class HTTP { debug(`← ${this.method} ${this.url} TIMED OUT`) this.request.destroy() }) + this.request.on('timeout', reject) } this.request.on('error', reject) - this.request.on('timeout', reject) if (this.options.body && deps.isStream.readable(this.options.body)) { this.options.body.pipe(this.request) } else {