Skip to content

Commit 45378d7

Browse files
uurienwatson
authored andcommitted
Do not test koa 1.x middleware signature in koa 3.x (#5623)
* 1.x middleware signature is not supported in koa >3 * Fix lint
1 parent fc00908 commit 45378d7

File tree

1 file changed

+64
-60
lines changed

1 file changed

+64
-60
lines changed

packages/datadog-plugin-koa/test/index.spec.js

Lines changed: 64 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ describe('Plugin', () => {
1414
let appListener
1515

1616
describe('koa', () => {
17-
withVersions('koa', 'koa', version => {
17+
withVersions('koa', 'koa', (version, _, realVersion) => {
1818
beforeEach(() => {
1919
tracer = require('../../dd-trace')
2020
Koa = require(`../../../versions/koa@${version}`).get()
@@ -79,44 +79,46 @@ describe('Plugin', () => {
7979
})
8080
})
8181

82-
it('should do automatic instrumentation on 1.x middleware', done => {
83-
const app = new Koa()
82+
if (semver.satisfies(realVersion, '<3')) {
83+
it('should do automatic instrumentation on 1.x middleware', done => {
84+
const app = new Koa()
8485

85-
app.use(function * handle (next) {
86-
this.body = ''
87-
yield next
88-
})
86+
app.use(function * handle (next) {
87+
this.body = ''
88+
yield next
89+
})
8990

90-
appListener = app.listen(0, 'localhost', () => {
91-
const port = appListener.address().port
91+
appListener = app.listen(0, 'localhost', () => {
92+
const port = appListener.address().port
9293

93-
agent
94-
.use(traces => {
95-
const spans = sort(traces[0])
94+
agent
95+
.use(traces => {
96+
const spans = sort(traces[0])
9697

97-
expect(spans[0]).to.have.property('name', 'koa.request')
98-
expect(spans[0]).to.have.property('service', 'test')
99-
expect(spans[0]).to.have.property('type', 'web')
100-
expect(spans[0]).to.have.property('resource', 'GET')
101-
expect(spans[0].meta).to.have.property('span.kind', 'server')
102-
expect(spans[0].meta).to.have.property('http.url', `http://localhost:${port}/user`)
103-
expect(spans[0].meta).to.have.property('http.method', 'GET')
104-
expect(spans[0].meta).to.have.property('http.status_code', '200')
105-
expect(spans[0].meta).to.have.property('component', 'koa')
98+
expect(spans[0]).to.have.property('name', 'koa.request')
99+
expect(spans[0]).to.have.property('service', 'test')
100+
expect(spans[0]).to.have.property('type', 'web')
101+
expect(spans[0]).to.have.property('resource', 'GET')
102+
expect(spans[0].meta).to.have.property('span.kind', 'server')
103+
expect(spans[0].meta).to.have.property('http.url', `http://localhost:${port}/user`)
104+
expect(spans[0].meta).to.have.property('http.method', 'GET')
105+
expect(spans[0].meta).to.have.property('http.status_code', '200')
106+
expect(spans[0].meta).to.have.property('component', 'koa')
106107

107-
expect(spans[1]).to.have.property('name', 'koa.middleware')
108-
expect(spans[1]).to.have.property('service', 'test')
109-
expect(spans[1]).to.have.property('resource', 'converted')
110-
expect(spans[1].meta).to.have.property('component', 'koa')
111-
})
112-
.then(done)
113-
.catch(done)
108+
expect(spans[1]).to.have.property('name', 'koa.middleware')
109+
expect(spans[1]).to.have.property('service', 'test')
110+
expect(spans[1]).to.have.property('resource', 'converted')
111+
expect(spans[1].meta).to.have.property('component', 'koa')
112+
})
113+
.then(done)
114+
.catch(done)
114115

115-
axios
116-
.get(`http://localhost:${port}/user`)
117-
.catch(done)
116+
axios
117+
.get(`http://localhost:${port}/user`)
118+
.catch(done)
119+
})
118120
})
119-
})
121+
}
120122

121123
it('should run middleware in the request scope', done => {
122124
const app = new Koa()
@@ -756,41 +758,43 @@ describe('Plugin', () => {
756758
})
757759
})
758760

759-
it('should not do automatic instrumentation on 1.x middleware', done => {
760-
const app = new Koa()
761+
if (semver.satisfies(realVersion, '<3')) {
762+
it('should not do automatic instrumentation on 1.x middleware', done => {
763+
const app = new Koa()
761764

762-
app.use(function * handle (next) {
763-
this.body = ''
764-
yield next
765-
})
765+
app.use(function * handle (next) {
766+
this.body = ''
767+
yield next
768+
})
766769

767-
appListener = app.listen(0, 'localhost', () => {
768-
const port = appListener.address().port
770+
appListener = app.listen(0, 'localhost', () => {
771+
const port = appListener.address().port
769772

770-
agent
771-
.use(traces => {
772-
const spans = sort(traces[0])
773+
agent
774+
.use(traces => {
775+
const spans = sort(traces[0])
773776

774-
expect(spans[0]).to.have.property('name', 'koa.request')
775-
expect(spans[0]).to.have.property('service', 'test')
776-
expect(spans[0]).to.have.property('type', 'web')
777-
expect(spans[0]).to.have.property('resource', 'GET')
778-
expect(spans[0].meta).to.have.property('span.kind', 'server')
779-
expect(spans[0].meta).to.have.property('http.url', `http://localhost:${port}/user`)
780-
expect(spans[0].meta).to.have.property('http.method', 'GET')
781-
expect(spans[0].meta).to.have.property('http.status_code', '200')
782-
expect(spans[0].meta).to.have.property('component', 'koa')
777+
expect(spans[0]).to.have.property('name', 'koa.request')
778+
expect(spans[0]).to.have.property('service', 'test')
779+
expect(spans[0]).to.have.property('type', 'web')
780+
expect(spans[0]).to.have.property('resource', 'GET')
781+
expect(spans[0].meta).to.have.property('span.kind', 'server')
782+
expect(spans[0].meta).to.have.property('http.url', `http://localhost:${port}/user`)
783+
expect(spans[0].meta).to.have.property('http.method', 'GET')
784+
expect(spans[0].meta).to.have.property('http.status_code', '200')
785+
expect(spans[0].meta).to.have.property('component', 'koa')
783786

784-
expect(spans).to.have.length(1)
785-
})
786-
.then(done)
787-
.catch(done)
787+
expect(spans).to.have.length(1)
788+
})
789+
.then(done)
790+
.catch(done)
788791

789-
axios
790-
.get(`http://localhost:${port}/user`)
791-
.catch(done)
792+
axios
793+
.get(`http://localhost:${port}/user`)
794+
.catch(done)
795+
})
792796
})
793-
})
797+
}
794798

795799
it('should run middleware in the request scope', done => {
796800
const app = new Koa()

0 commit comments

Comments
 (0)