From 007556c5f047bfb161647158dbfc5000ec6dd435 Mon Sep 17 00:00:00 2001 From: Vladimir Date: Wed, 21 Aug 2024 15:41:40 +0200 Subject: [PATCH] chore: fix hoistable regexp --- packages/mocker/src/node/hoistMocksPlugin.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/mocker/src/node/hoistMocksPlugin.ts b/packages/mocker/src/node/hoistMocksPlugin.ts index 693fcc4102f4..234f7a750d0f 100644 --- a/packages/mocker/src/node/hoistMocksPlugin.ts +++ b/packages/mocker/src/node/hoistMocksPlugin.ts @@ -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 { @@ -77,6 +84,7 @@ export function hoistMocksPlugin(options: HoistMocksPluginOptions = {}): Plugin hoistableMockMethodNames, hoistedMethodNames, utilsObjectNames, + dynamicImportMockMethodNames, }) }, }