Skip to content

Commit 94575b9

Browse files
committed
test(transformer): add tests for objectName+propertyName selector
1 parent acb0759 commit 94575b9

5 files changed

Lines changed: 94 additions & 0 deletions

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
3+
* This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2025 Datadog, Inc.
4+
**/
5+
'use strict'
6+
7+
// Named object pattern: async arrow function assigned to a property
8+
// on a named identifier (not `this`).
9+
const conn = {}
10+
conn.query = async () => {
11+
return 42
12+
}
13+
14+
module.exports = { conn }
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
3+
* This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2025 Datadog, Inc.
4+
**/
5+
'use strict'
6+
7+
const { conn } = require('./instrumented.js')
8+
const { assert, getContext } = require('../common/preamble.js')
9+
const context = getContext('orchestrion:undici:conn_query')
10+
11+
;(async () => {
12+
const result = await conn.query()
13+
assert.strictEqual(result, 42)
14+
assert.deepStrictEqual(context, {
15+
start: true,
16+
end: true,
17+
asyncStart: 42,
18+
asyncEnd: 42
19+
})
20+
})()
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
3+
* This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2025 Datadog, Inc.
4+
**/
5+
'use strict'
6+
7+
// Mimics the mariadb v2 pattern: query methods are arrow functions
8+
// assigned to `this` inside a function constructor.
9+
function Connection (opts) {
10+
this._query = async () => {
11+
return 42
12+
}
13+
}
14+
15+
module.exports = { Connection }
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
3+
* This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2025 Datadog, Inc.
4+
**/
5+
'use strict'
6+
7+
const { Connection } = require('./instrumented.js')
8+
const { assert, getContext } = require('../common/preamble.js')
9+
const context = getContext('orchestrion:undici:Connection_query')
10+
11+
;(async () => {
12+
const conn = new Connection({ host: 'localhost' })
13+
const result = await conn._query()
14+
assert.strictEqual(result, 42)
15+
assert.deepStrictEqual(context, {
16+
start: true,
17+
end: true,
18+
asyncStart: 42,
19+
asyncEnd: 42
20+
})
21+
})()

tests/tests.test.mjs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,3 +529,27 @@ describe('IIFE with class', () => {
529529
])
530530
})
531531
})
532+
533+
describe('object_property_this_cjs', () => {
534+
test('instruments async arrow function assigned to this inside a function constructor', () => {
535+
runTest('object_property_this_cjs', [
536+
{
537+
channelName: 'Connection_query',
538+
module: { name: TEST_MODULE_NAME, versionRange: '>=0.0.1', filePath: TEST_MODULE_PATH },
539+
functionQuery: { objectName: 'this', propertyName: '_query', kind: 'Async' },
540+
},
541+
])
542+
})
543+
})
544+
545+
describe('object_property_named_cjs', () => {
546+
test('instruments async arrow function assigned to a named identifier property', () => {
547+
runTest('object_property_named_cjs', [
548+
{
549+
channelName: 'conn_query',
550+
module: { name: TEST_MODULE_NAME, versionRange: '>=0.0.1', filePath: TEST_MODULE_PATH },
551+
functionQuery: { objectName: 'conn', propertyName: 'query', kind: 'Async' },
552+
},
553+
])
554+
})
555+
})

0 commit comments

Comments
 (0)