@voidzero-dev/vite-plus-test 0.0.0-0bfcc90f.20260209-0731

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 (318) hide show
  1. package/LICENSE.md +691 -0
  2. package/browser/context.d.ts +4 -0
  3. package/browser/context.js +20 -0
  4. package/config.d.ts +3 -0
  5. package/coverage.d.ts +1 -0
  6. package/dist/@vitest/browser/client/.vite/manifest.json +24 -0
  7. package/dist/@vitest/browser/client/__vitest__/assets/index-BUCFJtth.js +57 -0
  8. package/dist/@vitest/browser/client/__vitest__/assets/index-DlhE0rqZ.css +1 -0
  9. package/dist/@vitest/browser/client/__vitest__/bg.png +0 -0
  10. package/dist/@vitest/browser/client/__vitest__/favicon.ico +0 -0
  11. package/dist/@vitest/browser/client/__vitest__/favicon.svg +5 -0
  12. package/dist/@vitest/browser/client/__vitest__/index.html +32 -0
  13. package/dist/@vitest/browser/client/__vitest_browser__/orchestrator-S_3e_uzt.js +345 -0
  14. package/dist/@vitest/browser/client/__vitest_browser__/tester-k74mgIRa.js +2171 -0
  15. package/dist/@vitest/browser/client/__vitest_browser__/utils-uxqdqUz8.js +223 -0
  16. package/dist/@vitest/browser/client/error-catcher.js +82 -0
  17. package/dist/@vitest/browser/client/esm-client-injector.js +67 -0
  18. package/dist/@vitest/browser/client/favicon.svg +5 -0
  19. package/dist/@vitest/browser/client/orchestrator.html +35 -0
  20. package/dist/@vitest/browser/client/tester/tester.html +13 -0
  21. package/dist/@vitest/browser/client.js +456 -0
  22. package/dist/@vitest/browser/context.d.ts +792 -0
  23. package/dist/@vitest/browser/context.js +541 -0
  24. package/dist/@vitest/browser/expect-element.js +32 -0
  25. package/dist/@vitest/browser/index-D6m36C6U.js +11 -0
  26. package/dist/@vitest/browser/index.d.ts +73 -0
  27. package/dist/@vitest/browser/index.js +3513 -0
  28. package/dist/@vitest/browser/jest-dom.d.ts +724 -0
  29. package/dist/@vitest/browser/locators.d.ts +354 -0
  30. package/dist/@vitest/browser/locators.js +1 -0
  31. package/dist/@vitest/browser/matchers.d.ts +29 -0
  32. package/dist/@vitest/browser/shared/screenshotMatcher/types.d.ts +22 -0
  33. package/dist/@vitest/browser/state.js +280 -0
  34. package/dist/@vitest/browser/types.d.ts +69 -0
  35. package/dist/@vitest/browser-playwright/context.d.ts +1 -0
  36. package/dist/@vitest/browser-playwright/index.d.ts +106 -0
  37. package/dist/@vitest/browser-playwright/index.js +1111 -0
  38. package/dist/@vitest/browser-playwright/locators.js +114 -0
  39. package/dist/@vitest/browser-preview/context.d.ts +1 -0
  40. package/dist/@vitest/browser-preview/index.d.ts +19 -0
  41. package/dist/@vitest/browser-preview/index.js +148 -0
  42. package/dist/@vitest/browser-preview/locators.js +79 -0
  43. package/dist/@vitest/browser-webdriverio/context.d.ts +1 -0
  44. package/dist/@vitest/browser-webdriverio/index.d.ts +63 -0
  45. package/dist/@vitest/browser-webdriverio/index.js +600 -0
  46. package/dist/@vitest/browser-webdriverio/locators.js +163 -0
  47. package/dist/@vitest/expect/index.d.ts +807 -0
  48. package/dist/@vitest/expect/index.js +1875 -0
  49. package/dist/@vitest/mocker/auto-register.d.ts +2 -0
  50. package/dist/@vitest/mocker/auto-register.js +9 -0
  51. package/dist/@vitest/mocker/automock.d.ts +12 -0
  52. package/dist/@vitest/mocker/automock.js +1 -0
  53. package/dist/@vitest/mocker/browser.d.ts +53 -0
  54. package/dist/@vitest/mocker/browser.js +91 -0
  55. package/dist/@vitest/mocker/chunk-automock.js +354 -0
  56. package/dist/@vitest/mocker/chunk-interceptor-native.js +15 -0
  57. package/dist/@vitest/mocker/chunk-mocker.js +521 -0
  58. package/dist/@vitest/mocker/chunk-pathe.M-eThtNZ.js +174 -0
  59. package/dist/@vitest/mocker/chunk-registry.js +185 -0
  60. package/dist/@vitest/mocker/chunk-utils.js +16 -0
  61. package/dist/@vitest/mocker/index.d-C-sLYZi-.d.ts +25 -0
  62. package/dist/@vitest/mocker/index.d.ts +2 -0
  63. package/dist/@vitest/mocker/index.js +185 -0
  64. package/dist/@vitest/mocker/mocker.d-TnKRhz7N.d.ts +81 -0
  65. package/dist/@vitest/mocker/node.d.ts +800 -0
  66. package/dist/@vitest/mocker/node.js +966 -0
  67. package/dist/@vitest/mocker/redirect.d.ts +3 -0
  68. package/dist/@vitest/mocker/redirect.js +79 -0
  69. package/dist/@vitest/mocker/register.d.ts +9 -0
  70. package/dist/@vitest/mocker/register.js +41 -0
  71. package/dist/@vitest/mocker/types.d-B8CCKmHt.d.ts +107 -0
  72. package/dist/@vitest/pretty-format/index.d.ts +124 -0
  73. package/dist/@vitest/pretty-format/index.js +1022 -0
  74. package/dist/@vitest/runner/chunk-tasks.js +340 -0
  75. package/dist/@vitest/runner/index.d.ts +180 -0
  76. package/dist/@vitest/runner/index.js +2114 -0
  77. package/dist/@vitest/runner/tasks.d-C7UxawJ9.d.ts +834 -0
  78. package/dist/@vitest/runner/types.d.ts +183 -0
  79. package/dist/@vitest/runner/types.js +1 -0
  80. package/dist/@vitest/runner/utils.d.ts +45 -0
  81. package/dist/@vitest/runner/utils.js +5 -0
  82. package/dist/@vitest/snapshot/environment.d-DHdQ1Csl.d.ts +22 -0
  83. package/dist/@vitest/snapshot/environment.d.ts +16 -0
  84. package/dist/@vitest/snapshot/environment.js +40 -0
  85. package/dist/@vitest/snapshot/index.d.ts +130 -0
  86. package/dist/@vitest/snapshot/index.js +1437 -0
  87. package/dist/@vitest/snapshot/manager.d.ts +18 -0
  88. package/dist/@vitest/snapshot/manager.js +73 -0
  89. package/dist/@vitest/snapshot/rawSnapshot.d-lFsMJFUd.d.ts +61 -0
  90. package/dist/@vitest/spy/index.d.ts +384 -0
  91. package/dist/@vitest/spy/index.js +433 -0
  92. package/dist/@vitest/utils/chunk-_commonjsHelpers.js +5 -0
  93. package/dist/@vitest/utils/chunk-pathe.M-eThtNZ.js +156 -0
  94. package/dist/@vitest/utils/constants.d.ts +21 -0
  95. package/dist/@vitest/utils/constants.js +49 -0
  96. package/dist/@vitest/utils/diff.d.ts +93 -0
  97. package/dist/@vitest/utils/diff.js +2199 -0
  98. package/dist/@vitest/utils/display.d.ts +29 -0
  99. package/dist/@vitest/utils/display.js +742 -0
  100. package/dist/@vitest/utils/error.d.ts +7 -0
  101. package/dist/@vitest/utils/error.js +42 -0
  102. package/dist/@vitest/utils/helpers.d.ts +73 -0
  103. package/dist/@vitest/utils/helpers.js +295 -0
  104. package/dist/@vitest/utils/highlight.d.ts +9 -0
  105. package/dist/@vitest/utils/highlight.js +538 -0
  106. package/dist/@vitest/utils/index.d.ts +5 -0
  107. package/dist/@vitest/utils/index.js +1 -0
  108. package/dist/@vitest/utils/offset.d.ts +5 -0
  109. package/dist/@vitest/utils/offset.js +32 -0
  110. package/dist/@vitest/utils/resolver.d.ts +7 -0
  111. package/dist/@vitest/utils/resolver.js +71 -0
  112. package/dist/@vitest/utils/serialize.d.ts +3 -0
  113. package/dist/@vitest/utils/serialize.js +118 -0
  114. package/dist/@vitest/utils/source-map.d.ts +55 -0
  115. package/dist/@vitest/utils/source-map.js +478 -0
  116. package/dist/@vitest/utils/timers.d.ts +33 -0
  117. package/dist/@vitest/utils/timers.js +49 -0
  118. package/dist/@vitest/utils/types.d-BCElaP-c.d.ts +53 -0
  119. package/dist/@vitest/utils/types.d.ts +34 -0
  120. package/dist/@vitest/utils/types.js +1 -0
  121. package/dist/browser-compat.js +3 -0
  122. package/dist/browser.d.ts +46 -0
  123. package/dist/browser.js +20 -0
  124. package/dist/chunks/_commonjsHelpers.D26ty3Ew.js +6 -0
  125. package/dist/chunks/base.CJ0Y4ePK.js +165 -0
  126. package/dist/chunks/benchmark.B3N2zMcH.js +40 -0
  127. package/dist/chunks/benchmark.d.DAaHLpsq.d.ts +24 -0
  128. package/dist/chunks/browser.d.ChKACdzH.d.ts +59 -0
  129. package/dist/chunks/cac.DVeoLl0M.js +1409 -0
  130. package/dist/chunks/cli-api.B7PN_QUv.js +13672 -0
  131. package/dist/chunks/config.d.Cy95HiCx.d.ts +210 -0
  132. package/dist/chunks/console.Cf-YriPC.js +146 -0
  133. package/dist/chunks/constants.D_Q9UYh-.js +36 -0
  134. package/dist/chunks/coverage.AVPTjMgw.js +3292 -0
  135. package/dist/chunks/coverage.D_JHT54q.js +25 -0
  136. package/dist/chunks/coverage.d.BZtK59WP.d.ts +37 -0
  137. package/dist/chunks/creator.DAmOKTvJ.js +673 -0
  138. package/dist/chunks/date.Bq6ZW5rf.js +73 -0
  139. package/dist/chunks/defaults.BOqNVLsY.js +74 -0
  140. package/dist/chunks/env.D4Lgay0q.js +8 -0
  141. package/dist/chunks/environment.d.CrsxCzP1.d.ts +29 -0
  142. package/dist/chunks/evaluatedModules.Dg1zASAC.js +17 -0
  143. package/dist/chunks/evaluatedModules.d.BxJ5omdx.d.ts +7 -0
  144. package/dist/chunks/git.Bm2pzPAa.js +71 -0
  145. package/dist/chunks/global.d.B15mdLcR.d.ts +99 -0
  146. package/dist/chunks/globals.DOayXfHP.js +30 -0
  147. package/dist/chunks/index.6Qv1eEA6.js +109 -0
  148. package/dist/chunks/index.C5r1PdPD.js +231 -0
  149. package/dist/chunks/index.Chj8NDwU.js +206 -0
  150. package/dist/chunks/index.CyBMJtT7.js +727 -0
  151. package/dist/chunks/index.D3XRDfWc.js +213 -0
  152. package/dist/chunks/index.D4KonVSU.js +6343 -0
  153. package/dist/chunks/index.M8mOzt4Y.js +3839 -0
  154. package/dist/chunks/index.Z5E_ObnR.js +37 -0
  155. package/dist/chunks/init-forks._y3TW739.js +41 -0
  156. package/dist/chunks/init-threads.DBO2kn-p.js +18 -0
  157. package/dist/chunks/init.B6MLFIaN.js +334 -0
  158. package/dist/chunks/inspector.CvyFGlXm.js +53 -0
  159. package/dist/chunks/modules.BJuCwlRJ.js +36 -0
  160. package/dist/chunks/node.Ce0vMQM7.js +14 -0
  161. package/dist/chunks/plugin.d.CtqpEehP.d.ts +38 -0
  162. package/dist/chunks/reporters.d.CWXNI2jG.d.ts +3271 -0
  163. package/dist/chunks/rpc.BoxB0q7B.js +76 -0
  164. package/dist/chunks/rpc.d.RH3apGEf.d.ts +64 -0
  165. package/dist/chunks/setup-common.Cm-kSBVi.js +60 -0
  166. package/dist/chunks/startModuleRunner.DEj0jb3e.js +861 -0
  167. package/dist/chunks/suite.d.BJWk38HB.d.ts +10 -0
  168. package/dist/chunks/test.B8ej_ZHS.js +254 -0
  169. package/dist/chunks/traces.CCmnQaNT.js +217 -0
  170. package/dist/chunks/traces.d.402V_yFI.d.ts +18 -0
  171. package/dist/chunks/utils.DvEY5TfP.js +52 -0
  172. package/dist/chunks/vi.2VT5v0um.js +3919 -0
  173. package/dist/chunks/vm.D3epNOPZ.js +744 -0
  174. package/dist/chunks/worker.d.Dyxm8DEL.d.ts +255 -0
  175. package/dist/cli.js +28 -0
  176. package/dist/client/.vite/manifest.json +24 -0
  177. package/dist/client/__vitest__/assets/index-BUCFJtth.js +57 -0
  178. package/dist/client/__vitest__/assets/index-DlhE0rqZ.css +1 -0
  179. package/dist/client/__vitest__/bg.png +0 -0
  180. package/dist/client/__vitest__/favicon.ico +0 -0
  181. package/dist/client/__vitest__/favicon.svg +5 -0
  182. package/dist/client/__vitest__/index.html +32 -0
  183. package/dist/client/__vitest_browser__/orchestrator-S_3e_uzt.js +345 -0
  184. package/dist/client/__vitest_browser__/tester-k74mgIRa.js +2171 -0
  185. package/dist/client/__vitest_browser__/utils-uxqdqUz8.js +223 -0
  186. package/dist/client/error-catcher.js +82 -0
  187. package/dist/client/esm-client-injector.js +67 -0
  188. package/dist/client/favicon.svg +5 -0
  189. package/dist/client/orchestrator.html +35 -0
  190. package/dist/client/tester/tester.html +13 -0
  191. package/dist/client.js +456 -0
  192. package/dist/config.cjs +94 -0
  193. package/dist/config.d.ts +104 -0
  194. package/dist/config.js +15 -0
  195. package/dist/context.js +541 -0
  196. package/dist/coverage.d.ts +118 -0
  197. package/dist/coverage.js +23 -0
  198. package/dist/dummy.js +2 -0
  199. package/dist/environments.d.ts +22 -0
  200. package/dist/environments.js +3 -0
  201. package/dist/expect-element.js +27 -0
  202. package/dist/index-D6m36C6U.js +6 -0
  203. package/dist/index-node.js +7 -0
  204. package/dist/index.d.ts +510 -0
  205. package/dist/index.js +19 -0
  206. package/dist/locators.d.ts +354 -0
  207. package/dist/locators.js +1 -0
  208. package/dist/mocker.d.ts +1 -0
  209. package/dist/mocker.js +1 -0
  210. package/dist/module-evaluator.d.ts +124 -0
  211. package/dist/module-evaluator.js +343 -0
  212. package/dist/module-runner-stub.js +44 -0
  213. package/dist/module-runner.js +17 -0
  214. package/dist/node.d.ts +251 -0
  215. package/dist/node.js +98 -0
  216. package/dist/path.js +7 -0
  217. package/dist/plugins/browser-client.mjs +2 -0
  218. package/dist/plugins/browser-context.mjs +2 -0
  219. package/dist/plugins/browser-locators.mjs +2 -0
  220. package/dist/plugins/browser-playwright.mjs +2 -0
  221. package/dist/plugins/browser-preview.mjs +2 -0
  222. package/dist/plugins/browser-webdriverio.mjs +2 -0
  223. package/dist/plugins/browser.mjs +2 -0
  224. package/dist/plugins/expect.mjs +2 -0
  225. package/dist/plugins/mocker-automock.mjs +2 -0
  226. package/dist/plugins/mocker-browser.mjs +2 -0
  227. package/dist/plugins/mocker-node.mjs +2 -0
  228. package/dist/plugins/mocker-redirect.mjs +2 -0
  229. package/dist/plugins/mocker-register.mjs +2 -0
  230. package/dist/plugins/mocker.mjs +2 -0
  231. package/dist/plugins/pretty-format.mjs +2 -0
  232. package/dist/plugins/runner-types.mjs +2 -0
  233. package/dist/plugins/runner-utils.mjs +2 -0
  234. package/dist/plugins/runner.mjs +2 -0
  235. package/dist/plugins/snapshot-environment.mjs +2 -0
  236. package/dist/plugins/snapshot-manager.mjs +2 -0
  237. package/dist/plugins/snapshot.mjs +2 -0
  238. package/dist/plugins/spy.mjs +2 -0
  239. package/dist/plugins/utils-constants.mjs +2 -0
  240. package/dist/plugins/utils-diff.mjs +2 -0
  241. package/dist/plugins/utils-display.mjs +2 -0
  242. package/dist/plugins/utils-error.mjs +2 -0
  243. package/dist/plugins/utils-helpers.mjs +2 -0
  244. package/dist/plugins/utils-highlight.mjs +2 -0
  245. package/dist/plugins/utils-offset.mjs +2 -0
  246. package/dist/plugins/utils-resolver.mjs +2 -0
  247. package/dist/plugins/utils-serialize.mjs +2 -0
  248. package/dist/plugins/utils-source-map.mjs +2 -0
  249. package/dist/plugins/utils-timers.mjs +2 -0
  250. package/dist/plugins/utils.mjs +2 -0
  251. package/dist/reporters.d.ts +27 -0
  252. package/dist/reporters.js +24 -0
  253. package/dist/runners.d.ts +50 -0
  254. package/dist/runners.js +19 -0
  255. package/dist/shared/screenshotMatcher/types.d.ts +22 -0
  256. package/dist/snapshot.d.ts +9 -0
  257. package/dist/snapshot.js +4 -0
  258. package/dist/spy.js +1 -0
  259. package/dist/state.js +280 -0
  260. package/dist/suite.d.ts +5 -0
  261. package/dist/suite.js +6 -0
  262. package/dist/types.d.ts +69 -0
  263. package/dist/vendor/chai.d.mts +1 -0
  264. package/dist/vendor/chai.mjs +3577 -0
  265. package/dist/vendor/es-module-lexer.d.mts +193 -0
  266. package/dist/vendor/es-module-lexer.mjs +79 -0
  267. package/dist/vendor/estree-walker.d.mts +583 -0
  268. package/dist/vendor/estree-walker.mjs +339 -0
  269. package/dist/vendor/expect-type.d.mts +1574 -0
  270. package/dist/vendor/expect-type.mjs +214 -0
  271. package/dist/vendor/magic-string.d.mts +261 -0
  272. package/dist/vendor/magic-string.mjs +1700 -0
  273. package/dist/vendor/obug.d.mts +56 -0
  274. package/dist/vendor/obug.mjs +276 -0
  275. package/dist/vendor/pathe.d.mts +46 -0
  276. package/dist/vendor/pathe.mjs +496 -0
  277. package/dist/vendor/picomatch.d.mts +1 -0
  278. package/dist/vendor/picomatch.mjs +1855 -0
  279. package/dist/vendor/shared-3g9mwCWP.mjs +31 -0
  280. package/dist/vendor/std-env.d.mts +88 -0
  281. package/dist/vendor/std-env.mjs +159 -0
  282. package/dist/vendor/tinybench.d.mts +317 -0
  283. package/dist/vendor/tinybench.mjs +504 -0
  284. package/dist/vendor/tinyexec.d.mts +72 -0
  285. package/dist/vendor/tinyexec.mjs +637 -0
  286. package/dist/vendor/tinyglobby.d.mts +157 -0
  287. package/dist/vendor/tinyglobby.mjs +832 -0
  288. package/dist/vendor/tinyrainbow.d.mts +60 -0
  289. package/dist/vendor/tinyrainbow.mjs +93 -0
  290. package/dist/vendor/vitest_browser.mjs +2 -0
  291. package/dist/vendor/vitest_internal_browser.mjs +2 -0
  292. package/dist/vendor/vitest_runner.mjs +2 -0
  293. package/dist/vendor/vitest_runners.mjs +2 -0
  294. package/dist/worker.d.ts +32 -0
  295. package/dist/worker.js +48 -0
  296. package/dist/workers/forks.js +54 -0
  297. package/dist/workers/runVmTests.js +95 -0
  298. package/dist/workers/threads.js +55 -0
  299. package/dist/workers/vmForks.js +36 -0
  300. package/dist/workers/vmThreads.js +37 -0
  301. package/environments.d.ts +1 -0
  302. package/globals.d.ts +20 -0
  303. package/import-meta.d.ts +5 -0
  304. package/importMeta.d.ts +4 -0
  305. package/index.cjs +5 -0
  306. package/index.d.cts +1 -0
  307. package/jsdom.d.ts +6 -0
  308. package/mocker.d.ts +1 -0
  309. package/node.d.ts +1 -0
  310. package/optional-types.d.ts +7 -0
  311. package/package.json +335 -0
  312. package/reporters.d.ts +1 -0
  313. package/runners.d.ts +1 -0
  314. package/snapshot.d.ts +1 -0
  315. package/suite.d.ts +1 -0
  316. package/suppress-warnings.cjs +21 -0
  317. package/vitest.mjs +2 -0
  318. package/worker.d.ts +1 -0
