From 76b3852aeb415bc0fc6d3997ac899fd36296fb8b Mon Sep 17 00:00:00 2001 From: Jonatan Nilsson Date: Mon, 11 Oct 2021 03:16:40 +0000 Subject: [PATCH] hopefully last fix for request ended logic --- flaska.mjs | 6 +++--- test/flaska.in.test.mjs | 9 +-------- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/flaska.mjs b/flaska.mjs index 7a43ff2..a0bd2d1 100644 --- a/flaska.mjs +++ b/flaska.mjs @@ -393,17 +393,17 @@ export class Flaska { req.on('error', (err) => { this._onreqerror(err, ctx) + this.requestEnded(ctx) }) res.on('error', (err) => { this._onreserror(err, ctx) }) - req.on('aborted', function() { + req.on('aborted', () => { ctx.aborted = true - }) - req.on('close', () => { this.requestEnded(ctx) }) + res.on('finish', () => { this.requestEnded(ctx) }) diff --git a/test/flaska.in.test.mjs b/test/flaska.in.test.mjs index 7584956..6d219da 100644 --- a/test/flaska.in.test.mjs +++ b/test/flaska.in.test.mjs @@ -22,7 +22,7 @@ t.describe('#requestStart()', function() { flaska.requestEnd = function(err, ctx) { try { assert.ok(err) - assert.strictEqual(assertReq.on.callCount, 3) + assert.strictEqual(assertReq.on.callCount, 2) assert.strictEqual(assertRes.on.callCount, 2) @@ -52,13 +52,6 @@ t.describe('#requestStart()', function() { assert.notStrictEqual(ctx.aborted, false) assertReq.on.secondCall[1]() assert.strictEqual(ctx.aborted, true) - - assert.strictEqual(assertReq.on.thirdCall[0], 'close') - assert.strictEqual(typeof(assertReq.on.thirdCall[1]), 'function') - assert.strictEqual(onEnded.callCount, 1) - assertReq.on.thirdCall[1]() - assert.strictEqual(onEnded.callCount, 2) - assert.strictEqual(onEnded.secondCall[0], ctx) // Test abort and close