diff --git a/tests/sync_name_match_cjs/mod.js b/tests/sync_name_match_cjs/mod.js new file mode 100644 index 0000000..2550bbe --- /dev/null +++ b/tests/sync_name_match_cjs/mod.js @@ -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 } diff --git a/tests/sync_name_match_cjs/test.js b/tests/sync_name_match_cjs/test.js new file mode 100644 index 0000000..c5c35e8 --- /dev/null +++ b/tests/sync_name_match_cjs/test.js @@ -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 }) diff --git a/tests/tests.test.mjs b/tests/tests.test.mjs index d495a09..884e822 100644 --- a/tests/tests.test.mjs +++ b/tests/tests.test.mjs @@ -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', [