@@ -0,0 +1,10 @@
1
+ import { Test } from '../@vitest/runner/index.js';
2
+ import { c as BenchmarkAPI, a as BenchFunction } from './benchmark.d.DAaHLpsq.js';
3
+ import { Options } from '../vendor/tinybench.mjs';
4
+ import '../@vitest/runner/utils.js';
5
+
6
+ declare function getBenchOptions(key: Test): Options;
7
+ declare function getBenchFn(key: Test): BenchFunction;
8
+ declare const bench: BenchmarkAPI;
9
+
10
+ export { getBenchOptions as a, bench as b, getBenchFn as g };
@@ -0,0 +1,254 @@
1
+ import { updateTask } from '../@vitest/runner/index.js';
2
+ import { createDefer } from '../@vitest/utils/helpers.js';
3
+ import { getSafeTimers } from '../@vitest/utils/timers.js';
4
+ import { a as getBenchOptions, g as getBenchFn } from './benchmark.B3N2zMcH.js';
5
+ import { g as getWorkerState } from './utils.DvEY5TfP.js';
6
+ import { setState, GLOBAL_EXPECT, getState } from '../@vitest/expect/index.js';
7
+ import { getTests, getNames, getTestName } from '../@vitest/runner/utils.js';
8
+ import { processError } from '../@vitest/utils/error.js';
9
+ import { normalize } from '../vendor/pathe.mjs';
10
+ import { a as getSnapshotClient, i as inject, c as createExpect, v as vi } from './vi.2VT5v0um.js';
11
+ import { r as rpc } from './rpc.BoxB0q7B.js';
12
+
13
+ function createBenchmarkResult(name) {
14
+ return {
15
+ name,
16
+ rank: 0,
17
+ rme: 0,
18
+ samples: []
19
+ };
20
+ }
21
+ const benchmarkTasks = /* @__PURE__ */ new WeakMap();
22
+ async function runBenchmarkSuite(suite, runner) {
23
+ const { Task, Bench } = await runner.importTinybench();
24
+ const start = performance.now();
25
+ const benchmarkGroup = [];
26
+ const benchmarkSuiteGroup = [];
27
+ for (const task of suite.tasks) {
28
+ if (task.mode !== "run" && task.mode !== "queued") continue;
29
+ if (task.meta?.benchmark) benchmarkGroup.push(task);
30
+ else if (task.type === "suite") benchmarkSuiteGroup.push(task);
31
+ }
32
+ // run sub suites sequentially
33
+ for (const subSuite of benchmarkSuiteGroup) await runBenchmarkSuite(subSuite, runner);
34
+ if (benchmarkGroup.length) {
35
+ const defer = createDefer();
36
+ suite.result = {
37
+ state: "run",
38
+ startTime: start,
39
+ benchmark: createBenchmarkResult(suite.name)
40
+ };
41
+ updateTask$1("suite-prepare", suite);
42
+ const addBenchTaskListener = (task, benchmark) => {
43
+ task.addEventListener("complete", (e) => {
44
+ const taskRes = e.task.result;
45
+ const result = benchmark.result.benchmark;
46
+ benchmark.result.state = "pass";
47
+ Object.assign(result, taskRes);
48
+ // compute extra stats and free raw samples as early as possible
49
+ const samples = result.samples;
50
+ result.sampleCount = samples.length;
51
+ result.median = samples.length % 2 ? samples[Math.floor(samples.length / 2)] : (samples[samples.length / 2] + samples[samples.length / 2 - 1]) / 2;
52
+ if (!runner.config.benchmark?.includeSamples) result.samples.length = 0;
53
+ updateTask$1("test-finished", benchmark);
54
+ }, { once: true });
55
+ task.addEventListener("error", (e) => {
56
+ const task = e.task;
57
+ defer.reject(benchmark ? task.result.error : e);
58
+ }, { once: true });
59
+ };
60
+ benchmarkGroup.forEach((benchmark) => {
61
+ const benchmarkInstance = new Bench(getBenchOptions(benchmark));
62
+ const benchmarkFn = getBenchFn(benchmark);
63
+ benchmark.result = {
64
+ state: "run",
65
+ startTime: start,
66
+ benchmark: createBenchmarkResult(benchmark.name)
67
+ };
68
+ const task = new Task(benchmarkInstance, benchmark.name, benchmarkFn);
69
+ benchmarkTasks.set(benchmark, task);
70
+ addBenchTaskListener(task, benchmark);
71
+ });
72
+ const { setTimeout } = getSafeTimers();
73
+ const tasks = [];
74
+ for (const benchmark of benchmarkGroup) {
75
+ const task = benchmarkTasks.get(benchmark);
76
+ updateTask$1("test-prepare", benchmark);
77
+ await task.warmup();
78
+ tasks.push([await new Promise((resolve) => setTimeout(async () => {
79
+ resolve(await task.run());
80
+ })), benchmark]);
81
+ }
82
+ suite.result.duration = performance.now() - start;
83
+ suite.result.state = "pass";
84
+ updateTask$1("suite-finished", suite);
85
+ defer.resolve(null);
86
+ await defer;
87
+ }
88
+ function updateTask$1(event, task) {
89
+ updateTask(event, task, runner);
90
+ }
91
+ }
92
+ class NodeBenchmarkRunner {
93
+ moduleRunner;
94
+ constructor(config) {
95
+ this.config = config;
96
+ }
97
+ async importTinybench() {
98
+ return await import('../vendor/tinybench.mjs');
99
+ }
100
+ importFile(filepath, source) {
101
+ if (source === "setup") {
102
+ const moduleNode = getWorkerState().evaluatedModules.getModuleById(filepath);
103
+ if (moduleNode) getWorkerState().evaluatedModules.invalidateModule(moduleNode);
104
+ }
105
+ return this.moduleRunner.import(filepath);
106
+ }
107
+ async runSuite(suite) {
108
+ await runBenchmarkSuite(suite, this);
109
+ }
110
+ async runTask() {
111
+ throw new Error("`test()` and `it()` is only available in test mode.");
112
+ }
113
+ }
114
+
115
+ // worker context is shared between all tests
116
+ const workerContext = Object.create(null);
117
+ class VitestTestRunner {
118
+ snapshotClient = getSnapshotClient();
119
+ workerState = getWorkerState();
120
+ moduleRunner;
121
+ cancelRun = false;
122
+ assertionsErrors = /* @__PURE__ */ new WeakMap();
123
+ pool = this.workerState.ctx.pool;
124
+ _otel;
125
+ viteEnvironment;
126
+ constructor(config) {
127
+ this.config = config;
128
+ const environment = this.workerState.environment;
129
+ this.viteEnvironment = environment.viteEnvironment || environment.name;
130
+ }
131
+ importFile(filepath, source) {
132
+ if (source === "setup") {
133
+ const moduleNode = this.workerState.evaluatedModules.getModuleById(filepath);
134
+ if (moduleNode) this.workerState.evaluatedModules.invalidateModule(moduleNode);
135
+ }
136
+ return this._otel.$(`vitest.module.import_${source === "setup" ? "setup" : "spec"}`, { attributes: { "code.file.path": filepath } }, () => this.moduleRunner.import(filepath));
137
+ }
138
+ onCollectStart(file) {
139
+ this.workerState.current = file;
140
+ }
141
+ onCleanupWorkerContext(listener) {
142
+ this.workerState.onCleanup(listener);
143
+ }
144
+ onAfterRunFiles() {
145
+ this.snapshotClient.clear();
146
+ this.workerState.current = void 0;
147
+ }
148
+ getWorkerContext() {
149
+ return workerContext;
150
+ }
151
+ async onAfterRunSuite(suite) {
152
+ if (this.config.logHeapUsage && typeof process !== "undefined") suite.result.heap = process.memoryUsage().heapUsed;
153
+ if (suite.mode !== "skip" && "filepath" in suite) {
154
+ // mark snapshots in skipped tests as not obsolete
155
+ for (const test of getTests(suite)) if (test.mode === "skip") {
156
+ const name = getNames(test).slice(1).join(" > ");
157
+ this.snapshotClient.skipTest(suite.file.filepath, name);
158
+ }
159
+ const result = await this.snapshotClient.finish(suite.file.filepath);
160
+ if (this.workerState.config.snapshotOptions.updateSnapshot === "none" && result.unchecked) {
161
+ let message = `Obsolete snapshots found when no snapshot update is expected.\n`;
162
+ for (const key of result.uncheckedKeys) message += `· ${key}\n`;
163
+ suite.result.errors ??= [];
164
+ suite.result.errors.push(processError(new Error(message)));
165
+ suite.result.state = "fail";
166
+ }
167
+ await rpc().snapshotSaved(result);
168
+ }
169
+ this.workerState.current = suite.suite || suite.file;
170
+ }
171
+ onAfterRunTask(test) {
172
+ if (this.config.logHeapUsage && typeof process !== "undefined") test.result.heap = process.memoryUsage().heapUsed;
173
+ this.workerState.current = test.suite || test.file;
174
+ }
175
+ cancel(_reason) {
176
+ this.cancelRun = true;
177
+ }
178
+ injectValue(key) {
179
+ // inject has a very limiting type controlled by ProvidedContext
180
+ // some tests override it which causes the build to fail
181
+ return inject(key);
182
+ }
183
+ async onBeforeRunTask(test) {
184
+ if (this.cancelRun) test.mode = "skip";
185
+ if (test.mode !== "run" && test.mode !== "queued") return;
186
+ this.workerState.current = test;
187
+ }
188
+ async onBeforeRunSuite(suite) {
189
+ if (this.cancelRun) suite.mode = "skip";
190
+ // initialize snapshot state before running file suite
191
+ if (suite.mode !== "skip" && "filepath" in suite) await this.snapshotClient.setup(suite.file.filepath, this.workerState.config.snapshotOptions);
192
+ this.workerState.current = suite;
193
+ }
194
+ onBeforeTryTask(test) {
195
+ clearModuleMocks(this.config);
196
+ this.snapshotClient.clearTest(test.file.filepath, test.id);
197
+ setState({
198
+ assertionCalls: 0,
199
+ isExpectingAssertions: false,
200
+ isExpectingAssertionsError: null,
201
+ expectedAssertionsNumber: null,
202
+ expectedAssertionsNumberErrorGen: null,
203
+ currentTestName: getTestName(test),
204
+ snapshotState: this.snapshotClient.getSnapshotState(test.file.filepath)
205
+ }, globalThis[GLOBAL_EXPECT]);
206
+ }
207
+ onAfterTryTask(test) {
208
+ const { assertionCalls, expectedAssertionsNumber, expectedAssertionsNumberErrorGen, isExpectingAssertions, isExpectingAssertionsError } = test.context._local ? test.context.expect.getState() : getState(globalThis[GLOBAL_EXPECT]);
209
+ if (expectedAssertionsNumber !== null && assertionCalls !== expectedAssertionsNumber) throw expectedAssertionsNumberErrorGen();
210
+ if (isExpectingAssertions === true && assertionCalls === 0) throw isExpectingAssertionsError;
211
+ if (this.config.expect.requireAssertions && assertionCalls === 0) throw this.assertionsErrors.get(test);
212
+ }
213
+ extendTaskContext(context) {
214
+ // create error during the test initialization so we have a nice stack trace
215
+ if (this.config.expect.requireAssertions) this.assertionsErrors.set(context.task, /* @__PURE__ */ new Error("expected any number of assertion, but got none"));
216
+ let _expect;
217
+ Object.defineProperty(context, "expect", { get() {
218
+ if (!_expect) _expect = createExpect(context.task);
219
+ return _expect;
220
+ } });
221
+ Object.defineProperty(context, "_local", { get() {
222
+ return _expect != null;
223
+ } });
224
+ return context;
225
+ }
226
+ getImportDurations() {
227
+ const importDurations = {};
228
+ const entries = this.workerState.moduleExecutionInfo?.entries() || [];
229
+ for (const [filepath, { duration, selfTime, external, importer }] of entries) importDurations[normalize(filepath)] = {
230
+ selfTime,
231
+ totalTime: duration,
232
+ external,
233
+ importer
234
+ };
235
+ return importDurations;
236
+ }
237
+ trace = (name, attributes, cb) => {
238
+ const options = typeof attributes === "object" ? { attributes } : {};
239
+ return this._otel.$(`vitest.test.runner.${name}`, options, cb || attributes);
240
+ };
241
+ __setTraces(traces) {
242
+ this._otel = traces;
243
+ }
244
+ }
245
+ function clearModuleMocks(config) {
246
+ const { clearMocks, mockReset, restoreMocks, unstubEnvs, unstubGlobals } = config;
247
+ if (restoreMocks) vi.restoreAllMocks();
248
+ if (mockReset) vi.resetAllMocks();
249
+ if (clearMocks) vi.clearAllMocks();
250
+ if (unstubEnvs) vi.unstubAllEnvs();
251
+ if (unstubGlobals) vi.unstubAllGlobals();
252
+ }
253
+
254
+ export { NodeBenchmarkRunner as N, VitestTestRunner as V };
@@ -0,0 +1,217 @@
1
+ class Traces {
2
+ /**
3
+ * otel stands for OpenTelemetry
4
+ */
5
+ #otel = null;
6
+ #sdk = null;
7
+ #init = null;
8
+ #noopSpan = createNoopSpan();
9
+ #noopContext = createNoopContext();
10
+ #initStartTime = performance.now();
11
+ #initEndTime = 0;
12
+ #initRecorded = false;
13
+ constructor(options) {
14
+ if (options.enabled) {
15
+ const apiInit = import('@opentelemetry/api').then((api) => {
16
+ this.#otel = {
17
+ tracer: api.trace.getTracer(options.tracerName || "vitest"),
18
+ context: api.context,
19
+ propagation: api.propagation,
20
+ trace: api.trace,
21
+ SpanKind: api.SpanKind,
22
+ SpanStatusCode: api.SpanStatusCode
23
+ };
24
+ }).catch(() => {
25
+ throw new Error(`"@opentelemetry/api" is not installed locally. Make sure you have setup OpenTelemetry instrumentation: https://vitest.dev/guide/open-telemetry`);
26
+ });
27
+ const sdkInit = (options.sdkPath ? import(
28
+ /* @vite-ignore */
29
+ options.sdkPath
30
+ ) : Promise.resolve()).catch((cause) => {
31
+ throw new Error(`Failed to import custom OpenTelemetry SDK script (${options.sdkPath}): ${cause.message}`);
32
+ });
33
+ this.#init = Promise.all([sdkInit, apiInit]).then(([sdk]) => {
34
+ if (sdk != null) {
35
+ if (sdk.default != null && typeof sdk.default === "object" && typeof sdk.default.shutdown === "function") this.#sdk = sdk.default;
36
+ else if (options.watchMode !== true && process.env.VITEST_MODE !== "watch") console.warn(`OpenTelemetry instrumentation module (${options.sdkPath}) does not have a default export with a "shutdown" method. Vitest won't be able to ensure that all traces are processed in time. Try running Vitest in watch mode instead.`);
37
+ }
38
+ }).finally(() => {
39
+ this.#initEndTime = performance.now();
40
+ this.#init = null;
41
+ });
42
+ }
43
+ }
44
+ isEnabled() {
45
+ return !!this.#otel;
46
+ }
47
+ /**
48
+ * @internal
49
+ */
50
+ async waitInit() {
51
+ if (this.#init) await this.#init;
52
+ return this;
53
+ }
54
+ /**
55
+ * @internal
56
+ */
57
+ recordInitSpan(context) {
58
+ if (this.#initRecorded) return;
59
+ this.#initRecorded = true;
60
+ this.startSpan("vitest.runtime.traces", { startTime: this.#initStartTime }, context).end(this.#initEndTime);
61
+ }
62
+ /**
63
+ * @internal
64
+ */
65
+ startContextSpan(name, currentContext) {
66
+ if (!this.#otel) return {
67
+ span: this.#noopSpan,
68
+ context: this.#noopContext
69
+ };
70
+ const activeContext = currentContext || this.#otel.context.active();
71
+ const span = this.#otel.tracer.startSpan(name, {}, activeContext);
72
+ return {
73
+ span,
74
+ context: this.#otel.trace.setSpan(activeContext, span)
75
+ };
76
+ }
77
+ /**
78
+ * @internal
79
+ */
80
+ getContextFromCarrier(carrier) {
81
+ if (!this.#otel) return this.#noopContext;
82
+ const activeContext = this.#otel.context.active();
83
+ if (!carrier) return activeContext;
84
+ return this.#otel.propagation.extract(activeContext, carrier);
85
+ }
86
+ /**
87
+ * @internal
88
+ */
89
+ getContextFromEnv(env) {
90
+ if (!this.#otel) return this.#noopContext;
91
+ // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/context/env-carriers.md
92
+ // some tools sets only `TRACEPARENT` but not `TRACESTATE`
93
+ const carrier = {};
94
+ if (typeof env.TRACEPARENT === "string") carrier.traceparent = env.TRACEPARENT;
95
+ if (typeof env.TRACESTATE === "string") carrier.tracestate = env.TRACESTATE;
96
+ return this.getContextFromCarrier(carrier);
97
+ }
98
+ /**
99
+ * @internal
100
+ */
101
+ getContextCarrier(context) {
102
+ if (!this.#otel) return;
103
+ const carrier = {};
104
+ this.#otel.propagation.inject(context || this.#otel.context.active(), carrier);
105
+ return carrier;
106
+ }
107
+ #callActiveSpan(span, callback) {
108
+ const otel = this.#otel;
109
+ let result;
110
+ try {
111
+ result = callback(span);
112
+ if (result instanceof Promise) return result.catch((error) => {
113
+ span.recordException({
114
+ name: error.name,
115
+ message: error.message,
116
+ stack: error.stack
117
+ });
118
+ span.setStatus({ code: otel.SpanStatusCode.ERROR });
119
+ throw error;
120
+ }).finally(() => span.end());
121
+ return result;
122
+ } catch (error) {
123
+ if (error instanceof Error) {
124
+ span.recordException({
125
+ name: error.name,
126
+ message: error.message,
127
+ stack: error.stack
128
+ });
129
+ span.setStatus({ code: otel.SpanStatusCode.ERROR });
130
+ }
131
+ throw error;
132
+ } finally {
133
+ // end sync callbcak
134
+ if (!(result instanceof Promise)) span.end();
135
+ }
136
+ }
137
+ /**
138
+ * @internal
139
+ */
140
+ $(name, optionsOrFn, fn) {
141
+ const callback = typeof optionsOrFn === "function" ? optionsOrFn : fn;
142
+ if (!this.#otel) return callback(this.#noopSpan);
143
+ const otel = this.#otel;
144
+ const options = typeof optionsOrFn === "function" ? {} : optionsOrFn;
145
+ const context = options.context;
146
+ if (context) return otel.tracer.startActiveSpan(name, options, context, (span) => this.#callActiveSpan(span, callback));
147
+ return otel.tracer.startActiveSpan(name, options, (span) => this.#callActiveSpan(span, callback));
148
+ }
149
+ /**
150
+ * @internal
151
+ */
152
+ startSpan(name, options, context) {
153
+ if (!this.#otel) return this.#noopSpan;
154
+ const { tracer } = this.#otel;
155
+ return tracer.startSpan(name, options, context);
156
+ }
157
+ // On browser mode, async context is not automatically propagated,
158
+ // so we manually bind the `$` calls to the provided context.
159
+ // TODO: this doesn't bind to user land's `@optelemetry/api` calls
160
+ /**
161
+ * @internal
162
+ */
163
+ bind(context) {
164
+ if (!this.#otel) return;
165
+ const original = this.$.__original ?? this.$;
166
+ this.$ = this.#otel.context.bind(context, original);
167
+ this.$.__original = original;
168
+ }
169
+ /**
170
+ * @internal
171
+ */
172
+ async finish() {
173
+ await this.#sdk?.shutdown();
174
+ }
175
+ /**
176
+ * @internal
177
+ */
178
+ async flush() {
179
+ await this.#sdk?.forceFlush?.();
180
+ }
181
+ }
182
+ function noopSpan() {
183
+ return this;
184
+ }
185
+ function createNoopSpan() {
186
+ return {
187
+ setAttribute: noopSpan,
188
+ setStatus: noopSpan,
189
+ addEvent: noopSpan,
190
+ addLink: noopSpan,
191
+ addLinks: noopSpan,
192
+ setAttributes: noopSpan,
193
+ updateName: noopSpan,
194
+ end: () => {},
195
+ isRecording: () => false,
196
+ recordException: noopSpan,
197
+ spanContext() {
198
+ return {
199
+ spanId: "",
200
+ traceFlags: 0,
201
+ traceId: ""
202
+ };
203
+ }
204
+ };
205
+ }
206
+ function noopContext() {
207
+ return this;
208
+ }
209
+ function createNoopContext() {
210
+ return {
211
+ getValue: noopContext,
212
+ setValue: noopContext,
213
+ deleteValue: noopContext
214
+ };
215
+ }
216
+
217
+ export { Traces as T };
@@ -0,0 +1,18 @@
1
+ interface OTELCarrier {
2
+ traceparent?: string;
3
+ tracestate?: string;
4
+ }
5
+ interface TracesOptions {
6
+ enabled: boolean;
7
+ watchMode?: boolean;
8
+ sdkPath?: string;
9
+ tracerName?: string;
10
+ }
11
+ declare class Traces {
12
+ #private;
13
+ constructor(options: TracesOptions);
14
+ isEnabled(): boolean;
15
+ }
16
+
17
+ export { Traces as T };
18
+ export type { OTELCarrier as O };
@@ -0,0 +1,52 @@
1
+ import { getSafeTimers } from '../@vitest/utils/timers.js';
2
+
3
+ const NAME_WORKER_STATE = "__vitest_worker__";
4
+ function getWorkerState() {
5
+ // @ts-expect-error untyped global
6
+ const workerState = globalThis[NAME_WORKER_STATE];
7
+ if (!workerState) throw new Error("Vitest failed to access its internal state.\n\nOne of the following is possible:\n- \"vitest\" is imported directly without running \"vitest\" command\n- \"vitest\" is imported inside \"globalSetup\" (to fix this, use \"setupFiles\" instead, because \"globalSetup\" runs in a different context)\n- \"vitest\" is imported inside Vite / Vitest config file\n- Otherwise, it might be a Vitest bug. Please report it to https://github.com/vitest-dev/vitest/issues\n");
8
+ return workerState;
9
+ }
10
+ function provideWorkerState(context, state) {
11
+ Object.defineProperty(context, NAME_WORKER_STATE, {
12
+ value: state,
13
+ configurable: true,
14
+ writable: true,
15
+ enumerable: false
16
+ });
17
+ return state;
18
+ }
19
+ function isChildProcess() {
20
+ return typeof process !== "undefined" && !!process.send;
21
+ }
22
+ function resetModules(modules, resetMocks = false) {
23
+ const skipPaths = [
24
+ /\/vitest\/dist\//,
25
+ /vitest-virtual-\w+\/dist/,
26
+ /@vitest\/dist/,
27
+ ...!resetMocks ? [/^mock:/] : []
28
+ ];
29
+ modules.idToModuleMap.forEach((node, path) => {
30
+ if (skipPaths.some((re) => re.test(path))) return;
31
+ node.promise = void 0;
32
+ node.exports = void 0;
33
+ node.evaluated = false;
34
+ node.importers.clear();
35
+ });
36
+ }
37
+ function waitNextTick() {
38
+ const { setTimeout } = getSafeTimers();
39
+ return new Promise((resolve) => setTimeout(resolve, 0));
40
+ }
41
+ async function waitForImportsToResolve() {
42
+ await waitNextTick();
43
+ const state = getWorkerState();
44
+ const promises = [];
45
+ const resolvingCount = state.resolvingModules.size;
46
+ for (const [_, mod] of state.evaluatedModules.idToModuleMap) if (mod.promise && !mod.evaluated) promises.push(mod.promise);
47
+ if (!promises.length && !resolvingCount) return;
48
+ await Promise.allSettled(promises);
49
+ await waitForImportsToResolve();
50
+ }
51
+
52
+ export { getWorkerState as g, isChildProcess as i, provideWorkerState as p, resetModules as r, waitForImportsToResolve as w };