@voidzero-dev/vite-plus-test 0.1.9 → 0.1.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (205) hide show
  1. package/LICENSE.md +181 -1
  2. package/dist/@vitest/browser/client/.vite/manifest.json +6 -6
  3. package/dist/@vitest/browser/client/__vitest__/assets/index-Da0hb3oU.css +1 -0
  4. package/dist/@vitest/browser/client/__vitest__/assets/index-Di71CKDo.js +63 -0
  5. package/dist/@vitest/browser/client/__vitest__/favicon.ico +0 -0
  6. package/dist/@vitest/browser/client/__vitest__/favicon.svg +49 -4
  7. package/dist/@vitest/browser/client/__vitest__/index.html +2 -2
  8. package/dist/@vitest/browser/client/__vitest_browser__/{orchestrator-S_3e_uzt.js → orchestrator-CXs6qrFe.js} +70 -28
  9. package/dist/@vitest/browser/client/__vitest_browser__/{tester-k74mgIRa.js → tester-K5NNxh1O.js} +167 -58
  10. package/dist/@vitest/browser/client/__vitest_browser__/{utils-uxqdqUz8.js → utils-C2ISqq1C.js} +2 -2
  11. package/dist/@vitest/browser/client/favicon.svg +49 -4
  12. package/dist/@vitest/browser/client/orchestrator.html +2 -2
  13. package/dist/@vitest/browser/client/tester/tester.html +2 -2
  14. package/dist/@vitest/browser/client.js +20 -13
  15. package/dist/@vitest/browser/context.d.ts +160 -10
  16. package/dist/@vitest/browser/context.js +108 -22
  17. package/dist/@vitest/browser/expect-element.js +23 -28
  18. package/dist/@vitest/browser/index-5Pe7X7sp.js +7 -0
  19. package/dist/@vitest/browser/index.d.ts +20 -2
  20. package/dist/@vitest/browser/index.js +5706 -159
  21. package/dist/@vitest/browser/locators.d.ts +14 -3
  22. package/dist/@vitest/browser/locators.js +1 -1
  23. package/dist/@vitest/browser-playwright/index.d.ts +22 -5
  24. package/dist/@vitest/browser-playwright/index.js +169 -61
  25. package/dist/@vitest/browser-preview/index.d.ts +14 -1
  26. package/dist/@vitest/browser-preview/locators.js +31 -18
  27. package/dist/@vitest/browser-webdriverio/index.d.ts +17 -3
  28. package/dist/@vitest/browser-webdriverio/index.js +22 -2
  29. package/dist/@vitest/browser-webdriverio/locators.js +84 -7
  30. package/dist/@vitest/expect/index.d.ts +172 -54
  31. package/dist/@vitest/expect/index.js +124 -67
  32. package/dist/@vitest/mocker/auto-register.js +1 -0
  33. package/dist/@vitest/mocker/automock.d.ts +1 -0
  34. package/dist/@vitest/mocker/automock.js +5 -0
  35. package/dist/@vitest/mocker/browser.d.ts +4 -4
  36. package/dist/@vitest/mocker/browser.js +1 -0
  37. package/dist/@vitest/mocker/chunk-automock.js +182 -14
  38. package/dist/@vitest/mocker/chunk-helpers.js +44 -0
  39. package/dist/@vitest/mocker/chunk-hoistMocks.js +659 -0
  40. package/dist/@vitest/mocker/chunk-mocker.js +41 -30
  41. package/dist/@vitest/mocker/chunk-registry.js +21 -7
  42. package/dist/@vitest/mocker/chunk-utils.js +18 -7
  43. package/dist/@vitest/mocker/hoistMocks.d-w2ILr1dG.d.ts +739 -0
  44. package/dist/@vitest/mocker/{index.d-C-sLYZi-.d.ts → index.d-B41z0AuW.d.ts} +1 -1
  45. package/dist/@vitest/mocker/index.d.ts +2 -2
  46. package/dist/@vitest/mocker/index.js +18 -3
  47. package/dist/@vitest/mocker/{mocker.d-TnKRhz7N.d.ts → mocker.d-QEntlm6J.d.ts} +10 -5
  48. package/dist/@vitest/mocker/node.d.ts +5 -734
  49. package/dist/@vitest/mocker/node.js +29 -587
  50. package/dist/@vitest/mocker/redirect.js +4 -4
  51. package/dist/@vitest/mocker/register.d.ts +3 -3
  52. package/dist/@vitest/mocker/register.js +1 -0
  53. package/dist/@vitest/mocker/transforms.d.ts +6 -0
  54. package/dist/@vitest/mocker/transforms.js +8 -0
  55. package/dist/@vitest/mocker/{types.d-B8CCKmHt.d.ts → types.d-BjI5eAwu.d.ts} +23 -7
  56. package/dist/@vitest/pretty-format/index.d.ts +11 -1
  57. package/dist/@vitest/pretty-format/index.js +33 -4
  58. package/dist/@vitest/runner/chunk-tasks.js +305 -37
  59. package/dist/@vitest/runner/index.d.ts +5 -6
  60. package/dist/@vitest/runner/index.js +1146 -455
  61. package/dist/@vitest/runner/{tasks.d-C7UxawJ9.d.ts → tasks.d-D2GKpdwQ.d.ts} +726 -55
  62. package/dist/@vitest/runner/types.d.ts +2 -182
  63. package/dist/@vitest/runner/utils.d.ts +16 -8
  64. package/dist/@vitest/runner/utils.js +1 -1
  65. package/dist/@vitest/snapshot/{environment.d-DHdQ1Csl.d.ts → environment.d-DOJxxZV9.d.ts} +2 -7
  66. package/dist/@vitest/snapshot/environment.d.ts +2 -1
  67. package/dist/@vitest/snapshot/environment.js +1 -1
  68. package/dist/@vitest/snapshot/index.d.ts +4 -3
  69. package/dist/@vitest/snapshot/index.js +21 -550
  70. package/dist/@vitest/snapshot/manager.d.ts +3 -2
  71. package/dist/@vitest/snapshot/manager.js +1 -1
  72. package/dist/@vitest/snapshot/{rawSnapshot.d-lFsMJFUd.d.ts → rawSnapshot.d-U2kJUxDr.d.ts} +1 -1
  73. package/dist/@vitest/spy/index.d.ts +34 -4
  74. package/dist/@vitest/spy/index.js +69 -19
  75. package/dist/@vitest/utils/diff.js +11 -9
  76. package/dist/@vitest/utils/display.d.ts +2 -1
  77. package/dist/@vitest/utils/display.js +38 -5
  78. package/dist/@vitest/utils/error.d.ts +2 -1
  79. package/dist/@vitest/utils/error.js +1 -2
  80. package/dist/@vitest/utils/helpers.d.ts +4 -1
  81. package/dist/@vitest/utils/helpers.js +43 -1
  82. package/dist/@vitest/utils/resolver.js +1 -2
  83. package/dist/@vitest/utils/serialize.js +6 -6
  84. package/dist/@vitest/utils/source-map/node.d.ts +6 -0
  85. package/dist/@vitest/utils/source-map/node.js +23 -0
  86. package/dist/@vitest/utils/source-map.js +15 -5
  87. package/dist/browser.d.ts +3 -2
  88. package/dist/browser.js +2 -2
  89. package/dist/chunks/acorn.B2iPLyUM.js +5958 -0
  90. package/dist/chunks/{base.CJ0Y4ePK.js → base.DM0-RqVb.js} +54 -16
  91. package/dist/chunks/{benchmark.B3N2zMcH.js → benchmark.D0SlKNbZ.js} +1 -1
  92. package/dist/chunks/{browser.d.ChKACdzH.d.ts → browser.d.X3SXoOCV.d.ts} +4 -1
  93. package/dist/chunks/{cac.DVeoLl0M.js → cac.CWGDZnXT.js} +979 -20
  94. package/dist/chunks/{cli-api.B7PN_QUv.js → cli-api.DuT9iuvY.js} +8764 -7898
  95. package/dist/chunks/{config.d.Cy95HiCx.d.ts → config.d.EJLVE3es.d.ts} +30 -15
  96. package/dist/chunks/{console.Cf-YriPC.js → console.3WNpx0tS.js} +3 -2
  97. package/dist/chunks/{constants.D_Q9UYh-.js → constants.CPYnjOGj.js} +4 -2
  98. package/dist/chunks/coverage.Bri33R1t.js +1050 -0
  99. package/dist/chunks/{creator.DAmOKTvJ.js → creator.DgVhQm5q.js} +35 -4
  100. package/dist/chunks/{defaults.BOqNVLsY.js → defaults.CdU2lD-q.js} +4 -3
  101. package/dist/chunks/{global.d.B15mdLcR.d.ts → global.d.x-ILCfAE.d.ts} +1 -2
  102. package/dist/chunks/{globals.DOayXfHP.js → globals.BXNGLnTL.js} +11 -10
  103. package/dist/chunks/{coverage.AVPTjMgw.js → index.BCY_7LL2.js} +5 -959
  104. package/dist/chunks/{index.C5r1PdPD.js → index.CEzQDJGb.js} +1 -1
  105. package/dist/chunks/{index.D3XRDfWc.js → index.CMESou6r.js} +26 -1
  106. package/dist/chunks/{index.6Qv1eEA6.js → index.DGNSnENe.js} +95 -9
  107. package/dist/chunks/{index.M8mOzt4Y.js → index.DXMFO5MJ.js} +3279 -2914
  108. package/dist/chunks/{index.Z5E_ObnR.js → index.DlDSLQD3.js} +7 -3
  109. package/dist/chunks/{index.CyBMJtT7.js → index.EY6TCHpo.js} +10 -8
  110. package/dist/chunks/{index.D4KonVSU.js → index.og1WyBLx.js} +18 -3
  111. package/dist/chunks/{init-forks._y3TW739.js → init-forks.DeArv0jT.js} +1 -1
  112. package/dist/chunks/{init-threads.DBO2kn-p.js → init-threads.-2OUl4Nn.js} +1 -1
  113. package/dist/chunks/{init.B6MLFIaN.js → init.DICorXCo.js} +52 -13
  114. package/dist/chunks/native.DPzPHdi5.js +148 -0
  115. package/dist/chunks/nativeModuleMocker.DndvSdL6.js +206 -0
  116. package/dist/chunks/nativeModuleRunner.BIakptoF.js +36 -0
  117. package/dist/chunks/{node.Ce0vMQM7.js → node.COQbm6gK.js} +1 -1
  118. package/dist/chunks/{plugin.d.CtqpEehP.d.ts → plugin.d.BuW-flqo.d.ts} +1 -1
  119. package/dist/chunks/{reporters.d.CWXNI2jG.d.ts → reporters.d.DVUYHHhe.d.ts} +328 -79
  120. package/dist/chunks/rpc.MzXet3jl.js +144 -0
  121. package/dist/chunks/{rpc.d.RH3apGEf.d.ts → rpc.d.BFMWpdph.d.ts} +10 -2
  122. package/dist/chunks/{setup-common.Cm-kSBVi.js → setup-common.B41N_kPE.js} +3 -3
  123. package/dist/chunks/{startModuleRunner.DEj0jb3e.js → startVitestModuleRunner.C3ZR-4J3.js} +265 -405
  124. package/dist/chunks/{suite.d.BJWk38HB.d.ts → suite.d.udJtyAgw.d.ts} +1 -1
  125. package/dist/chunks/{vi.2VT5v0um.js → test.CTcmp4Su.js} +538 -181
  126. package/dist/chunks/{utils.DvEY5TfP.js → utils.BX5Fg8C4.js} +8 -1
  127. package/dist/chunks/{vm.D3epNOPZ.js → vm.Dh2rTtmP.js} +48 -8
  128. package/dist/chunks/{worker.d.Dyxm8DEL.d.ts → worker.d.B84sVRy0.d.ts} +2 -2
  129. package/dist/cli.js +6 -5
  130. package/dist/client/.vite/manifest.json +6 -6
  131. package/dist/client/__vitest__/assets/index-Da0hb3oU.css +1 -0
  132. package/dist/client/__vitest__/assets/index-Di71CKDo.js +63 -0
  133. package/dist/client/__vitest__/favicon.ico +0 -0
  134. package/dist/client/__vitest__/favicon.svg +49 -4
  135. package/dist/client/__vitest__/index.html +2 -2
  136. package/dist/client/__vitest_browser__/{orchestrator-S_3e_uzt.js → orchestrator-CXs6qrFe.js} +70 -28
  137. package/dist/client/__vitest_browser__/{tester-k74mgIRa.js → tester-K5NNxh1O.js} +167 -58
  138. package/dist/client/__vitest_browser__/{utils-uxqdqUz8.js → utils-C2ISqq1C.js} +2 -2
  139. package/dist/client/favicon.svg +49 -4
  140. package/dist/client/orchestrator.html +2 -2
  141. package/dist/client/tester/tester.html +2 -2
  142. package/dist/client.js +20 -13
  143. package/dist/config.cjs +3 -2
  144. package/dist/config.d.ts +13 -12
  145. package/dist/config.js +2 -2
  146. package/dist/context.js +108 -22
  147. package/dist/coverage.d.ts +12 -8
  148. package/dist/coverage.js +8 -5
  149. package/dist/environments.js +3 -1
  150. package/dist/expect-element.js +23 -23
  151. package/dist/index-5Pe7X7sp.js +7 -0
  152. package/dist/index.d.ts +66 -27
  153. package/dist/index.js +10 -9
  154. package/dist/locators.d.ts +14 -3
  155. package/dist/locators.js +1 -1
  156. package/dist/module-evaluator.d.ts +11 -1
  157. package/dist/module-evaluator.js +43 -26
  158. package/dist/node.d.ts +28 -14
  159. package/dist/node.js +42 -40
  160. package/dist/nodejs-worker-loader.js +41 -0
  161. package/dist/plugins/mocker-transforms.mjs +2 -0
  162. package/dist/plugins/utils-source-map-node.mjs +2 -0
  163. package/dist/reporters.d.ts +8 -8
  164. package/dist/reporters.js +7 -5
  165. package/dist/runners.d.ts +24 -5
  166. package/dist/runners.js +6 -6
  167. package/dist/runtime.d.ts +6 -0
  168. package/dist/runtime.js +35 -0
  169. package/dist/snapshot.js +4 -2
  170. package/dist/suite.d.ts +1 -1
  171. package/dist/suite.js +4 -2
  172. package/dist/vendor/blazediff_core.d.mts +1 -0
  173. package/dist/vendor/blazediff_core.mjs +117 -0
  174. package/dist/vendor/chai.mjs +4 -249
  175. package/dist/vendor/convert-source-map.d.mts +1 -0
  176. package/dist/vendor/convert-source-map.mjs +150 -0
  177. package/dist/vendor/expect-type.d.mts +14 -7
  178. package/dist/vendor/expect-type.mjs +5 -5
  179. package/dist/vendor/std-env.d.mts +131 -40
  180. package/dist/vendor/std-env.mjs +114 -117
  181. package/dist/worker.d.ts +6 -6
  182. package/dist/worker.js +27 -21
  183. package/dist/workers/forks.js +23 -17
  184. package/dist/workers/runVmTests.js +18 -16
  185. package/dist/workers/threads.js +23 -17
  186. package/dist/workers/vmForks.js +15 -12
  187. package/dist/workers/vmThreads.js +15 -12
  188. package/globals.d.ts +2 -0
  189. package/package.json +35 -26
  190. package/suppress-warnings.cjs +1 -0
  191. package/dist/@vitest/browser/client/__vitest__/assets/index-BUCFJtth.js +0 -57
  192. package/dist/@vitest/browser/client/__vitest__/assets/index-DlhE0rqZ.css +0 -1
  193. package/dist/@vitest/browser/index-D6m36C6U.js +0 -11
  194. package/dist/@vitest/utils/chunk-_commonjsHelpers.js +0 -5
  195. package/dist/@vitest/utils/highlight.d.ts +0 -9
  196. package/dist/@vitest/utils/highlight.js +0 -538
  197. package/dist/chunks/date.Bq6ZW5rf.js +0 -73
  198. package/dist/chunks/rpc.BoxB0q7B.js +0 -76
  199. package/dist/chunks/test.B8ej_ZHS.js +0 -254
  200. package/dist/client/__vitest__/assets/index-BUCFJtth.js +0 -57
  201. package/dist/client/__vitest__/assets/index-DlhE0rqZ.css +0 -1
  202. package/dist/index-D6m36C6U.js +0 -6
  203. package/dist/mocker.d.ts +0 -1
  204. package/dist/mocker.js +0 -1
  205. package/dist/module-runner.js +0 -17
