| @@ -83,6 +83,12 @@ const regexpHoistable |
|
|
| 83 |
83 |
= /\b(?:vi|vitest)\s*\.\s*(?:mock |
| 84 |
84 |
const hashbangRE = /^#!.*\n/ |
| 85 |
85 |
|
|
86 |
+// Public redistributions of Vitest that re-export its mocking API (`vi`) |
|
87 |
+// verbatim under their own specifier. Imports from these are treated as the |
|
88 |
+// hoisted module so `vi.mock()` is hoisted for e.g. |
|
89 |
+// `import { vi } from 'vite-plus/test'`, exactly as it is for `vitest`. |
|
90 |
+const REDISTRIBUTED_HOISTED_MODULES = ['vite-plus/test'] |
|
91 |
+ |
| 86 |
92 |
// this is a fork of Vite SSR transform |
| 87 |
93 |
export function hoistMocks( |
| 88 |
94 |
code: string, |
| @@ -141,8 +147,9 @@ export function hoistMocks( |
|
|
| 141 |
147 |
) { |
| 142 |
148 |
const source = importNode.source.value as string |
| 143 |
149 |
// always hoist vitest import to top of the file, so |
| 144 |
|
-// "vi" helpers can access it |
| 145 |
|
-if (hoistedModule === source) { |
|
150 |
+// "vi" helpers can access it. Vitest redistributions that re-export the |
|
151 |
+// mocking API under their own specifier are recognized the same way. |
|
152 |
+if (hoistedModule === source | |
| 146 |
153 |
hoistedModuleImported = true |
| 147 |
154 |
return |
| 148 |
155 |
} |