Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Fix testing of koa-router #2576

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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']]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this breaks older versions of koa, was this something that changed in behavior with newer versions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the original behavior?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current version of koa is still at 2 ☹️

])
t.equal(
tx.name,
Expand Down
Loading