Skip to content

Commit

Permalink
test: Updated koa-router to tests to handle bug fixes from 13.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
bizob2828 committed Sep 16, 2024
1 parent 0db6599 commit 72cf908
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
4 changes: 2 additions & 2 deletions test/versioned/koa/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"samples": 5
},
"koa-router": {
"versions": ">=11.0.2 && <13.0.0",
"versions": ">=11.0.2",
"samples": 5
}
},
Expand All @@ -53,7 +53,7 @@
"samples": 5
},
"@koa/router": {
"versions": ">=11.0.2 && <13.0.0",
"versions": ">=11.0.2",
"samples": 5
}
},
Expand Down
35 changes: 20 additions & 15 deletions test/versioned/koa/router-common.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ module.exports = (pkg) => {
}

function tearDown(t) {
t.context.server.close()
t.context?.server?.close()
helper.unloadAgent(t.context.agent)
}

Expand Down Expand Up @@ -148,18 +148,22 @@ module.exports = (pkg) => {

t.test('should name and produce segments for matched wildcard path', (t) => {
const { agent, router, app } = t.context
router.get('/:first/(.*)', function firstMiddleware(ctx) {
let path = '(.*)'
if (semver.gte(pkgVersion, '13.0.1')) {
path = '{*any}'
}
router.get(`/:first/${path}`, function firstMiddleware(ctx) {
ctx.body = 'first'
})
app.use(router.routes())
agent.on('transactionFinished', (tx) => {
t.assertSegments(tx.trace.root, [
'WebTransaction/WebFrameworkUri/Koa/GET//:first/(.*)',
['Koa/Router: /', ['Nodejs/Middleware/Koa/firstMiddleware//:first/(.*)']]
`WebTransaction/WebFrameworkUri/Koa/GET//:first/${path}`,
['Koa/Router: /', [`Nodejs/Middleware/Koa/firstMiddleware//:first/${path}`]]
])
t.equal(
tx.name,
'WebTransaction/WebFrameworkUri/Koa/GET//:first/(.*)',
`WebTransaction/WebFrameworkUri/Koa/GET//:first/${path}`,
'transaction should be named after the matched regex path'
)
t.end()
Expand Down Expand Up @@ -342,20 +346,21 @@ module.exports = (pkg) => {
router.get('/:second', function terminalMiddleware(ctx) {
ctx.body = ' second'
})

const segmentTree = semver.gte(pkgVersion, '13.0.1')
? ['Nodejs/Middleware/Koa/terminalMiddleware//:second']
: [
'Nodejs/Middleware/Koa/secondMiddleware//:first',
[
'Nodejs/Middleware/Koa/secondMiddleware//:second',
['Nodejs/Middleware/Koa/terminalMiddleware//:second']
]
]
app.use(router.routes())
agent.on('transactionFinished', (tx) => {
t.assertSegments(tx.trace.root, [
'WebTransaction/WebFrameworkUri/Koa/GET//:second',
[
'Koa/Router: /',
[
'Nodejs/Middleware/Koa/secondMiddleware//:first',
[
'Nodejs/Middleware/Koa/secondMiddleware//:second',
['Nodejs/Middleware/Koa/terminalMiddleware//:second']
]
]
]
['Koa/Router: /', segmentTree]
])
t.equal(
tx.name,
Expand Down

0 comments on commit 72cf908

Please sign in to comment.