@@ -2,6 +2,7 @@ import { a as cleanUrl, c as createManualModuleSource } from './chunk-utils.js';
2
2
  import { a as automockModule, e as esmWalker } from './chunk-automock.js';
3
3
  import MagicString from '../../vendor/magic-string.mjs';
4
4
  import { createFilter } from '@voidzero-dev/vite-plus-core';
5
+ import { h as hoistMocks } from './chunk-hoistMocks.js';
5
6
  import { readFile } from 'node:fs/promises';
6
7
  import { join } from 'node:path/posix';
7
8
  import { M as MockerRegistry, a as ManualMockedModule } from './chunk-registry.js';
@@ -10,6 +11,8 @@ import { existsSync, readFileSync } from 'node:fs';
10
11
  import { findMockRedirect } from './redirect.js';
11
12
  import { i as isAbsolute, j as join$1, r as resolve } from './chunk-pathe.M-eThtNZ.js';
12
13
  import 'node:module';
14
+ import 'node:path';
15
+ import './chunk-helpers.js';
13
16
 
14
17
  function automockPlugin(options = {}) {
15
18
  return {
@@ -49,6 +52,9 @@ function dynamicImportPlugin(options = {}) {
49
52
  };
50
53
  }
51
54
  function injectDynamicImport(code, id, parse, options = {}) {
55
+ if (code.includes("wrapDynamicImport")) {
56
+ return;
57
+ }
52
58
  const s = new MagicString(code);
53
59
  let ast;
54
60
  try {
@@ -80,295 +86,6 @@ function injectDynamicImport(code, id, parse, options = {}) {
80
86
  };
81
87
  }
82
88
 
83
- // AST walker module for ESTree compatible trees
84
-
85
-
86
- function makeTest(test) {
87
- if (typeof test === "string")
88
- { return function (type) { return type === test; } }
89
- else if (!test)
90
- { return function () { return true; } }
91
- else
92
- { return test }
93
- }
94
-
95
- var Found = function Found(node, state) { this.node = node; this.state = state; };
96
-
97
- // Find the innermost node of a given type that contains the given
98
- // position. Interface similar to findNodeAt.
99
- function findNodeAround(node, pos, test, baseVisitor, state) {
100
- test = makeTest(test);
101
- if (!baseVisitor) { baseVisitor = base; }
102
- try {
103
- (function c(node, st, override) {
104
- var type = override || node.type;
105
- if (node.start > pos || node.end < pos) { return }
106
- baseVisitor[type](node, st, c);
107
- if (test(type, node)) { throw new Found(node, st) }
108
- })(node, state);
109
- } catch (e) {
110
- if (e instanceof Found) { return e }
111
- throw e
112
- }
113
- }
114
-
115
- function skipThrough(node, st, c) { c(node, st); }
116
- function ignore(_node, _st, _c) {}
117
-
118
- // Node walkers.
119
-
120
- var base = {};
121
-
122
- base.Program = base.BlockStatement = base.StaticBlock = function (node, st, c) {
123
- for (var i = 0, list = node.body; i < list.length; i += 1)
124
- {
125
- var stmt = list[i];
126
-
127
- c(stmt, st, "Statement");
128
- }
129
- };
130
- base.Statement = skipThrough;
131
- base.EmptyStatement = ignore;
132
- base.ExpressionStatement = base.ParenthesizedExpression = base.ChainExpression =
133
- function (node, st, c) { return c(node.expression, st, "Expression"); };
134
- base.IfStatement = function (node, st, c) {
135
- c(node.test, st, "Expression");
136
- c(node.consequent, st, "Statement");
137
- if (node.alternate) { c(node.alternate, st, "Statement"); }
138
- };
139
- base.LabeledStatement = function (node, st, c) { return c(node.body, st, "Statement"); };
140
- base.BreakStatement = base.ContinueStatement = ignore;
141
- base.WithStatement = function (node, st, c) {
142
- c(node.object, st, "Expression");
143
- c(node.body, st, "Statement");
144
- };
145
- base.SwitchStatement = function (node, st, c) {
146
- c(node.discriminant, st, "Expression");
147
- for (var i = 0, list = node.cases; i < list.length; i += 1) {
148
- var cs = list[i];
149
-
150
- c(cs, st);
151
- }
152
- };
153
- base.SwitchCase = function (node, st, c) {
154
- if (node.test) { c(node.test, st, "Expression"); }
155
- for (var i = 0, list = node.consequent; i < list.length; i += 1)
156
- {
157
- var cons = list[i];
158
-
159
- c(cons, st, "Statement");
160
- }
161
- };
162
- base.ReturnStatement = base.YieldExpression = base.AwaitExpression = function (node, st, c) {
163
- if (node.argument) { c(node.argument, st, "Expression"); }
164
- };
165
- base.ThrowStatement = base.SpreadElement =
166
- function (node, st, c) { return c(node.argument, st, "Expression"); };
167
- base.TryStatement = function (node, st, c) {
168
- c(node.block, st, "Statement");
169
- if (node.handler) { c(node.handler, st); }
170
- if (node.finalizer) { c(node.finalizer, st, "Statement"); }
171
- };
172
- base.CatchClause = function (node, st, c) {
173
- if (node.param) { c(node.param, st, "Pattern"); }
174
- c(node.body, st, "Statement");
175
- };
176
- base.WhileStatement = base.DoWhileStatement = function (node, st, c) {
177
- c(node.test, st, "Expression");
178
- c(node.body, st, "Statement");
179
- };
180
- base.ForStatement = function (node, st, c) {
181
- if (node.init) { c(node.init, st, "ForInit"); }
182
- if (node.test) { c(node.test, st, "Expression"); }
183
- if (node.update) { c(node.update, st, "Expression"); }
184
- c(node.body, st, "Statement");
185
- };
186
- base.ForInStatement = base.ForOfStatement = function (node, st, c) {
187
- c(node.left, st, "ForInit");
188
- c(node.right, st, "Expression");
189
- c(node.body, st, "Statement");
190
- };
191
- base.ForInit = function (node, st, c) {
192
- if (node.type === "VariableDeclaration") { c(node, st); }
193
- else { c(node, st, "Expression"); }
194
- };
195
- base.DebuggerStatement = ignore;
196
-
197
- base.FunctionDeclaration = function (node, st, c) { return c(node, st, "Function"); };
198
- base.VariableDeclaration = function (node, st, c) {
199
- for (var i = 0, list = node.declarations; i < list.length; i += 1)
200
- {
201
- var decl = list[i];
202
-
203
- c(decl, st);
204
- }
205
- };
206
- base.VariableDeclarator = function (node, st, c) {
207
- c(node.id, st, "Pattern");
208
- if (node.init) { c(node.init, st, "Expression"); }
209
- };
210
-
211
- base.Function = function (node, st, c) {
212
- if (node.id) { c(node.id, st, "Pattern"); }
213
- for (var i = 0, list = node.params; i < list.length; i += 1)
214
- {
215
- var param = list[i];
216
-
217
- c(param, st, "Pattern");
218
- }
219
- c(node.body, st, node.expression ? "Expression" : "Statement");
220
- };
221
-
222
- base.Pattern = function (node, st, c) {
223
- if (node.type === "Identifier")
224
- { c(node, st, "VariablePattern"); }
225
- else if (node.type === "MemberExpression")
226
- { c(node, st, "MemberPattern"); }
227
- else
228
- { c(node, st); }
229
- };
230
- base.VariablePattern = ignore;
231
- base.MemberPattern = skipThrough;
232
- base.RestElement = function (node, st, c) { return c(node.argument, st, "Pattern"); };
233
- base.ArrayPattern = function (node, st, c) {
234
- for (var i = 0, list = node.elements; i < list.length; i += 1) {
235
- var elt = list[i];
236
-
237
- if (elt) { c(elt, st, "Pattern"); }
238
- }
239
- };
240
- base.ObjectPattern = function (node, st, c) {
241
- for (var i = 0, list = node.properties; i < list.length; i += 1) {
242
- var prop = list[i];
243
-
244
- if (prop.type === "Property") {
245
- if (prop.computed) { c(prop.key, st, "Expression"); }
246
- c(prop.value, st, "Pattern");
247
- } else if (prop.type === "RestElement") {
248
- c(prop.argument, st, "Pattern");
249
- }
250
- }
251
- };
252
-
253
- base.Expression = skipThrough;
254
- base.ThisExpression = base.Super = base.MetaProperty = ignore;
255
- base.ArrayExpression = function (node, st, c) {
256
- for (var i = 0, list = node.elements; i < list.length; i += 1) {
257
- var elt = list[i];
258
-
259
- if (elt) { c(elt, st, "Expression"); }
260
- }
261
- };
262
- base.ObjectExpression = function (node, st, c) {
263
- for (var i = 0, list = node.properties; i < list.length; i += 1)
264
- {
265
- var prop = list[i];
266
-
267
- c(prop, st);
268
- }
269
- };
270
- base.FunctionExpression = base.ArrowFunctionExpression = base.FunctionDeclaration;
271
- base.SequenceExpression = function (node, st, c) {
272
- for (var i = 0, list = node.expressions; i < list.length; i += 1)
273
- {
274
- var expr = list[i];
275
-
276
- c(expr, st, "Expression");
277
- }
278
- };
279
- base.TemplateLiteral = function (node, st, c) {
280
- for (var i = 0, list = node.quasis; i < list.length; i += 1)
281
- {
282
- var quasi = list[i];
283
-
284
- c(quasi, st);
285
- }
286
-
287
- for (var i$1 = 0, list$1 = node.expressions; i$1 < list$1.length; i$1 += 1)
288
- {
289
- var expr = list$1[i$1];
290
-
291
- c(expr, st, "Expression");
292
- }
293
- };
294
- base.TemplateElement = ignore;
295
- base.UnaryExpression = base.UpdateExpression = function (node, st, c) {
296
- c(node.argument, st, "Expression");
297
- };
298
- base.BinaryExpression = base.LogicalExpression = function (node, st, c) {
299
- c(node.left, st, "Expression");
300
- c(node.right, st, "Expression");
301
- };
302
- base.AssignmentExpression = base.AssignmentPattern = function (node, st, c) {
303
- c(node.left, st, "Pattern");
304
- c(node.right, st, "Expression");
305
- };
306
- base.ConditionalExpression = function (node, st, c) {
307
- c(node.test, st, "Expression");
308
- c(node.consequent, st, "Expression");
309
- c(node.alternate, st, "Expression");
310
- };
311
- base.NewExpression = base.CallExpression = function (node, st, c) {
312
- c(node.callee, st, "Expression");
313
- if (node.arguments)
314
- { for (var i = 0, list = node.arguments; i < list.length; i += 1)
315
- {
316
- var arg = list[i];
317
-
318
- c(arg, st, "Expression");
319
- } }
320
- };
321
- base.MemberExpression = function (node, st, c) {
322
- c(node.object, st, "Expression");
323
- if (node.computed) { c(node.property, st, "Expression"); }
324
- };
325
- base.ExportNamedDeclaration = base.ExportDefaultDeclaration = function (node, st, c) {
326
- if (node.declaration)
327
- { c(node.declaration, st, node.type === "ExportNamedDeclaration" || node.declaration.id ? "Statement" : "Expression"); }
328
- if (node.source) { c(node.source, st, "Expression"); }
329
- };
330
- base.ExportAllDeclaration = function (node, st, c) {
331
- if (node.exported)
332
- { c(node.exported, st); }
333
- c(node.source, st, "Expression");
334
- };
335
- base.ImportDeclaration = function (node, st, c) {
336
- for (var i = 0, list = node.specifiers; i < list.length; i += 1)
337
- {
338
- var spec = list[i];
339
-
340
- c(spec, st);
341
- }
342
- c(node.source, st, "Expression");
343
- };
344
- base.ImportExpression = function (node, st, c) {
345
- c(node.source, st, "Expression");
346
- };
347
- base.ImportSpecifier = base.ImportDefaultSpecifier = base.ImportNamespaceSpecifier = base.Identifier = base.PrivateIdentifier = base.Literal = ignore;
348
-
349
- base.TaggedTemplateExpression = function (node, st, c) {
350
- c(node.tag, st, "Expression");
351
- c(node.quasi, st, "Expression");
352
- };
353
- base.ClassDeclaration = base.ClassExpression = function (node, st, c) { return c(node, st, "Class"); };
354
- base.Class = function (node, st, c) {
355
- if (node.id) { c(node.id, st, "Pattern"); }
356
- if (node.superClass) { c(node.superClass, st, "Expression"); }
357
- c(node.body, st);
358
- };
359
- base.ClassBody = function (node, st, c) {
360
- for (var i = 0, list = node.body; i < list.length; i += 1)
361
- {
362
- var elt = list[i];
363
-
364
- c(elt, st);
365
- }
366
- };
367
- base.MethodDefinition = base.PropertyDefinition = base.Property = function (node, st, c) {
368
- if (node.computed) { c(node.key, st, "Expression"); }
369
- if (node.value) { c(node.value, st, "Expression"); }
370
- };
371
-
372
89
  function hoistMocksPlugin(options = {}) {
373
90
  const filter = options.filter || createFilter(options.include, options.exclude);
374
91
  const { hoistableMockMethodNames = ["mock", "unmock"], dynamicImportMockMethodNames = [
@@ -390,7 +107,7 @@ function hoistMocksPlugin(options = {}) {
390
107
  if (!filter(id)) {
391
108
  return;
392
109
  }
393
- return hoistMocks(code, id, this.parse, {
110
+ const s = hoistMocks(code, id, this.parse, {
394
111
  regexpHoistable,
395
112
  hoistableMockMethodNames,
396
113
  hoistedMethodNames,
@@ -398,304 +115,30 @@ function hoistMocksPlugin(options = {}) {
398
115
  dynamicImportMockMethodNames,
399
116
  ...options
400
117
  });
118
+ if (s) {
119
+ return {
120
+ code: s.toString(),
121
+ map: s.generateMap({
122
+ hires: "boundary",
123
+ source: cleanUrl(id)
124
+ })
125
+ };
126
+ }
401
127
  }
402
128
  };
403
129
  }
404
- const API_NOT_FOUND_ERROR = `There are some problems in resolving the mocks API.
405
- You may encounter this issue when importing the mocks API from another module other than 'vitest'.
406
- To fix this issue you can either:
407
- - import the mocks API directly from 'vitest'
408
- - enable the 'globals' options`;
409
- function API_NOT_FOUND_CHECK(names) {
410
- return `\nif (${names.map((name) => `typeof globalThis["${name}"] === "undefined"`).join(" && ")}) ` + `{ throw new Error(${JSON.stringify(API_NOT_FOUND_ERROR)}) }\n`;
411
- }
412
- function isIdentifier(node) {
413
- return node.type === "Identifier";
414
- }
415
- function getNodeTail(code, node) {
416
- let end = node.end;
417
- if (code[node.end] === ";") {
418
- end += 1;
419
- }
420
- if (code[node.end] === "\n") {
421
- return end + 1;
422
- }
423
- if (code[node.end + 1] === "\n") {
424
- end += 1;
425
- }
426
- return end;
427
- }
428
- const regexpHoistable = /\b(?:vi|vitest)\s*\.\s*(?:mock|unmock|hoisted|doMock|doUnmock)\s*\(/;
429
- const hashbangRE = /^#!.*\n/;
430
- // this is a fork of Vite SSR transform
431
- function hoistMocks(code, id, parse, options = {}) {
432
- var _hashbangRE$exec;
433
- const needHoisting = (options.regexpHoistable || regexpHoistable).test(code);
434
- if (!needHoisting) {
435
- return;
436
- }
437
- const s = new MagicString(code);
438
- let ast;
439
- try {
440
- ast = parse(code);
441
- } catch (err) {
442
- console.error(`Cannot parse ${id}:\n${err.message}.`);
443
- return;
444
- }
445
- const { hoistableMockMethodNames = ["mock", "unmock"], dynamicImportMockMethodNames = [
446
- "mock",
447
- "unmock",
448
- "doMock",
449
- "doUnmock"
450
- ], hoistedMethodNames = ["hoisted"], utilsObjectNames = ["vi", "vitest"], hoistedModule = "vitest" } = options;
451
- // hoist at the start of the file, after the hashbang
452
- let hoistIndex = ((_hashbangRE$exec = hashbangRE.exec(code)) === null || _hashbangRE$exec === void 0 ? void 0 : _hashbangRE$exec[0].length) ?? 0;
453
- let hoistedModuleImported = false;
454
- let uid = 0;
455
- const idToImportMap = new Map();
456
- const imports = [];
457
- // this will transform import statements into dynamic ones, if there are imports
458
- // it will keep the import as is, if we don't need to mock anything
459
- // in browser environment it will wrap the module value with "vitest_wrap_module" function
460
- // that returns a proxy to the module so that named exports can be mocked
461
- function defineImport(importNode) {
462
- const source = importNode.source.value;
463
- // always hoist vitest import to top of the file, so
464
- // "vi" helpers can access it
465
- if (hoistedModule === source || source === "vite-plus/test" || source === "@voidzero-dev/vite-plus-test") {
466
- hoistedModuleImported = true;
467
- return;
468
- }
469
- const importId = `__vi_import_${uid++}__`;
470
- imports.push({
471
- id: importId,
472
- node: importNode
473
- });
474
- return importId;
475
- }
476
- // 1. check all import statements and record id -> importName map
477
- for (const node of ast.body) {
478
- // import foo from 'foo' --> foo -> __import_foo__.default
479
- // import { baz } from 'foo' --> baz -> __import_foo__.baz
480
- // import * as ok from 'foo' --> ok -> __import_foo__
481
- if (node.type === "ImportDeclaration") {
482
- const importId = defineImport(node);
483
- if (!importId) {
484
- continue;
485
- }
486
- for (const spec of node.specifiers) {
487
- if (spec.type === "ImportSpecifier") {
488
- if (spec.imported.type === "Identifier") {
489
- idToImportMap.set(spec.local.name, `${importId}.${spec.imported.name}`);
490
- } else {
491
- idToImportMap.set(spec.local.name, `${importId}[${JSON.stringify(spec.imported.value)}]`);
492
- }
493
- } else if (spec.type === "ImportDefaultSpecifier") {
494
- idToImportMap.set(spec.local.name, `${importId}.default`);
495
- } else {
496
- // namespace specifier
497
- idToImportMap.set(spec.local.name, importId);
498
- }
499
- }
500
- }
501
- }
502
- const declaredConst = new Set();
503
- const hoistedNodes = [];
504
- function createSyntaxError(node, message) {
505
- const _error = new SyntaxError(message);
506
- Error.captureStackTrace(_error, createSyntaxError);
507
- const serializedError = {
508
- name: "SyntaxError",
509
- message: _error.message,
510
- stack: _error.stack
130
+ // to keeb backwards compat
131
+ function hoistMockAndResolve(code, id, parse, options = {}) {
132
+ const s = hoistMocks(code, id, parse, options);
133
+ if (s) {
134
+ return {
135
+ code: s.toString(),
136
+ map: s.generateMap({
137
+ hires: "boundary",
138
+ source: cleanUrl(id)
139
+ })
511
140
  };
512
- if (options.codeFrameGenerator) {
513
- serializedError.frame = options.codeFrameGenerator(node, id, code);
514
- }
515
- return serializedError;
516
- }
517
- function assertNotDefaultExport(node, error) {
518
- var _findNodeAround;
519
- const defaultExport = (_findNodeAround = findNodeAround(ast, node.start, "ExportDefaultDeclaration")) === null || _findNodeAround === void 0 ? void 0 : _findNodeAround.node;
520
- if ((defaultExport === null || defaultExport === void 0 ? void 0 : defaultExport.declaration) === node || (defaultExport === null || defaultExport === void 0 ? void 0 : defaultExport.declaration.type) === "AwaitExpression" && defaultExport.declaration.argument === node) {
521
- throw createSyntaxError(defaultExport, error);
522
- }
523
- }
524
- function assertNotNamedExport(node, error) {
525
- var _findNodeAround2;
526
- const nodeExported = (_findNodeAround2 = findNodeAround(ast, node.start, "ExportNamedDeclaration")) === null || _findNodeAround2 === void 0 ? void 0 : _findNodeAround2.node;
527
- if ((nodeExported === null || nodeExported === void 0 ? void 0 : nodeExported.declaration) === node) {
528
- throw createSyntaxError(nodeExported, error);
529
- }
530
- }
531
- function getVariableDeclaration(node) {
532
- var _findNodeAround3, _declarationNode$decl;
533
- const declarationNode = (_findNodeAround3 = findNodeAround(ast, node.start, "VariableDeclaration")) === null || _findNodeAround3 === void 0 ? void 0 : _findNodeAround3.node;
534
- const init = declarationNode === null || declarationNode === void 0 || (_declarationNode$decl = declarationNode.declarations[0]) === null || _declarationNode$decl === void 0 ? void 0 : _declarationNode$decl.init;
535
- if (init && (init === node || init.type === "AwaitExpression" && init.argument === node)) {
536
- return declarationNode;
537
- }
538
- }
539
- const usedUtilityExports = new Set();
540
- esmWalker(ast, {
541
- onIdentifier(id, info, parentStack) {
542
- const binding = idToImportMap.get(id.name);
543
- if (!binding) {
544
- return;
545
- }
546
- if (info.hasBindingShortcut) {
547
- s.appendLeft(id.end, `: ${binding}`);
548
- } else if (info.classDeclaration) {
549
- if (!declaredConst.has(id.name)) {
550
- declaredConst.add(id.name);
551
- // locate the top-most node containing the class declaration
552
- const topNode = parentStack[parentStack.length - 2];
553
- s.prependRight(topNode.start, `const ${id.name} = ${binding};\n`);
554
- }
555
- } else if (!info.classExpression) {
556
- s.update(id.start, id.end, binding);
557
- }
558
- },
559
- onCallExpression(node) {
560
- if (node.callee.type === "MemberExpression" && isIdentifier(node.callee.object) && utilsObjectNames.includes(node.callee.object.name) && isIdentifier(node.callee.property)) {
561
- const methodName = node.callee.property.name;
562
- usedUtilityExports.add(node.callee.object.name);
563
- if (hoistableMockMethodNames.includes(methodName)) {
564
- const method = `${node.callee.object.name}.${methodName}`;
565
- assertNotDefaultExport(node, `Cannot export the result of "${method}". Remove export declaration because "${method}" doesn\'t return anything.`);
566
- const declarationNode = getVariableDeclaration(node);
567
- if (declarationNode) {
568
- assertNotNamedExport(declarationNode, `Cannot export the result of "${method}". Remove export declaration because "${method}" doesn\'t return anything.`);
569
- }
570
- // rewrite vi.mock(import('..')) into vi.mock('..')
571
- if (node.type === "CallExpression" && node.callee.type === "MemberExpression" && dynamicImportMockMethodNames.includes(node.callee.property.name)) {
572
- const moduleInfo = node.arguments[0];
573
- // vi.mock(import('./path')) -> vi.mock('./path')
574
- if (moduleInfo.type === "ImportExpression") {
575
- const source = moduleInfo.source;
576
- s.overwrite(moduleInfo.start, moduleInfo.end, s.slice(source.start, source.end));
577
- }
578
- // vi.mock(await import('./path')) -> vi.mock('./path')
579
- if (moduleInfo.type === "AwaitExpression" && moduleInfo.argument.type === "ImportExpression") {
580
- const source = moduleInfo.argument.source;
581
- s.overwrite(moduleInfo.start, moduleInfo.end, s.slice(source.start, source.end));
582
- }
583
- }
584
- hoistedNodes.push(node);
585
- } else if (dynamicImportMockMethodNames.includes(methodName)) {
586
- const moduleInfo = node.arguments[0];
587
- let source = null;
588
- if (moduleInfo.type === "ImportExpression") {
589
- source = moduleInfo.source;
590
- }
591
- if (moduleInfo.type === "AwaitExpression" && moduleInfo.argument.type === "ImportExpression") {
592
- source = moduleInfo.argument.source;
593
- }
594
- if (source) {
595
- s.overwrite(moduleInfo.start, moduleInfo.end, s.slice(source.start, source.end));
596
- }
597
- }
598
- if (hoistedMethodNames.includes(methodName)) {
599
- assertNotDefaultExport(node, "Cannot export hoisted variable. You can control hoisting behavior by placing the import from this file first.");
600
- const declarationNode = getVariableDeclaration(node);
601
- if (declarationNode) {
602
- assertNotNamedExport(declarationNode, "Cannot export hoisted variable. You can control hoisting behavior by placing the import from this file first.");
603
- // hoist "const variable = vi.hoisted(() => {})"
604
- hoistedNodes.push(declarationNode);
605
- } else {
606
- var _findNodeAround4;
607
- const awaitedExpression = (_findNodeAround4 = findNodeAround(ast, node.start, "AwaitExpression")) === null || _findNodeAround4 === void 0 ? void 0 : _findNodeAround4.node;
608
- // hoist "await vi.hoisted(async () => {})" or "vi.hoisted(() => {})"
609
- const moveNode = (awaitedExpression === null || awaitedExpression === void 0 ? void 0 : awaitedExpression.argument) === node ? awaitedExpression : node;
610
- hoistedNodes.push(moveNode);
611
- }
612
- }
613
- }
614
- }
615
- });
616
- function getNodeName(node) {
617
- const callee = node.callee || {};
618
- if (callee.type === "MemberExpression" && isIdentifier(callee.property) && isIdentifier(callee.object)) {
619
- return `${callee.object.name}.${callee.property.name}()`;
620
- }
621
- return "\"hoisted method\"";
622
- }
623
- function getNodeCall(node) {
624
- if (node.type === "CallExpression") {
625
- return node;
626
- }
627
- if (node.type === "VariableDeclaration") {
628
- const { declarations } = node;
629
- const init = declarations[0].init;
630
- if (init) {
631
- return getNodeCall(init);
632
- }
633
- }
634
- if (node.type === "AwaitExpression") {
635
- const { argument } = node;
636
- if (argument.type === "CallExpression") {
637
- return getNodeCall(argument);
638
- }
639
- }
640
- return node;
641
- }
642
- function createError(outsideNode, insideNode) {
643
- const outsideCall = getNodeCall(outsideNode);
644
- const insideCall = getNodeCall(insideNode);
645
- throw createSyntaxError(insideCall, `Cannot call ${getNodeName(insideCall)} inside ${getNodeName(outsideCall)}: both methods are hoisted to the top of the file and not actually called inside each other.`);
646
141
  }
647
- // validate hoistedNodes doesn't have nodes inside other nodes
648
- for (let i = 0; i < hoistedNodes.length; i++) {
649
- const node = hoistedNodes[i];
650
- for (let j = i + 1; j < hoistedNodes.length; j++) {
651
- const otherNode = hoistedNodes[j];
652
- if (node.start >= otherNode.start && node.end <= otherNode.end) {
653
- throw createError(otherNode, node);
654
- }
655
- if (otherNode.start >= node.start && otherNode.end <= node.end) {
656
- throw createError(node, otherNode);
657
- }
658
- }
659
- }
660
- // hoist vi.mock/vi.hoisted
661
- for (const node of hoistedNodes) {
662
- const end = getNodeTail(code, node);
663
- // don't hoist into itself if it's already at the top
664
- if (hoistIndex === end || hoistIndex === node.start) {
665
- hoistIndex = end;
666
- } else {
667
- s.move(node.start, end, hoistIndex);
668
- }
669
- }
670
- // hoist actual dynamic imports last so they are inserted after all hoisted mocks
671
- for (const { node: importNode, id: importId } of imports) {
672
- const source = importNode.source.value;
673
- s.update(importNode.start, importNode.end, `const ${importId} = await import(${JSON.stringify(source)});\n`);
674
- if (importNode.start === hoistIndex) {
675
- // no need to hoist, but update hoistIndex to keep the order
676
- hoistIndex = importNode.end;
677
- } else {
678
- // There will be an error if the module is called before it is imported,
679
- // so the module import statement is hoisted to the top
680
- s.move(importNode.start, importNode.end, hoistIndex);
681
- }
682
- }
683
- if (!hoistedModuleImported && hoistedNodes.length) {
684
- const utilityImports = [...usedUtilityExports];
685
- // "vi" or "vitest" is imported from a module other than "vitest"
686
- if (utilityImports.some((name) => idToImportMap.has(name))) {
687
- s.prepend(API_NOT_FOUND_CHECK(utilityImports));
688
- } else if (utilityImports.length) {
689
- s.prepend(`import { ${[...usedUtilityExports].join(", ")} } from ${JSON.stringify(hoistedModule)}\n`);
690
- }
691
- }
692
- return {
693
- code: s.toString(),
694
- map: s.generateMap({
695
- hires: "boundary",
696
- source: id
697
- })
698
- };
699
142
  }
700
143
 
701
144
  function interceptorPlugin(options = {}) {
@@ -793,9 +236,8 @@ class ServerMockResolver {
793
236
  const { id, fsPath, external } = await this.resolveMockId(rawId, importer);
794
237
  const resolvedUrl = this.normalizeResolveIdToUrl({ id }).url;
795
238
  if (options.mock === "factory") {
796
- var _manifest$fsPath;
797
239
  const manifest = getViteDepsManifest(this.server.config);
798
- const needsInterop = (manifest === null || manifest === void 0 || (_manifest$fsPath = manifest[fsPath]) === null || _manifest$fsPath === void 0 ? void 0 : _manifest$fsPath.needsInterop) ?? false;
240
+ const needsInterop = manifest?.[fsPath]?.needsInterop ?? false;
799
241
  return {
800
242
  mockType: "manual",
801
243
  resolvedId: id,
@@ -864,7 +306,7 @@ class ServerMockResolver {
864
306
  return this.resolveModule(rawId, resolved);
865
307
  }
866
308
  resolveModule(rawId, resolved) {
867
- const id = (resolved === null || resolved === void 0 ? void 0 : resolved.id) || rawId;
309
+ const id = resolved?.id || rawId;
868
310
  const external = !isAbsolute(id) || isModuleDirectory(this.options, id) ? rawId : null;
869
311
  return {
870
312
  id,
@@ -963,4 +405,4 @@ function mockerPlugin(options = {}) {
963
405
  ];
964
406
  }
965
407
 
966
- export { ServerMockResolver, automockModule, automockPlugin, createManualModuleSource, dynamicImportPlugin, findMockRedirect, hoistMocks, hoistMocksPlugin, interceptorPlugin, mockerPlugin };
408
+ export { ServerMockResolver, automockModule, automockPlugin, createManualModuleSource, dynamicImportPlugin, findMockRedirect, hoistMockAndResolve as hoistMocks, hoistMocksPlugin, interceptorPlugin, mockerPlugin };