Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed failing test and added other test branch #65

Merged
merged 3 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
41 changes: 33 additions & 8 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand All @@ -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) => {
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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) => {
Expand Down
Loading