Skip to content

Commit 4aa485c

Browse files
chargomeclaude
andauthored
test(node): Run koa integration tests against koa 3 (#24457)
Koa instrumentation already declares `>=2.0.0 <4` and hooks nothing that changed in Koa 3, but only Koa 2 was tested, so the integration suite now runs against both majors. Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
1 parent c94fd11 commit 4aa485c

1 file changed

Lines changed: 82 additions & 71 deletions

File tree

  • dev-packages/node-integration-tests/suites/tracing/koa

dev-packages/node-integration-tests/suites/tracing/koa/test.ts

Lines changed: 82 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -29,81 +29,92 @@ describe('koa auto-instrumentation', () => {
2929
},
3030
};
3131

32-
createEsmAndCjsTests(__dirname, 'scenario.mjs', 'instrument.mjs', (createRunner, test) => {
33-
test('should auto-instrument `koa` router and middleware layers.', async () => {
34-
const runner = createRunner()
35-
.expect({
36-
span: container => {
37-
expect(container.items.find(item => item.is_segment)?.name).toBe('GET /');
32+
describe.each([
33+
['v2', {}],
34+
['v3', { koa: '^3.0.0' }],
35+
])('%s', (_version, additionalDependencies) => {
36+
createEsmAndCjsTests(
37+
__dirname,
38+
'scenario.mjs',
39+
'instrument.mjs',
40+
(createRunner, test) => {
41+
test('should auto-instrument `koa` router and middleware layers.', async () => {
42+
const runner = createRunner()
43+
.expect({
44+
span: container => {
45+
expect(container.items.find(item => item.is_segment)?.name).toBe('GET /');
3846

39-
// Router layer span (from `@koa/router`), carrying the matched route.
40-
expect(container.items).toContainEqual(
41-
expect.objectContaining({
42-
name: '/',
43-
attributes: expect.objectContaining({
44-
'http.route': { type: 'string', value: '/' },
45-
'koa.type': { type: 'string', value: 'router' },
46-
'sentry.op': { type: 'string', value: 'router' },
47-
'sentry.origin': { type: 'string', value: origin },
48-
}),
49-
}),
50-
);
47+
// Router layer span (from `@koa/router`), carrying the matched route.
48+
expect(container.items).toContainEqual(
49+
expect.objectContaining({
50+
name: '/',
51+
attributes: expect.objectContaining({
52+
'http.route': { type: 'string', value: '/' },
53+
'koa.type': { type: 'string', value: 'router' },
54+
'sentry.op': { type: 'string', value: 'router' },
55+
'sentry.origin': { type: 'string', value: origin },
56+
}),
57+
}),
58+
);
5159

52-
// Plain middleware span.
53-
expect(container.items).toContainEqual(
54-
expect.objectContaining({
55-
name: 'simpleMiddleware',
56-
attributes: expect.objectContaining({
57-
'koa.type': { type: 'string', value: 'middleware' },
58-
'code.function.name': { type: 'string', value: 'simpleMiddleware' },
59-
'sentry.op': { type: 'string', value: 'middleware' },
60-
'sentry.origin': { type: 'string', value: origin },
61-
}),
62-
}),
63-
);
64-
},
65-
})
66-
.start();
67-
runner.makeRequest('get', '/');
68-
await runner.completed();
69-
});
60+
// Plain middleware span.
61+
expect(container.items).toContainEqual(
62+
expect.objectContaining({
63+
name: 'simpleMiddleware',
64+
attributes: expect.objectContaining({
65+
'koa.type': { type: 'string', value: 'middleware' },
66+
'code.function.name': { type: 'string', value: 'simpleMiddleware' },
67+
'sentry.op': { type: 'string', value: 'middleware' },
68+
'sentry.origin': { type: 'string', value: origin },
69+
}),
70+
}),
71+
);
72+
},
73+
})
74+
.start();
75+
runner.makeRequest('get', '/');
76+
await runner.completed();
77+
});
7078

71-
test('should assign a parameterized segment name.', async () => {
72-
const runner = createRunner()
73-
.expect({
74-
span: container => {
75-
expect(container.items.find(item => item.is_segment)?.name).toBe('GET /test-param/:id');
79+
test('should assign a parameterized segment name.', async () => {
80+
const runner = createRunner()
81+
.expect({
82+
span: container => {
83+
expect(container.items.find(item => item.is_segment)?.name).toBe('GET /test-param/:id');
7684

77-
expect(container.items).toContainEqual(
78-
expect.objectContaining({
79-
name: '/test-param/:id',
80-
attributes: expect.objectContaining({
81-
'http.route': { type: 'string', value: '/test-param/:id' },
82-
'koa.type': { type: 'string', value: 'router' },
83-
'sentry.op': { type: 'string', value: 'router' },
84-
'sentry.origin': { type: 'string', value: origin },
85-
}),
86-
}),
87-
);
88-
},
89-
})
90-
.start();
91-
runner.makeRequest('get', '/test-param/123');
92-
await runner.completed();
93-
});
85+
expect(container.items).toContainEqual(
86+
expect.objectContaining({
87+
name: '/test-param/:id',
88+
attributes: expect.objectContaining({
89+
'http.route': { type: 'string', value: '/test-param/:id' },
90+
'koa.type': { type: 'string', value: 'router' },
91+
'sentry.op': { type: 'string', value: 'router' },
92+
'sentry.origin': { type: 'string', value: origin },
93+
}),
94+
}),
95+
);
96+
},
97+
})
98+
.start();
99+
runner.makeRequest('get', '/test-param/123');
100+
await runner.completed();
101+
});
94102

95-
test('should capture errors thrown in routes via the koa error handler.', async () => {
96-
const runner = createRunner()
97-
.unordered()
98-
.expect({
99-
span: container => {
100-
expect(container.items.find(item => item.is_segment)?.name).toBe('GET /error');
101-
},
102-
})
103-
.expect({ event: EXPECTED_ERROR_EVENT })
104-
.start();
105-
runner.makeRequest('get', '/error', { expectError: true });
106-
await runner.completed();
107-
});
103+
test('should capture errors thrown in routes via the koa error handler.', async () => {
104+
const runner = createRunner()
105+
.unordered()
106+
.expect({
107+
span: container => {
108+
expect(container.items.find(item => item.is_segment)?.name).toBe('GET /error');
109+
},
110+
})
111+
.expect({ event: EXPECTED_ERROR_EVENT })
112+
.start();
113+
runner.makeRequest('get', '/error', { expectError: true });
114+
await runner.completed();
115+
});
116+
},
117+
{ additionalDependencies },
118+
);
108119
});
109120
});

0 commit comments

Comments
 (0)