Skip to content

Commit

Permalink
Revert "test: Updated koa-router to tests to handle bug fixes from 13…
Browse files Browse the repository at this point in the history
….0.1 (newrelic#2578)"

This reverts commit 23e979c.
  • Loading branch information
sumitsuthar authored Sep 20, 2024
1 parent 343aea6 commit 5ec1368
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 22 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",
"versions": ">=11.0.2 && <13.0.0",
"samples": 5
}
},
Expand All @@ -53,7 +53,7 @@
"samples": 5
},
"@koa/router": {
"versions": ">=11.0.2",
"versions": ">=11.0.2 && <13.0.0",
"samples": 5
}
},
Expand Down
35 changes: 15 additions & 20 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,22 +148,18 @@ module.exports = (pkg) => {

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

0 comments on commit 5ec1368

Please sign in to comment.