Skip to content

Commit 0329fdf

Browse files
authored
test: load helpers directly instead of using globals (#5962)
* test: load helpers directly instead of using globals As drive-by also import a couple of Node.js modules with the explicit `node:` prefix. That makes it clear it is a Node.js module that is loaded. The benefit over loading the helpers directly is that it allows to read the API in an IDE and to jump to the code directly. * test: make peer service test robuster The test could have failed with two done calls. This is now resolved by stricter checking if the called method is a promise or a callback based one. Those calls are awaited before finishing the test.
1 parent f6fcf98 commit 0329fdf

File tree

48 files changed

+187
-99
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+187
-99
lines changed

eslint.config.mjs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,6 @@ export default [
196196
expect: 'readonly',
197197
proxyquire: 'readonly',
198198
withVersions: 'readonly',
199-
withPeerService: 'readonly',
200-
withNamingSchema: 'readonly',
201-
withExports: 'readonly'
202199
}
203200
},
204201
rules: {

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

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict'
22

3+
const { withNamingSchema, withPeerService, withVersions } = require('../../dd-trace/test/setup/mocha')
34
const agent = require('../../dd-trace/test/plugins/agent')
45
const { ERROR_MESSAGE, ERROR_TYPE, ERROR_STACK } = require('../../dd-trace/src/constants')
56
const { expectedSchema, rawExpectedSchema } = require('./naming')
@@ -53,10 +54,11 @@ describe('Plugin', () => {
5354
withPeerService(
5455
() => tracer,
5556
'aerospike',
56-
() => aerospike.connect(config).then(client => {
57-
return client.put(key, { i: 123 })
58-
.then(() => client.close(false))
59-
}),
57+
async () => {
58+
const client = await aerospike.connect(config)
59+
await client.put(key, { i: 123 })
60+
return client.close(false)
61+
},
6062
'test',
6163
'aerospike.namespace'
6264
)
@@ -284,10 +286,11 @@ describe('Plugin', () => {
284286
})
285287
})
286288
withNamingSchema(
287-
() => aerospike.connect(config).then(client => {
288-
return client.put(key, { i: 123 })
289-
.then(() => client.close(false))
290-
}),
289+
async () => {
290+
const client = await aerospike.connect(config)
291+
await client.put(key, { i: 123 })
292+
return client.close(false)
293+
},
291294
rawExpectedSchema.command
292295
)
293296
})
@@ -318,10 +321,11 @@ describe('Plugin', () => {
318321
})
319322

