@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,673 @@
1
+ import { existsSync, writeFileSync, readFileSync } from 'node:fs';
2
+ import { mkdir, writeFile } from 'node:fs/promises';
3
+ import { resolve, dirname, relative } from 'node:path';
4
+ import { detectPackageManager, installPackage } from './index.D3XRDfWc.js';
5
+ import { p as prompt, a as any } from './index.D4KonVSU.js';
6
+ import { x } from '../vendor/tinyexec.mjs';
7
+ import c from '../vendor/tinyrainbow.mjs';
8
+ import { c as configFiles } from './constants.D_Q9UYh-.js';
9
+ import 'node:process';
10
+ import 'node:module';
11
+ import 'node:url';
12
+ import './_commonjsHelpers.D26ty3Ew.js';
13
+ import 'readline';
14
+ import 'events';
15
+
16
+ const jsxExample = {
17
+ name: "HelloWorld.jsx",
18
+ js: `
19
+ export default function HelloWorld({ name }) {
20
+ return (
21
+ <div>
22
+ <h1>Hello {name}!</h1>
23
+ </div>
24
+ )
25
+ }
26
+ `,
27
+ ts: `
28
+ export default function HelloWorld({ name }: { name: string }) {
29
+ return (
30
+ <div>
31
+ <h1>Hello {name}!</h1>
32
+ </div>
33
+ )
34
+ }
35
+ `,
36
+ test: `
37
+ import { expect, test } from 'vitest'
38
+ import { render } from '@testing-library/jsx'
39
+ import HelloWorld from './HelloWorld.<EXT>x'
40
+
41
+ test('renders name', async () => {
42
+ const { getByText } = await render(<HelloWorld name="Vitest" />)
43
+ await expect.element(getByText('Hello Vitest!')).toBeInTheDocument()
44
+ })
45
+ `
46
+ };
47
+ const vueExample = {
48
+ name: "HelloWorld.vue",
49
+ js: `
50
+ <script setup>
51
+ defineProps({
52
+ name: String
53
+ })
54
+ <\/script>
55
+
56
+ <template>
57
+ <div>
58
+ <h1>Hello {{ name }}!</h1>
59
+ </div>
60
+ </template>
61
+ `,
62
+ ts: `
63
+ <script setup lang="ts">
64
+ defineProps<{
65
+ name: string
66
+ }>()
67
+ <\/script>
68
+
69
+ <template>
70
+ <div>
71
+ <h1>Hello {{ name }}!</h1>
72
+ </div>
73
+ </template>
74
+ `,
75
+ test: `
76
+ import { expect, test } from 'vitest'
77
+ import { render } from 'vitest-browser-vue'
78
+ import HelloWorld from './HelloWorld.vue'
79
+
80
+ test('renders name', async () => {
81
+ const { getByText } = render(HelloWorld, {
82
+ props: { name: 'Vitest' },
83
+ })
84
+ await expect.element(getByText('Hello Vitest!')).toBeInTheDocument()
85
+ })
86
+ `
87
+ };
88
+ const svelteExample = {
89
+ name: "HelloWorld.svelte",
90
+ js: `
91
+ <script>
92
+ export let name
93
+ <\/script>
94
+
95
+ <h1>Hello {name}!</h1>
96
+ `,
97
+ ts: `
98
+ <script lang="ts">
99
+ export let name: string
100
+ <\/script>
101
+
102
+ <h1>Hello {name}!</h1>
103
+ `,
104
+ test: `
105
+ import { expect, test } from 'vitest'
106
+ import { render } from 'vitest-browser-svelte'
107
+ import HelloWorld from './HelloWorld.svelte'
108
+
109
+ test('renders name', async () => {
110
+ const { getByText } = render(HelloWorld, { name: 'Vitest' })
111
+ await expect.element(getByText('Hello Vitest!')).toBeInTheDocument()
112
+ })
113
+ `
114
+ };
115
+ const markoExample = {
116
+ name: "HelloWorld.marko",
117
+ js: `
118
+ class {
119
+ onCreate() {
120
+ this.state = { name: null }
121
+ }
122
+ }
123
+
124
+ <h1>Hello \${state.name}!</h1>
125
+ `,
126
+ ts: `
127
+ export interface Input {
128
+ name: string
129
+ }
130
+
131
+ <h1>Hello \${input.name}!</h1>
132
+ `,
133
+ test: `
134
+ import { expect, test } from 'vitest'
135
+ import { render } from '@marko/testing-library'
136
+ import HelloWorld from './HelloWorld.svelte'
137
+
138
+ test('renders name', async () => {
139
+ const { getByText } = await render(HelloWorld, { name: 'Vitest' })
140
+ const element = getByText('Hello Vitest!')
141
+ expect(element).toBeInTheDocument()
142
+ })
143
+ `
144
+ };
145
+ const litExample = {
146
+ name: "HelloWorld.js",
147
+ js: `
148
+ import { html, LitElement } from 'lit'
149
+
150
+ export class HelloWorld extends LitElement {
151
+ static properties = {
152
+ name: { type: String },
153
+ }
154
+
155
+ constructor() {
156
+ super()
157
+ this.name = 'World'
158
+ }
159
+
160
+ render() {
161
+ return html\`<h1>Hello \${this.name}!</h1>\`
162
+ }
163
+ }
164
+
165
+ customElements.define('hello-world', HelloWorld)
166
+ `,
167
+ ts: `
168
+ import { html, LitElement } from 'lit'
169
+ import { customElement, property } from 'lit/decorators.js'
170
+
171
+ @customElement('hello-world')
172
+ export class HelloWorld extends LitElement {
173
+ @property({ type: String })
174
+ name = 'World'
175
+
176
+ render() {
177
+ return html\`<h1>Hello \${this.name}!</h1>\`
178
+ }
179
+ }
180
+
181
+ declare global {
182
+ interface HTMLElementTagNameMap {
183
+ 'hello-world': HelloWorld
184
+ }
185
+ }
186
+ `,
187
+ test: `
188
+ import { expect, test } from 'vitest'
189
+ import { render } from 'vitest-browser-lit'
190
+ import { html } from 'lit'
191
+ import './HelloWorld.js'
192
+
193
+ test('renders name', async () => {
194
+ const screen = render(html\`<hello-world name="Vitest"></hello-world>\`)
195
+ const element = screen.getByText('Hello Vitest!')
196
+ await expect.element(element).toBeInTheDocument()
197
+ })
198
+ `
199
+ };
200
+ const qwikExample = {
201
+ name: "HelloWorld.jsx",
202
+ js: `
203
+ import { component$ } from '@builder.io/qwik'
204
+
205
+ export default component$(({ name }) => {
206
+ return (
207
+ <div>
208
+ <h1>Hello {name}!</h1>
209
+ </div>
210
+ )
211
+ })
212
+ `,
213
+ ts: `
214
+ import { component$ } from '@builder.io/qwik'
215
+
216
+ export default component$(({ name }: { name: string }) => {
217
+ return (
218
+ <div>
219
+ <h1>Hello {name}!</h1>
220
+ </div>
221
+ )
222
+ })
223
+ `,
224
+ test: `
225
+ import { expect, test } from 'vitest'
226
+ import { render } from 'vitest-browser-qwik'
227
+ import HelloWorld from './HelloWorld.tsx'
228
+
229
+ test('renders name', async () => {
230
+ const { getByText } = render(<HelloWorld name="Vitest" />)
231
+ await expect.element(getByText('Hello Vitest!')).toBeInTheDocument()
232
+ })
233
+ `
234
+ };
235
+ const vanillaExample = {
236
+ name: "HelloWorld.js",
237
+ js: `
238
+ export default function HelloWorld({ name }) {
239
+ const parent = document.createElement('div')
240
+
241
+ const h1 = document.createElement('h1')
242
+ h1.textContent = 'Hello ' + name + '!'
243
+ parent.appendChild(h1)
244
+
245
+ return parent
246
+ }
247
+ `,
248
+ ts: `
249
+ export default function HelloWorld({ name }: { name: string }): HTMLDivElement {
250
+ const parent = document.createElement('div')
251
+
252
+ const h1 = document.createElement('h1')
253
+ h1.textContent = 'Hello ' + name + '!'
254
+ parent.appendChild(h1)
255
+
256
+ return parent
257
+ }
258
+ `,
259
+ test: `
260
+ import { expect, test } from 'vitest'
261
+ import { getByText } from '@testing-library/dom'
262
+ import HelloWorld from './HelloWorld.js'
263
+
264
+ test('renders name', () => {
265
+ const parent = HelloWorld({ name: 'Vitest' })
266
+ document.body.appendChild(parent)
267
+
268
+ const element = getByText(parent, 'Hello Vitest!')
269
+ expect(element).toBeInTheDocument()
270
+ })
271
+ `
272
+ };
273
+ function getExampleTest(framework) {
274
+ switch (framework) {
275
+ case "solid": return {
276
+ ...jsxExample,
277
+ test: jsxExample.test.replace("@testing-library/jsx", `@testing-library/${framework}`)
278
+ };
279
+ case "preact":
280
+ case "react": return {
281
+ ...jsxExample,
282
+ test: jsxExample.test.replace("@testing-library/jsx", `vitest-browser-${framework}`)
283
+ };
284
+ case "vue": return vueExample;
285
+ case "svelte": return svelteExample;
286
+ case "lit": return litExample;
287
+ case "marko": return markoExample;
288
+ case "qwik": return qwikExample;
289
+ default: return vanillaExample;
290
+ }
291
+ }
292
+ async function generateExampleFiles(framework, lang) {
293
+ const example = getExampleTest(framework);
294
+ let fileName = example.name;
295
+ const folder = resolve(process.cwd(), "vitest-example");
296
+ const fileContent = example[lang];
297
+ if (!existsSync(folder)) await mkdir(folder, { recursive: true });
298
+ const isJSX = fileName.endsWith(".jsx");
299
+ if (isJSX && lang === "ts") fileName = fileName.replace(".jsx", ".tsx");
300
+ else if (fileName.endsWith(".js") && lang === "ts") fileName = fileName.replace(".js", ".ts");
301
+ example.test = example.test.replace("<EXT>", lang);
302
+ const filePath = resolve(folder, fileName);
303
+ const testPath = resolve(folder, `HelloWorld.test.${isJSX ? `${lang}x` : lang}`);
304
+ writeFileSync(filePath, fileContent.trimStart(), "utf-8");
305
+ writeFileSync(testPath, example.test.trimStart(), "utf-8");
306
+ return testPath;
307
+ }
308
+
309
+ // eslint-disable-next-line no-console
310
+ const log = console.log;
311
+ function getProviderOptions() {
312
+ return Object.entries({
313
+ playwright: "Playwright relies on Chrome DevTools protocol. Read more: https://playwright.dev",
314
+ webdriverio: "WebdriverIO uses WebDriver protocol. Read more: https://webdriver.io",
315
+ preview: "Preview is useful to quickly run your tests in the browser, but not suitable for CI."
316
+ }).map(([provider, description]) => {
317
+ return {
318
+ title: provider,
319
+ description,
320
+ value: provider
321
+ };
322
+ });
323
+ }
324
+ function getBrowserNames(provider) {
325
+ switch (provider) {
326
+ case "webdriverio": return [
327
+ "chrome",
328
+ "firefox",
329
+ "edge",
330
+ "safari"
331
+ ];
332
+ case "playwright": return [
333
+ "chromium",
334
+ "firefox",
335
+ "webkit"
336
+ ];
337
+ case "preview": return [
338
+ "chrome",
339
+ "firefox",
340
+ "safari"
341
+ ];
342
+ }
343
+ }
344
+ function getFramework() {
345
+ return [
346
+ {
347
+ title: "vanilla",
348
+ value: "vanilla",
349
+ description: "No framework, just plain JavaScript or TypeScript."
350
+ },
351
+ {
352
+ title: "vue",
353
+ value: "vue",
354
+ description: "\"The Progressive JavaScript Framework\""
355
+ },
356
+ {
357
+ title: "svelte",
358
+ value: "svelte",
359
+ description: "\"Svelte: cybernetically enhanced web apps\""
360
+ },
361
+ {
362
+ title: "react",
363
+ value: "react",
364
+ description: "\"The library for web and native user interfaces\""
365
+ },
366
+ {
367
+ title: "lit",
368
+ value: "lit",
369
+ description: "\"A simple library for building fast, lightweight web components.\""
370
+ },
371
+ {
372
+ title: "preact",
373
+ value: "preact",
374
+ description: "\"Fast 3kB alternative to React with the same modern API\""
375
+ },
376
+ {
377
+ title: "solid",
378
+ value: "solid",
379
+ description: "\"Simple and performant reactivity for building user interfaces\""
380
+ },
381
+ {
382
+ title: "marko",
383
+ value: "marko",
384
+ description: "\"A declarative, HTML-based language that makes building web apps fun\""
385
+ },
386
+ {
387
+ title: "qwik",
388
+ value: "qwik",
389
+ description: "\"Instantly interactive web apps at scale\""
390
+ }
391
+ ];
392
+ }
393
+ function getFrameworkTestPackage(framework) {
394
+ switch (framework) {
395
+ case "vanilla": return null;
396
+ case "vue": return "vitest-browser-vue";
397
+ case "svelte": return "vitest-browser-svelte";
398
+ case "react": return "vitest-browser-react";
399
+ case "lit": return "vitest-browser-lit";
400
+ case "preact": return "vitest-browser-preact";
401
+ case "solid": return "@solidjs/testing-library";
402
+ case "marko": return "@marko/testing-library";
403
+ case "qwik": return "vitest-browser-qwik";
404
+ }
405
+ throw new Error(`Unsupported framework: ${framework}`);
406
+ }
407
+ function getFrameworkPluginPackage(framework) {
408
+ switch (framework) {
409
+ case "vue": return "@vitejs/plugin-vue";
410
+ case "svelte": return "@sveltejs/vite-plugin-svelte";
411
+ case "react": return "@vitejs/plugin-react";
412
+ case "preact": return "@preact/preset-vite";
413
+ case "solid": return "vite-plugin-solid";
414
+ case "marko": return "@marko/vite";
415
+ case "qwik": return "@builder.io/qwik/optimizer";
416
+ }
417
+ return null;
418
+ }
419
+ function getLanguageOptions() {
420
+ return [{
421
+ title: "TypeScript",
422
+ description: "Use TypeScript.",
423
+ value: "ts"
424
+ }, {
425
+ title: "JavaScript",
426
+ description: "Use plain JavaScript.",
427
+ value: "js"
428
+ }];
429
+ }
430
+ async function installPackages(pkgManager, packages) {
431
+ if (!packages.length) {
432
+ log(c.green("✔"), c.bold("All packages are already installed."));
433
+ return;
434
+ }
435
+ log(c.cyan("◼"), c.bold("Installing packages..."));
436
+ log(c.cyan("◼"), packages.join(", "));
437
+ log();
438
+ await installPackage(packages, {
439
+ dev: true,
440
+ packageManager: pkgManager ?? void 0
441
+ });
442
+ }
443
+ function readPkgJson(path) {
444
+ if (!existsSync(path)) return null;
445
+ const content = readFileSync(path, "utf-8");
446
+ return JSON.parse(content);
447
+ }
448
+ function getPossibleDefaults(dependencies) {
449
+ return {
450
+ lang: "ts",
451
+ provider: getPossibleProvider(dependencies),
452
+ framework: getPossibleFramework(dependencies)
453
+ };
454
+ }
455
+ function getPossibleFramework(dependencies) {
456
+ if (dependencies.vue || dependencies["vue-tsc"] || dependencies["@vue/reactivity"]) return "vue";
457
+ if (dependencies.react || dependencies["react-dom"]) return "react";
458
+ if (dependencies.svelte || dependencies["@sveltejs/kit"]) return "svelte";
459
+ if (dependencies.lit || dependencies["lit-html"]) return "lit";
460
+ if (dependencies.preact) return "preact";
461
+ if (dependencies["solid-js"] || dependencies["@solidjs/start"]) return "solid";
462
+ if (dependencies.marko) return "marko";
463
+ if (dependencies["@builder.io/qwik"] || dependencies["@qwik.dev/core"]) return "qwik";
464
+ return "vanilla";
465
+ }
466
+ function getPossibleProvider(dependencies) {
467
+ if (dependencies.webdriverio || dependencies["@wdio/cli"] || dependencies["@wdio/config"]) return "webdriverio";
468
+ // playwright is the default recommendation
469
+ return "playwright";
470
+ }
471
+ function getProviderDocsLink(provider) {
472
+ switch (provider) {
473
+ case "playwright": return "https://vitest.dev/config/browser/playwright";
474
+ case "webdriverio": return "https://vitest.dev/config/browser/webdriverio";
475
+ }
476
+ }
477
+ function sort(choices, value) {
478
+ const index = choices.findIndex((i) => i.value === value);
479
+ if (index === -1) return choices;
480
+ return [choices.splice(index, 1)[0], ...choices];
481
+ }
482
+ function fail() {
483
+ process.exitCode = 1;
484
+ }
485
+ function getFrameworkImportInfo(framework) {
486
+ switch (framework) {
487
+ case "svelte": return {
488
+ importName: "svelte",
489
+ isNamedExport: true
490
+ };
491
+ case "qwik": return {
492
+ importName: "qwikVite",
493
+ isNamedExport: true
494
+ };
495
+ default: return {
496
+ importName: framework,
497
+ isNamedExport: false
498
+ };
499
+ }
500
+ }
501
+ async function generateFrameworkConfigFile(options) {
502
+ const { importName, isNamedExport } = getFrameworkImportInfo(options.framework);
503
+ const frameworkImport = isNamedExport ? `import { ${importName} } from '${options.frameworkPlugin}'` : `import ${importName} from '${options.frameworkPlugin}'`;
504
+ const configContent = [
505
+ `import { defineConfig } from 'vitest/config'`,
506
+ `import { ${options.provider} } from '@vitest/browser-${options.provider}'`,
507
+ options.frameworkPlugin ? frameworkImport : null,
508
+ ``,
509
+ "export default defineConfig({",
510
+ options.frameworkPlugin ? ` plugins: [${importName}()],` : null,
511
+ ` test: {`,
512
+ ` browser: {`,
513
+ ` enabled: true,`,
514
+ ` provider: ${options.provider}(),`,
515
+ options.provider !== "preview" && ` // ${getProviderDocsLink(options.provider)}`,
516
+ ` instances: [`,
517
+ ...options.browsers.map((browser) => ` { browser: '${browser}' },`),
518
+ ` ],`,
519
+ ` },`,
520
+ ` },`,
521
+ `})`,
522
+ ""
523
+ ].filter((t) => typeof t === "string").join("\n");
524
+ await writeFile(options.configPath, configContent);
525
+ }
526
+ async function updatePkgJsonScripts(pkgJsonPath, vitestScript) {
527
+ if (!existsSync(pkgJsonPath)) {
528
+ const pkg = { scripts: { "test:browser": vitestScript } };
529
+ await writeFile(pkgJsonPath, `${JSON.stringify(pkg, null, 2)}\n`, "utf-8");
530
+ } else {
531
+ const pkg = JSON.parse(readFileSync(pkgJsonPath, "utf-8"));
532
+ pkg.scripts = pkg.scripts || {};
533
+ pkg.scripts["test:browser"] = vitestScript;
534
+ await writeFile(pkgJsonPath, `${JSON.stringify(pkg, null, 2)}\n`, "utf-8");
535
+ }
536
+ log(c.green("✔"), "Added \"test:browser\" script to your package.json.");
537
+ }
538
+ function getRunScript(pkgManager) {
539
+ switch (pkgManager) {
540
+ case "yarn@berry":
541
+ case "yarn": return "yarn test:browser";
542
+ case "pnpm@6":
543
+ case "pnpm": return "pnpm test:browser";
544
+ case "bun": return "bun test:browser";
545
+ default: return "npm run test:browser";
546
+ }
547
+ }
548
+ function getPlaywrightRunArgs(pkgManager) {
549
+ switch (pkgManager) {
550
+ case "yarn@berry":
551
+ case "yarn": return ["yarn", "exec"];
552
+ case "pnpm@6":
553
+ case "pnpm": return ["pnpx"];
554
+ case "bun": return ["bunx"];
555
+ default: return ["npx"];
556
+ }
557
+ }
558
+ async function create() {
559
+ log(c.cyan("◼"), "This utility will help you set up a browser testing environment.\n");
560
+ const pkgJsonPath = resolve(process.cwd(), "package.json");
561
+ const pkg = readPkgJson(pkgJsonPath) || {};
562
+ const dependencies = {
563
+ ...pkg.dependencies,
564
+ ...pkg.devDependencies
565
+ };
566
+ const defaults = getPossibleDefaults(dependencies);
567
+ const { lang } = await prompt({
568
+ type: "select",
569
+ name: "lang",
570
+ message: "Choose a language for your tests",
571
+ choices: sort(getLanguageOptions(), defaults?.lang)
572
+ });
573
+ if (!lang) return fail();
574
+ const { provider } = await prompt({
575
+ type: "select",
576
+ name: "provider",
577
+ message: "Choose a browser provider. Vitest will use its API to control the testing environment",
578
+ choices: sort(getProviderOptions(), defaults?.provider)
579
+ });
580
+ if (!provider) return fail();
581
+ const { browsers } = await prompt({
582
+ type: "multiselect",
583
+ name: "browsers",
584
+ message: "Choose a browser",
585
+ choices: getBrowserNames(provider).map((browser) => ({
586
+ title: browser,
587
+ value: browser
588
+ }))
589
+ });
590
+ if (!provider) return fail();
591
+ const { framework } = await prompt({
592
+ type: "select",
593
+ name: "framework",
594
+ message: "Choose your framework",
595
+ choices: sort(getFramework(), defaults?.framework)
596
+ });
597
+ if (!framework) return fail();
598
+ let installPlaywright = false;
599
+ if (provider === "playwright") ({installPlaywright} = await prompt({
600
+ type: "confirm",
601
+ name: "installPlaywright",
602
+ message: `Install Playwright browsers (can be done manually via 'pnpm exec playwright install')?`
603
+ }));
604
+ if (installPlaywright == null) return fail();
605
+ const dependenciesToInstall = [`@vitest/browser-${provider}`];
606
+ const frameworkPackage = getFrameworkTestPackage(framework);
607
+ if (frameworkPackage) dependenciesToInstall.push(frameworkPackage);
608
+ const frameworkPlugin = getFrameworkPluginPackage(framework);
609
+ if (frameworkPlugin) dependenciesToInstall.push(frameworkPlugin);
610
+ const pkgManager = await detectPackageManager();
611
+ log();
612
+ await installPackages(pkgManager, dependenciesToInstall.filter((pkg) => !dependencies[pkg]));
613
+ const rootConfig = any(configFiles, { cwd: process.cwd() });
614
+ let scriptCommand = "vitest";
615
+ log();
616
+ if (rootConfig) {
617
+ const configPath = resolve(dirname(rootConfig), `vitest.browser.config.${lang}`);
618
+ scriptCommand = `vitest --config=${relative(process.cwd(), configPath)}`;
619
+ await generateFrameworkConfigFile({
620
+ configPath,
621
+ framework,
622
+ frameworkPlugin,
623
+ provider,
624
+ browsers
625
+ });
626
+ log(
627
+ c.green("✔"),
628
+ "Created a new config file for browser tests:",
629
+ c.bold(relative(process.cwd(), configPath)),
630
+ // TODO: Can we modify the config ourselves?
631
+ "\nSince you already have a Vitest config file, it is recommended to copy the contents of the new file ",
632
+ "into your existing config located at ",
633
+ c.bold(relative(process.cwd(), rootConfig))
634
+ );
635
+ } else {
636
+ const configPath = resolve(process.cwd(), `vitest.config.${lang}`);
637
+ await generateFrameworkConfigFile({
638
+ configPath,
639
+ framework,
640
+ frameworkPlugin,
641
+ provider,
642
+ browsers
643
+ });
644
+ log(c.green("✔"), "Created a config file for browser tests:", c.bold(relative(process.cwd(), configPath)));
645
+ }
646
+ log();
647
+ await updatePkgJsonScripts(pkgJsonPath, scriptCommand);
648
+ if (installPlaywright) {
649
+ log();
650
+ const [command, ...args] = getPlaywrightRunArgs(pkgManager);
651
+ const allArgs = [
652
+ ...args,
653
+ "playwright",
654
+ "install",
655
+ "--with-deps"
656
+ ];
657
+ log(c.cyan("◼"), `Installing Playwright dependencies with \`${c.bold(command)} ${c.bold(allArgs.join(" "))}\`...`);
658
+ log();
659
+ await x(command, allArgs, { nodeOptions: { stdio: [
660
+ "pipe",
661
+ "inherit",
662
+ "inherit"
663
+ ] } });
664
+ }
665
+ log();
666
+ const exampleTestFile = await generateExampleFiles(framework, lang);
667
+ log(c.green("✔"), "Created example test file in", c.bold(relative(process.cwd(), exampleTestFile)));
668
+ log(c.dim(" You can safely delete this file once you have written your own tests."));
669
+ log();
670
+ log(c.cyan("◼"), "All done! Run your tests with", c.bold(getRunScript(pkgManager)));
671
+ }
672
+
673
+ export { create };