Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions tests/sync_name_match_cjs/mod.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// A synchronous function expression and a synchronous object method.
// This fixture guards that the name-based `functionQuery` variants match
// synchronous functions: the `[async]` token in the generated selectors
// is a structural "is-a-function-node" existence check (every function
// node has an `async` field), NOT an async-only filter.
const fetchExpr = function fetchExpr (x) {
return x + 1
}

const client = {
query (x) {
return x * 2
}
}

module.exports = { fetchExpr, client }
16 changes: 16 additions & 0 deletions tests/sync_name_match_cjs/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// This test guards that the name-based `functionQuery` variants match
// synchronous functions: the `[async]` token in the generated selectors
// is a structural "is-a-function-node" existence check (every function
// node has an `async` field), NOT an async-only filter.
const { fetchExpr, client } = require('./instrumented.js')
const { assert, getContext } = require('../common/preamble.js')

// expressionName, kind: 'Sync' matched, fetchExpr is not async.
const exprCtx = getContext('orchestrion:undici:fetch_expr_sync')
assert.strictEqual(fetchExpr(1), 2)
assert.deepStrictEqual(exprCtx, { start: true, end: 2 })

// methodName (object method), kind: 'Sync' matched, query is not async.
const methodCtx = getContext('orchestrion:undici:client_query_sync')
assert.strictEqual(client.query(3), 6)
assert.deepStrictEqual(methodCtx, { start: true, end: 6 })
17 changes: 17 additions & 0 deletions tests/tests.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,23 @@ describe('ast_query_returned_arrow_cjs', () => {
})
})

describe('sync_name_match_cjs', () => {
test('name-based queries match synchronous functions (the [async] token is structural)', () => {
runTest('sync_name_match_cjs', [
{
channelName: 'fetch_expr_sync',
module: { name: TEST_MODULE_NAME, versionRange: '>=0.0.1', filePath: TEST_MODULE_PATH },
functionQuery: { expressionName: 'fetchExpr', kind: 'Sync' },
},
{
channelName: 'client_query_sync',
module: { name: TEST_MODULE_NAME, versionRange: '>=0.0.1', filePath: TEST_MODULE_PATH },
functionQuery: { methodName: 'query', kind: 'Sync' },
},
])
})
})

describe('polyfill_cjs', () => {
test('instruments with a custom dc module (cjs)', () => {
runTest('polyfill_cjs', [
Expand Down
Loading