From de127db2a6408a42a81b7d7d9f55a4df88221c35 Mon Sep 17 00:00:00 2001 From: cjihrig Date: Tue, 25 Aug 2020 17:00:24 -0400 Subject: [PATCH] Revert "Fix cleanup to be consistent across node releases" This reverts commit 50ceba63ec72d01b3298a6384f1498f578f9dbf6. This change caused a regression in the hapi test suite. --- lib/request.js | 13 +++++++++---- lib/response.js | 4 ++++ test/index.js | 19 ------------------- 3 files changed, 13 insertions(+), 23 deletions(-) diff --git a/lib/request.js b/lib/request.js index 05d9e33..e67c151 100755 --- a/lib/request.js +++ b/lib/request.js @@ -13,10 +13,7 @@ exports = module.exports = internals.Request = class extends Stream.Readable { constructor(options) { - super({ - emitClose: !!(options.simulate && options.simulate.close), - autoDestroy: true // This is the default in node 14+ - }); + super(); // options: method, url, payload, headers, remoteAddress @@ -139,11 +136,19 @@ exports = module.exports = internals.Request = class extends Stream.Readable { this.emit('error', new Error('Simulated')); } + if (this._shot.simulate.close) { + this.emit('close'); + } + if (this._shot.simulate.end !== false) { // 'end' defaults to true this.push(null); } }); } + + destroy() { + + } }; diff --git a/lib/response.js b/lib/response.js index 5c97956..9678e23 100755 --- a/lib/response.js +++ b/lib/response.js @@ -82,6 +82,10 @@ exports = module.exports = internals.Response = class extends Http.ServerRespons this.emit('finish'); } + destroy() { + + } + addTrailers(trailers) { for (const key in trailers) { diff --git a/test/index.js b/test/index.js index f2a8724..3393523 100755 --- a/test/index.js +++ b/test/index.js @@ -562,25 +562,6 @@ describe('_read()', () => { expect(res.payload).to.equal(body); }); - it('supports async iteration', async () => { - - const dispatch = async function (req, res) { - - let buffer = ''; - for await (const chunk of req) { - buffer = buffer + chunk.toString(); - } - - res.writeHead(200, { 'Content-Length': 0 }); - res.end(buffer); - req.destroy(); - }; - - const body = 'something special just for you'; - const res = await Shot.inject(dispatch, { method: 'get', url: '/', payload: body }); - expect(res.payload).to.equal(body); - }); - it('simulates split', async () => { const dispatch = function (req, res) {