Skip to content

Commit 795babd

Browse files
tlindhardtTyson Lindhardt
authored andcommitted
Revert test changes to support 2.7.0+
1 parent 5d54143 commit 795babd

File tree

3 files changed

+39
-28
lines changed

3 files changed

+39
-28
lines changed

package-lock.json

Lines changed: 0 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/instrumentation-koa/.tav.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@
1313
koa:
1414
# Testing ^2.7.0 covers at least 97% of the downloaded koa versions
1515
versions:
16-
include: "^3.0.1"
16+
include: ">=2.7.0 <4"
1717
mode: latest-minors
1818
commands: npm run test

packages/instrumentation-koa/test/koa.test.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,11 @@ describe('Koa Instrumentation', function () {
144144
throw new Error('I failed!');
145145
};
146146

147+
const generatorMiddleware: () => koa.Middleware = () =>
148+
function* generatorMiddleware(next) {
149+
yield next;
150+
};
151+
147152
describe('Instrumenting @koa/router calls', function () {
148153
before(function () {
149154
if (!isrouterCompat) {
@@ -497,6 +502,39 @@ describe('Koa Instrumentation', function () {
497502
);
498503
});
499504

505+
it('should not instrument generator middleware functions', async function() {
506+
if (typeof (app as any).createAsyncCtxStorageMiddleware !== 'function') {
507+
this.skip()
508+
}
509+
510+
const rootSpan = tracer.startSpan('rootSpan');
511+
app.use((_ctx, next) =>
512+
context.with(trace.setSpan(context.active(), rootSpan), next)
513+
);
514+
515+
app.use(generatorMiddleware());
516+
app.use(simpleResponse());
517+
518+
await context.with(
519+
trace.setSpan(context.active(), rootSpan),
520+
async () => {
521+
await httpRequest.get(`http://localhost:${port}`);
522+
rootSpan.end();
523+
assert.deepStrictEqual(memoryExporter.getFinishedSpans().length, 2);
524+
525+
const simpleResponseSpan = memoryExporter
526+
.getFinishedSpans()
527+
.find(span => span.name.includes('simpleResponse'));
528+
assert.notStrictEqual(simpleResponseSpan, undefined);
529+
530+
const exportedRootSpan = memoryExporter
531+
.getFinishedSpans()
532+
.find(span => span.name === 'rootSpan');
533+
assert.notStrictEqual(exportedRootSpan, undefined);
534+
}
535+
);
536+
});
537+
500538
it('should not instrument the same middleware more than once', async () => {
501539
const sameAsyncMiddleware = asyncMiddleware();
502540

0 commit comments

Comments
 (0)