From 252dcce0afc8db2549389c3a77e3677818dc5cf0 Mon Sep 17 00:00:00 2001 From: big-kahuna-burger Date: Fri, 10 Nov 2023 01:24:12 +0100 Subject: [PATCH 1/3] test: add extra test to res.flushHeaders behaviour --- test.js | 41 +++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/test.js b/test.js index 128559d..5bb1dae 100644 --- a/test.js +++ b/test.js @@ -38,6 +38,11 @@ function doGet (server) { http.get('http://' + address.address + ':' + address.port) } +function doGetError (server) { + const address = server.address() + http.get('http://' + address.address + ':' + address.port + '/error') +} + test('default settings', function (t) { const dest = split(JSON.parse) const logger = pinoLogger(dest) @@ -120,13 +125,13 @@ test('supports errors in the response', function (t) { const app = setup(t, logger, function (err, server) { t.error(err) - const address = server.address() - http.get('http://' + address.address + ':' + address.port + '/error') + doGetError(server) }) app.use((ctx, next) => { if (ctx.request.url === '/error') { ctx.body = '' + ctx.res.flushHeaders() ctx.res.emit('error', Error('boom!')) } return next() @@ -143,14 +148,36 @@ test('supports errors in the response', function (t) { }) }) +test('status code will be null if headers are not flushed in response', function (t) { + t.plan(2) + const dest = split(JSON.parse) + const logger = pinoLogger(dest) + + const app = setup(t, logger, function (err, server) { + t.error(err) + doGetError(server) + }) + + app.use((ctx, next) => { + if (ctx.request.url === '/error') { + ctx.body = '' + ctx.res.emit('error', Error('boom!')) + } + return next() + }) + + dest.on('data', function (line) { + t.equal(line.res.statusCode, null, 'statusCode is null') + }) +}) + test('supports errors in the middleware', function (t) { const dest = split(JSON.parse) const logger = pinoLogger(dest) const app = setup(t, logger, function (err, server) { t.error(err) - const address = server.address() - http.get('http://' + address.address + ':' + address.port + '/error') + doGetError(server) }) app.use((ctx, next) => { @@ -183,8 +210,7 @@ test('does not inhibit downstream error handling', function (t) { const app = setup(t, logger, function (err, server) { t.error(err) - const address = server.address() - http.get('http://' + address.address + ':' + address.port + '/error') + doGetError(server) }) app.use((ctx, next) => { @@ -222,8 +248,7 @@ test('work with error reporting middlewares', function (t) { const app = setup(t, [reporter, logger], function (err, server) { t.error(err) - const address = server.address() - http.get('http://' + address.address + ':' + address.port + '/error') + doGetError(server) }) app.use((ctx, next) => { From b86603d6acca5ab4f983f5c327c16f7b8698129d Mon Sep 17 00:00:00 2001 From: big-kahuna-burger Date: Fri, 10 Nov 2023 01:27:43 +0100 Subject: [PATCH 2/3] ci: stop testing for node versions < 18 --- .github/workflows/ci.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ac39b54..9fe9c06 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,10 +20,12 @@ jobs: fail-fast: false matrix: os: [macOS-latest, windows-latest, ubuntu-latest] - node-version: [14, 16, 18] + node-version: [18, 20] steps: - - uses: actions/checkout@v3 - - name: Use Node.js ${{ matrix.node-version }} + - name: Check out repo + uses: actions/checkout@v4 + + - name: Setup Node ${{ matrix.node-version }} uses: actions/setup-node@v3 with: node-version: ${{ matrix.node-version }} From 5aa0028e0f9d938a556a506f3cdc74daa322f3d3 Mon Sep 17 00:00:00 2001 From: big-kahuna-burger Date: Fri, 10 Nov 2023 01:37:03 +0100 Subject: [PATCH 3/3] deps: point to pino-http (next), bump dev deps --- package.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index d23a950..1b02725 100644 --- a/package.json +++ b/package.json @@ -24,15 +24,15 @@ }, "homepage": "https://github.com/davidmarkclements/koa-pino-logger#readme", "dependencies": { - "pino-http": "^7.0.0" + "pino-http": "git+https://github.com/pinojs/pino-http.git#next" }, "devDependencies": { - "koa": "^2.13.1", + "koa": "^2.14.2", "koa-bunyan-logger": "^2.1.0", "koa-logger": "^3.2.1", "koa-morgan": "^1.0.1", - "split2": "^4.1.0", - "standard": "^17.0.0", - "tap": "^16.0.0" + "split2": "^4.2.0", + "standard": "^17.1.0", + "tap": "^16.3.9" } }