320323
withNamingSchema(
321-
() => aerospike.connect(config).then(client => {
322-
return client.put(key, { i: 123 })
323-
.then(() => client.close(false))
324-
}),
324+
async () => {
325+
const client = await aerospike.connect(config)
326+
await client.put(key, { i: 123 })
327+
return client.close(false)
328+
},
325329
{
326330
v0: {
327331
opName: 'aerospike.command',

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict'
22

3+
const { withNamingSchema, withPeerService, withVersions } = require('../../dd-trace/test/setup/mocha')
34
const agent = require('../../dd-trace/test/plugins/agent')
45
const { ERROR_MESSAGE, ERROR_STACK, ERROR_TYPE } = require('../../dd-trace/src/constants')
56

@@ -64,7 +65,10 @@ describe('Plugin', () => {
6465
withPeerService(
6566
() => tracer,
6667
'amqp10',
67-
() => sender.send({ key: 'value' }),
68+
(done) => {
69+
sender.send({ key: 'value' })
70+
done()
71+
},
6872
'localhost',
6973
'out.host'
7074
)

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict'
22

3+
const { withNamingSchema, withPeerService, withVersions } = require('../../dd-trace/test/setup/mocha')
34
const agent = require('../../dd-trace/test/plugins/agent')
45
const { ERROR_MESSAGE, ERROR_STACK, ERROR_TYPE } = require('../../dd-trace/src/constants')
56
const id = require('../../dd-trace/src/id')
@@ -60,7 +61,7 @@ describe('Plugin', () => {
6061
withPeerService(
6162
() => tracer,
6263
'amqplib',
63-
() => channel.assertQueue(queue, {}, () => {}),
64+
(done) => channel.assertQueue(queue, {}, done),
6465
'localhost',
6566
'out.host'
6667
)
@@ -138,7 +139,7 @@ describe('Plugin', () => {
138139
withPeerService(
139140
() => tracer,
140141
'amqplib',
141-
() => channel.assertQueue(queue, {}, () => {}),
142+
(done) => channel.assertQueue(queue, {}, done),
142143
'localhost',
143144
'out.host'
144145
)

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict'
22

33
const { expect } = require('chai')
4+
const { withNamingSchema, withVersions } = require('../../dd-trace/test/setup/mocha')
45
const agent = require('../../dd-trace/test/plugins/agent.js')
56
const { ERROR_MESSAGE, ERROR_TYPE, ERROR_STACK } = require('../../dd-trace/src/constants.js')
67
const { expectedSchema, rawExpectedSchema } = require('./naming.js')
@@ -443,14 +444,12 @@ describe('Plugin', () => {
443444
})
444445

445446
withNamingSchema(
446-
() => {
447+
async () => {
447448
const operationName = 'MyQuery'
448449
const source = `query ${operationName} { hello(name: "world") }`
449450
const variableValues = { who: 'world' }
450-
gateway()
451-
.then(({ executor }) => {
452-
return execute(executor, source, variableValues, operationName).then(() => {})
453-
})
451+
const { executor } = await gateway()
452+
return execute(executor, source, variableValues, operationName)
454453
},
455454
rawExpectedSchema.server,
456455
{

packages/datadog-plugin-aws-sdk/test/kinesis.spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
'use strict'
33

44
const sinon = require('sinon')
5+
const { withNamingSchema, withVersions } = require('../../dd-trace/test/setup/mocha')
56
const agent = require('../../dd-trace/test/plugins/agent')
67
const { setup } = require('./spec_helpers')
78
const helpers = require('./kinesis_helpers')

packages/datadog-plugin-aws-sdk/test/lambda.spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict'
22

33
const JSZip = require('jszip')
4+
const { withNamingSchema, withVersions } = require('../../dd-trace/test/setup/mocha')
45
const agent = require('../../dd-trace/test/plugins/agent')
56
const { setup } = require('./spec_helpers')
67
const { rawExpectedSchema } = require('./lambda-naming')

packages/datadog-plugin-aws-sdk/test/s3.spec.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict'
22

3+
const { withNamingSchema, withPeerService, withVersions } = require('../../dd-trace/test/setup/mocha')
34
const agent = require('../../dd-trace/test/plugins/agent')
45
const { setup } = require('./spec_helpers')
56
const axios = require('axios')
@@ -62,7 +63,7 @@ describe('Plugin', () => {
6263
Bucket: bucketName,
6364
Key: 'test-key',
6465
Body: 'test body'
65-
}, (err) => err && done(err)),
66+
}, done),
6667
bucketName, 'bucketname')
6768

6869
withNamingSchema(

packages/datadog-plugin-aws-sdk/test/sns.spec.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
const sinon = require('sinon')
55
const semver = require('semver')
6+
const { withNamingSchema, withPeerService, withVersions } = require('../../dd-trace/test/setup/mocha')
67
const agent = require('../../dd-trace/test/plugins/agent')
78
const { setup } = require('./spec_helpers')
89
const { rawExpectedSchema } = require('./sns-naming')
@@ -354,7 +355,7 @@ describe('Sns', function () {
354355
(done) => sns.publish({
355356
TopicArn,
356357
Message: 'message 1'
357-
}, (err) => err && done()),
358+
}, done),
358359
'TestTopic', 'topicname')
359360

360361
withNamingSchema(

packages/datadog-plugin-aws-sdk/test/sqs.spec.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict'
22

33
const sinon = require('sinon')
4+
const { withNamingSchema, withPeerService, withVersions } = require('../../dd-trace/test/setup/mocha')
45
const agent = require('../../dd-trace/test/plugins/agent')
56
const { setup } = require('./spec_helpers')
67
const semver = require('semver')
@@ -73,7 +74,7 @@ describe('Plugin', () => {
7374
(done) => sqs.sendMessage({
7475
MessageBody: 'test body',
7576
QueueUrl
76-
}, (err) => err && done(err)),
77+
}, done),
7778
'SQS_QUEUE_NAME',
7879
'queuename'
7980
)

0 commit comments

Comments
 (0)