Skip to content

Commit da07fea

Browse files
authored
chore(tests): added ESM test for light-my-request (#7433)
1 parent 09945cd commit da07fea

File tree

6 files changed

+110
-5
lines changed

6 files changed

+110
-5
lines changed

.github/workflows/apm-integrations.yml

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,16 @@ jobs:
154154
with:
155155
dd_api_key: ${{ secrets.DD_API_KEY }}
156156

157+
body-parser:
158+
runs-on: ubuntu-latest
159+
env:
160+
PLUGINS: body-parser
161+
steps:
162+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
163+
- uses: ./.github/actions/plugins/upstream
164+
with:
165+
dd_api_key: ${{ secrets.DD_API_KEY }}
166+
157167
bullmq:
158168
runs-on: ubuntu-latest
159169
services:
@@ -672,7 +682,7 @@ jobs:
672682
dd_api_key: ${{ secrets.DD_API_KEY }}
673683

674684
ldapjs:
675-
runs-on: 'ubuntu-latest'
685+
runs-on: ubuntu-latest
676686
env:
677687
PLUGINS: ldapjs
678688
steps:
@@ -681,6 +691,16 @@ jobs:
681691
with:
682692
dd_api_key: ${{ secrets.DD_API_KEY }}
683693

694+
light-my-request:
695+
runs-on: ubuntu-latest
696+
env:
697+
PLUGINS: 'light-my-request'
698+
steps:
699+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
700+
- uses: ./.github/actions/plugins/test
701+
with:
702+
dd_api_key: ${{ secrets.DD_API_KEY }}
703+
684704
limitd-client:
685705
runs-on: ubuntu-latest
686706
services:
@@ -702,7 +722,7 @@ jobs:
702722
dd_api_key: ${{ secrets.DD_API_KEY }}
703723

704724
lodash:
705-
runs-on: 'ubuntu-latest'
725+
runs-on: ubuntu-latest
706726
env:
707727
PLUGINS: lodash
708728
steps:
@@ -1057,6 +1077,16 @@ jobs:
10571077
api_key: ${{ secrets.DD_API_KEY }}
10581078
service: dd-trace-js-tests
10591079

1080+
passport-http:
1081+
runs-on: ubuntu-latest
1082+
env:
1083+
PLUGINS: passport-http
1084+
steps:
1085+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
1086+
- uses: ./.github/actions/plugins/test
1087+
with:
1088+
dd_api_key: ${{ secrets.DD_API_KEY }}
1089+
10601090
postgres:
10611091
runs-on: ubuntu-latest
10621092
services:
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
'use strict'
2+
3+
const assert = require('node:assert/strict')
4+
const {
5+
FakeAgent,
6+
sandboxCwd,
7+
useSandbox,
8+
checkSpansForServiceName,
9+
spawnPluginIntegrationTestProcAndExpectExit,
10+
varySandbox,
11+
} = require('../../../../integration-tests/helpers')
12+
const { withVersions } = require('../../../dd-trace/test/setup/mocha')
13+
14+
describe('esm', () => {
15+
let agent
16+
let proc
17+
let variants
18+
19+
withVersions('light-my-request', 'light-my-request', version => {
20+
useSandbox([`'light-my-request@${version}'`], false, [
21+
'./packages/datadog-plugin-light-my-request/test/integration-test/*'])
22+
23+
beforeEach(async () => {
24+
agent = await new FakeAgent().start()
25+
})
26+
27+
before(async function () {
28+
variants = varySandbox('server.mjs', 'inject', undefined, 'light-my-request')
29+
})
30+
31+
afterEach(async () => {
32+
proc && proc.kill()
33+
await agent.stop()
34+
})
35+
36+
for (const variant of varySandbox.VARIANTS) {
37+
it(`is instrumented ${variant}`, async () => {
38+
agent.assertMessageReceived(({ headers, payload }) => {
39+
assert.strictEqual(headers.host, `127.0.0.1:${agent.port}`)
40+
assert.ok(Array.isArray(payload))
41+
assert.strictEqual(checkSpansForServiceName(payload, 'mariadb.query'), true)
42+
})
43+
44+
proc = await spawnPluginIntegrationTestProcAndExpectExit(sandboxCwd(), variants[variant], agent.port)
45+
}).timeout(20000)
46+
}
47+
})
48+
})
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import 'dd-trace/init.js'
2+
import inject from 'light-my-request'
3+
import dc from 'dc-polyfill'
4+
5+
const startServerCh = dc.channel('apm:http:server:request:start')
6+
7+
let counter = 0
8+
startServerCh.subscribe(() => {
9+
counter += 1
10+
})
11+
12+
const dispatch = function (req, res) {
13+
const reply = JSON.stringify({ counter })
14+
res.writeHead(200, {
15+
'Content-Type': 'application/json',
16+
'Content-Length': reply.length,
17+
})
18+
res.end(reply)
19+
}
20+
21+
inject(dispatch, { method: 'GET', url: '/' }, (err, res) => {
22+
if (err) {
23+
process.exit(1)
24+
}
25+
process.exit(0)
26+
})

packages/datadog-plugin-passport-http/test/integration-test/client.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ withVersions('passport-http', 'passport-http', version => {
1515
['./packages/datadog-plugin-passport-http/test/integration-test/*'])
1616

1717
before(function () {
18-
variants = varySandbox('server.mjs', 'passport-http, BasicStrategy')
18+
variants = varySandbox('server.mjs', 'passportHttp', 'BasicStrategy', 'passport-http')
1919
})
2020

2121
beforeEach(async () => {

packages/datadog-plugin-passport-http/test/integration-test/server.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import 'dd-trace/init.js'
22
import express from 'express'
33
import passport from 'passport'
4-
import { BasicStrategy } from 'passport-http'
4+
import passportHttp from 'passport-http'
55
import dc from 'dc-polyfill'
66

77
const passportVerifyChannel = dc.channel('datadog:passport:verify:finish')
@@ -26,7 +26,7 @@ app.use((req, res, next) => {
2626
next()
2727
})
2828

29-
passport.use('basic', new BasicStrategy({
29+
passport.use('basic', new passportHttp.BasicStrategy({
3030
usernameField: 'username',
3131
passwordField: 'password',
3232
passReqToCallback: false,

packages/dd-trace/test/plugins/plugin-structure.spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ const missingPlugins = [
3838
'datadog-plugin-vm', // vm does not produce spans
3939
'datadog-plugin-sequelize', // sequelize does not produce spans
4040
'datadog-plugin-body-parser', // body-parser does not produce spans
41+
'datadog-plugin-light-my-request', // light-my-request does not produce spans
4142
]
4243

4344
// instrumentations that do not have a hook, but are still instrumented

0 commit comments

Comments
 (0)