Skip to content
Open
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
2 changes: 1 addition & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export interface ModuleMatcher {
/**
* The path of the file you want to match from the module root
*/
filePath: string;
filePath: string | RegExp;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/matcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class InstrumentationMatcher {

const configs = this.#configs.filter(({ module: mod }) =>
mod.name === moduleName &&
mod.filePath === filePath &&
(typeof mod.filePath === 'string' ? mod.filePath === filePath : mod.filePath.test(filePath)) &&
semifies(version, mod.versionRange)
)

Expand Down
13 changes: 13 additions & 0 deletions tests/tests.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const TEST_MODULE_NAME = 'undici'
const TEST_MODULE_VERSION = '0.0.1'
const TEST_MODULE_PATH = 'index.mjs'
const WINDOWS_MODULE_PATH = 'lib/index.mjs'
const WINDOWS_MODULE_REGEX = /lib\/index\.m?js/

function runTest (testName, configs, { mjs = false, filePath = TEST_MODULE_PATH, dcModule, customTransforms = {} } = {}) {
const ext = mjs ? 'mjs' : 'js'
Expand Down Expand Up @@ -309,6 +310,18 @@ describe('windows_path', () => {
})
})

describe('windows_path_regex', () => {
test('instruments with windows-style file path matching regex', () => {
runTest('windows_path', [
{
channelName: 'fetch_decl',
module: { name: TEST_MODULE_NAME, versionRange: '>=0.0.1', filePath: WINDOWS_MODULE_REGEX },
functionQuery: { functionName: 'fetch', kind: 'Async' },
},
], { filePath: 'lib\\index.mjs' })
})
})

describe('export_alias_mjs', () => {
test('instruments async function declaration via export alias (mjs)', () => {
runTest('export_alias_mjs', [
Expand Down
Loading