Skip to content

Commit

Permalink
remove most usage of get-port for plugin tests (#4429)
Browse files Browse the repository at this point in the history
* remove most usage of get-port for plugins

* remove get-port from instrumentation tests

* fix new test
  • Loading branch information
rochdev authored and juan-fernandez committed Jul 10, 2024
1 parent 7a85bdf commit 07457c6
Show file tree
Hide file tree
Showing 24 changed files with 1,487 additions and 1,622 deletions.
9 changes: 3 additions & 6 deletions packages/datadog-instrumentations/test/body-parser.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict'

const getPort = require('get-port')
const dc = require('dc-polyfill')
const axios = require('axios')
const agent = require('../../dd-trace/test/plugins/agent')
Expand All @@ -22,11 +21,9 @@ withVersions('body-parser', 'body-parser', version => {
middlewareProcessBodyStub()
res.end('DONE')
})
getPort().then(newPort => {
port = newPort
server = app.listen(port, () => {
done()
})
server = app.listen(0, () => {
port = server.address().port
done()
})
})
beforeEach(async () => {
Expand Down
9 changes: 3 additions & 6 deletions packages/datadog-instrumentations/test/cookie-parser.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict'

const { assert } = require('chai')
const getPort = require('get-port')
const dc = require('dc-polyfill')
const axios = require('axios')
const agent = require('../../dd-trace/test/plugins/agent')
Expand All @@ -23,11 +22,9 @@ withVersions('cookie-parser', 'cookie-parser', version => {
middlewareProcessCookieStub()
res.end('DONE')
})
getPort().then(newPort => {
port = newPort
server = app.listen(port, () => {
done()
})
server = app.listen(0, () => {
port = server.address().port
done()
})
})
beforeEach(async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict'

const agent = require('../../dd-trace/test/plugins/agent')
const getPort = require('get-port')
const { channel } = require('dc-polyfill')
const axios = require('axios')
describe('express-mongo-sanitize', () => {
Expand All @@ -25,11 +24,9 @@ describe('express-mongo-sanitize', () => {
res.end()
})

getPort().then(newPort => {
port = newPort
server = app.listen(port, () => {
done()
})
server = app.listen(0, () => {
port = server.address().port
done()
})
})

Expand Down
9 changes: 3 additions & 6 deletions packages/datadog-instrumentations/test/express.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict'

const agent = require('../../dd-trace/test/plugins/agent')
const getPort = require('get-port')
const axios = require('axios')
const dc = require('dc-polyfill')

Expand All @@ -20,11 +19,9 @@ withVersions('express', 'express', version => {
requestBody()
res.end('DONE')
})
getPort().then(newPort => {
port = newPort
server = app.listen(port, () => {
done()
})
server = app.listen(0, () => {
port = server.address().port
done()
})
})
beforeEach(async () => {
Expand Down
9 changes: 3 additions & 6 deletions packages/datadog-instrumentations/test/passport-http.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict'

const agent = require('../../dd-trace/test/plugins/agent')
const getPort = require('get-port')
const axios = require('axios')
const dc = require('dc-polyfill')

Expand Down Expand Up @@ -70,11 +69,9 @@ withVersions('passport-http', 'passport-http', version => {
subscriberStub(arguments[0])
})

getPort().then(newPort => {
port = newPort
server = app.listen(port, () => {
done()
})
server = app.listen(0, () => {
port = server.address().port
done()
})
})
beforeEach(() => {
Expand Down
9 changes: 3 additions & 6 deletions packages/datadog-instrumentations/test/passport-local.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict'

const agent = require('../../dd-trace/test/plugins/agent')
const getPort = require('get-port')
const axios = require('axios')
const dc = require('dc-polyfill')

Expand Down Expand Up @@ -71,11 +70,9 @@ withVersions('passport-local', 'passport-local', version => {
subscriberStub(arguments[0])
})

getPort().then(newPort => {
port = newPort
server = app.listen(port, () => {
done()
})
server = app.listen(0, () => {
port = server.address().port
done()
})
})
beforeEach(() => {
Expand Down
13 changes: 7 additions & 6 deletions packages/datadog-plugin-apollo/test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const agent = require('../../dd-trace/test/plugins/agent.js')
const { ERROR_MESSAGE, ERROR_TYPE, ERROR_STACK } = require('../../dd-trace/src/constants.js')
const { expectedSchema, rawExpectedSchema } = require('./naming.js')
const axios = require('axios')
const getPort = require('get-port')

const accounts = require('./fixtures.js')

Expand Down Expand Up @@ -86,13 +85,15 @@ describe('Plugin', () => {
gateway: setupGateway(),
subscriptions: false // Disable subscriptions (not supported with Apollo Gateway)
})
getPort().then(newPort => {
port = newPort
startStandaloneServer(server, {
listen: { port }
}).then(() => {})

return startStandaloneServer(server, {
listen: { port: 0 }
}).then(({ url }) => {
port = new URL(url).port
})
})

before(() => {
return agent.load('apollo')
})

Expand Down
Loading

0 comments on commit 07457c6

Please sign in to comment.