Skip to content

Commit

Permalink
chore: fix hoistable regexp
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed Aug 21, 2024
1 parent c0ebea9 commit 007556c
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion packages/mocker/src/node/hoistMocksPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,19 @@ export function hoistMocksPlugin(options: HoistMocksPluginOptions = {}): Plugin

const {
hoistableMockMethodNames = ['mock', 'unmock'],
dynamicImportMockMethodNames = ['mock', 'unmock', 'doMock', 'doUnmock'],
hoistedMethodNames = ['hoisted'],
utilsObjectNames = ['vi', 'vitest'],
} = options

const methods = new Set([
...hoistableMockMethodNames,
...hoistedMethodNames,
...dynamicImportMockMethodNames,
])

const regexpHoistable = new RegExp(
`\\b(?:${utilsObjectNames.join('|')})\\s*\.\\s*(?:${[...hoistableMockMethodNames, ...hoistedMethodNames].join('|')})\\(`,
`\\b(?:${utilsObjectNames.join('|')})\\s*\.\\s*(?:${Array.from(methods).join('|')})\\(`,
)

return {
Expand All @@ -77,6 +84,7 @@ export function hoistMocksPlugin(options: HoistMocksPluginOptions = {}): Plugin
hoistableMockMethodNames,
hoistedMethodNames,
utilsObjectNames,
dynamicImportMockMethodNames,
})
},
}
Expand Down

0 comments on commit 007556c

Please sign in to comment.