Skip to content
This repository has been archived by the owner on Apr 24, 2024. It is now read-only.

Commit

Permalink
test(koa-router): add test using router prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Svetlichny committed Apr 17, 2019
1 parent e84f4aa commit 4493aab
Showing 1 changed file with 44 additions and 2 deletions.
46 changes: 44 additions & 2 deletions tests/versioned/koa-router.tap.js
Original file line number Diff line number Diff line change
Expand Up @@ -465,10 +465,10 @@ tap.test('koa-router instrumentation', (t) => {

const nestedRouter = new Router()
nestedRouter.get('/:second', function terminalMiddleware(ctx) {
ctx.body = 'want this to set the name'
ctx.body = 'this is a test'
})
nestedRouter.get('/second', function secondMiddleware(ctx) {
ctx.body = 'this is a test'
ctx.body = 'want this to set the name'
})
router.use('/:first', nestedRouter.routes())
app.use(router.routes())
Expand Down Expand Up @@ -499,6 +499,48 @@ tap.test('koa-router instrumentation', (t) => {
run('/123/second')
})

t.test('app-level middleware should not rename tx from prefixed router', (t) => {
app.use(function appLevelMiddleware(ctx, next) {
return next().then(() => {
ctx.body = 'do not want this to set the name'
})
})

router.get('/:second', function terminalMiddleware(ctx) {
ctx.body = 'this is a test'
})
router.get('/second', function secondMiddleware(ctx) {
ctx.body = 'want this to set the name'
})
router.prefix('/:first')
app.use(router.routes())

helper.agent.on('transactionFinished', (tx) => {
t.exactSegments(
tx.trace.root, [{
name: 'WebTransaction/WebFrameworkUri/Koa/GET//:first/second',
children: [{
name: 'Nodejs/Middleware/Koa/appLevelMiddleware',
children: [{
name: 'Koa/Router: /',
children: [{
name: 'Nodejs/Middleware/Koa/terminalMiddleware//:first/:second'
}]
}]
}]
}],
'should have expected segments'
)
t.equal(
tx.name,
'WebTransaction/WebFrameworkUri/Koa/GET//:first/second',
'should be named after the middleware responsible for originally responding'
)
t.end()
})
run('/123/second')
})

t.autoend()

function run(path) {
Expand Down

0 comments on commit 4493aab

Please sign in to comment.