Skip to content

Commit

Permalink
chore: Fix testing of koa-router
Browse files Browse the repository at this point in the history
  • Loading branch information
jsumners-nr committed Sep 16, 2024
1 parent 5e6825b commit 766af75
Show file tree
Hide file tree
Showing 2 changed files with 11 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
24 changes: 9 additions & 15 deletions test/versioned/koa/router-common.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ module.exports = (pkg) => {
}

function tearDown(t) {
t.context.server.close()
if (t.context.server) {
// t.context.server is defined by `run(t.context)`.
t.context.server.close()
}
helper.unloadAgent(t.context.agent)
}

Expand Down Expand Up @@ -148,18 +151,18 @@ 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) {
router.get('/:first/{*any}', 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/{*any}',
['Koa/Router: /', ['Nodejs/Middleware/Koa/firstMiddleware//:first/{*any}']]
])
t.equal(
tx.name,
'WebTransaction/WebFrameworkUri/Koa/GET//:first/(.*)',
'WebTransaction/WebFrameworkUri/Koa/GET//:first/{*any}',
'transaction should be named after the matched regex path'
)
t.end()
Expand Down Expand Up @@ -346,16 +349,7 @@ module.exports = (pkg) => {
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: /', ['Nodejs/Middleware/Koa/terminalMiddleware//:second']]
])
t.equal(
tx.name,
Expand Down

0 comments on commit 766af75

Please sign in to comment.