diff --git a/test/versioned/koa/package.json b/test/versioned/koa/package.json index bee8c70660..50a1775d0f 100644 --- a/test/versioned/koa/package.json +++ b/test/versioned/koa/package.json @@ -34,7 +34,7 @@ "samples": 5 }, "koa-router": { - "versions": ">=11.0.2 && <13.0.0", + "versions": ">=11.0.2", "samples": 5 } }, @@ -53,7 +53,7 @@ "samples": 5 }, "@koa/router": { - "versions": ">=11.0.2 && <13.0.0", + "versions": ">=11.0.2", "samples": 5 } }, diff --git a/test/versioned/koa/router-common.js b/test/versioned/koa/router-common.js index 7927391e36..698531aec3 100644 --- a/test/versioned/koa/router-common.js +++ b/test/versioned/koa/router-common.js @@ -45,7 +45,7 @@ module.exports = (pkg) => { } function tearDown(t) { - t.context.server.close() + t.context?.server?.close() helper.unloadAgent(t.context.agent) } @@ -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() @@ -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,