diff --git a/dev-packages/node-integration-tests/suites/tracing/koa/test.ts b/dev-packages/node-integration-tests/suites/tracing/koa/test.ts index b1d8ded48e5b..4a9f99364a3a 100644 --- a/dev-packages/node-integration-tests/suites/tracing/koa/test.ts +++ b/dev-packages/node-integration-tests/suites/tracing/koa/test.ts @@ -29,81 +29,92 @@ describe('koa auto-instrumentation', () => { }, }; - createEsmAndCjsTests(__dirname, 'scenario.mjs', 'instrument.mjs', (createRunner, test) => { - test('should auto-instrument `koa` router and middleware layers.', async () => { - const runner = createRunner() - .expect({ - span: container => { - expect(container.items.find(item => item.is_segment)?.name).toBe('GET /'); + describe.each([ + ['v2', {}], + ['v3', { koa: '^3.0.0' }], + ])('%s', (_version, additionalDependencies) => { + createEsmAndCjsTests( + __dirname, + 'scenario.mjs', + 'instrument.mjs', + (createRunner, test) => { + test('should auto-instrument `koa` router and middleware layers.', async () => { + const runner = createRunner() + .expect({ + span: container => { + expect(container.items.find(item => item.is_segment)?.name).toBe('GET /'); - // Router layer span (from `@koa/router`), carrying the matched route. - expect(container.items).toContainEqual( - expect.objectContaining({ - name: '/', - attributes: expect.objectContaining({ - 'http.route': { type: 'string', value: '/' }, - 'koa.type': { type: 'string', value: 'router' }, - 'sentry.op': { type: 'string', value: 'router' }, - 'sentry.origin': { type: 'string', value: origin }, - }), - }), - ); + // Router layer span (from `@koa/router`), carrying the matched route. + expect(container.items).toContainEqual( + expect.objectContaining({ + name: '/', + attributes: expect.objectContaining({ + 'http.route': { type: 'string', value: '/' }, + 'koa.type': { type: 'string', value: 'router' }, + 'sentry.op': { type: 'string', value: 'router' }, + 'sentry.origin': { type: 'string', value: origin }, + }), + }), + ); - // Plain middleware span. - expect(container.items).toContainEqual( - expect.objectContaining({ - name: 'simpleMiddleware', - attributes: expect.objectContaining({ - 'koa.type': { type: 'string', value: 'middleware' }, - 'code.function.name': { type: 'string', value: 'simpleMiddleware' }, - 'sentry.op': { type: 'string', value: 'middleware' }, - 'sentry.origin': { type: 'string', value: origin }, - }), - }), - ); - }, - }) - .start(); - runner.makeRequest('get', '/'); - await runner.completed(); - }); + // Plain middleware span. + expect(container.items).toContainEqual( + expect.objectContaining({ + name: 'simpleMiddleware', + attributes: expect.objectContaining({ + 'koa.type': { type: 'string', value: 'middleware' }, + 'code.function.name': { type: 'string', value: 'simpleMiddleware' }, + 'sentry.op': { type: 'string', value: 'middleware' }, + 'sentry.origin': { type: 'string', value: origin }, + }), + }), + ); + }, + }) + .start(); + runner.makeRequest('get', '/'); + await runner.completed(); + }); - test('should assign a parameterized segment name.', async () => { - const runner = createRunner() - .expect({ - span: container => { - expect(container.items.find(item => item.is_segment)?.name).toBe('GET /test-param/:id'); + test('should assign a parameterized segment name.', async () => { + const runner = createRunner() + .expect({ + span: container => { + expect(container.items.find(item => item.is_segment)?.name).toBe('GET /test-param/:id'); - expect(container.items).toContainEqual( - expect.objectContaining({ - name: '/test-param/:id', - attributes: expect.objectContaining({ - 'http.route': { type: 'string', value: '/test-param/:id' }, - 'koa.type': { type: 'string', value: 'router' }, - 'sentry.op': { type: 'string', value: 'router' }, - 'sentry.origin': { type: 'string', value: origin }, - }), - }), - ); - }, - }) - .start(); - runner.makeRequest('get', '/test-param/123'); - await runner.completed(); - }); + expect(container.items).toContainEqual( + expect.objectContaining({ + name: '/test-param/:id', + attributes: expect.objectContaining({ + 'http.route': { type: 'string', value: '/test-param/:id' }, + 'koa.type': { type: 'string', value: 'router' }, + 'sentry.op': { type: 'string', value: 'router' }, + 'sentry.origin': { type: 'string', value: origin }, + }), + }), + ); + }, + }) + .start(); + runner.makeRequest('get', '/test-param/123'); + await runner.completed(); + }); - test('should capture errors thrown in routes via the koa error handler.', async () => { - const runner = createRunner() - .unordered() - .expect({ - span: container => { - expect(container.items.find(item => item.is_segment)?.name).toBe('GET /error'); - }, - }) - .expect({ event: EXPECTED_ERROR_EVENT }) - .start(); - runner.makeRequest('get', '/error', { expectError: true }); - await runner.completed(); - }); + test('should capture errors thrown in routes via the koa error handler.', async () => { + const runner = createRunner() + .unordered() + .expect({ + span: container => { + expect(container.items.find(item => item.is_segment)?.name).toBe('GET /error'); + }, + }) + .expect({ event: EXPECTED_ERROR_EVENT }) + .start(); + runner.makeRequest('get', '/error', { expectError: true }); + await runner.completed(); + }); + }, + { additionalDependencies }, + ); }); });