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 }} 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" } } 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) => {