@vitest-agent/mcp 1.0.1 → 1.2.0

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 (229) hide show
  1. package/README.md +1 -2
  2. package/bin/vitest-agent-mcp.js +1 -17
  3. package/index.d.ts +324 -315
  4. package/index.js +2 -4
  5. package/middleware/idempotency.js +1 -1
  6. package/package.json +2 -2
  7. package/server.js +2 -4
  8. package/tools/acceptance-metrics.js +1 -1
  9. package/tools/cache-health.js +1 -1
  10. package/tools/commit-changes.js +1 -1
  11. package/tools/configure.js +1 -1
  12. package/tools/coverage.js +1 -1
  13. package/tools/errors.js +1 -1
  14. package/tools/failure-signature-get.js +1 -1
  15. package/tools/file-coverage.js +1 -1
  16. package/tools/history.js +1 -1
  17. package/tools/inventory.js +1 -1
  18. package/tools/overview.js +1 -1
  19. package/tools/run-tests.js +15 -3
  20. package/tools/settings-list.js +1 -1
  21. package/tools/status.js +1 -1
  22. package/tools/tdd-artifact.js +1 -1
  23. package/tools/tdd-task.js +1 -1
  24. package/tools/test.js +1 -1
  25. package/tools/trends.js +1 -1
  26. package/tools/turn-search.js +1 -1
  27. package/public/patterns/_meta.json +0 -67
  28. package/public/patterns/authoring-a-custom-vitest-agent-reporter.md +0 -82
  29. package/public/patterns/known-issues-and-caveats.md +0 -52
  30. package/public/patterns/operating-vitest-agent-as-an-agent.md +0 -53
  31. package/public/patterns/running-tests-via-mcp.md +0 -58
  32. package/public/patterns/silencing-leaking-output-in-tests.md +0 -91
  33. package/public/patterns/testing-effect-schema-definitions.md +0 -71
  34. package/public/patterns/testing-effect-services-with-mock-layers.md +0 -63
  35. package/public/vendor/vitest-docs/ATTRIBUTION.md +0 -5
  36. package/public/vendor/vitest-docs/api/advanced/artifacts.md +0 -189
  37. package/public/vendor/vitest-docs/api/advanced/metadata.md +0 -68
  38. package/public/vendor/vitest-docs/api/advanced/plugin.md +0 -168
  39. package/public/vendor/vitest-docs/api/advanced/reporters.md +0 -342
  40. package/public/vendor/vitest-docs/api/advanced/runner.md +0 -334
  41. package/public/vendor/vitest-docs/api/advanced/test-case.md +0 -302
  42. package/public/vendor/vitest-docs/api/advanced/test-collection.md +0 -89
  43. package/public/vendor/vitest-docs/api/advanced/test-module.md +0 -140
  44. package/public/vendor/vitest-docs/api/advanced/test-project.md +0 -321
  45. package/public/vendor/vitest-docs/api/advanced/test-specification.md +0 -96
  46. package/public/vendor/vitest-docs/api/advanced/test-suite.md +0 -230
  47. package/public/vendor/vitest-docs/api/advanced/vitest.md +0 -684
  48. package/public/vendor/vitest-docs/api/assert-type.md +0 -22
  49. package/public/vendor/vitest-docs/api/assert.md +0 -1960
  50. package/public/vendor/vitest-docs/api/browser/assertions.md +0 -1277
  51. package/public/vendor/vitest-docs/api/browser/commands.md +0 -154
  52. package/public/vendor/vitest-docs/api/browser/context.md +0 -338
  53. package/public/vendor/vitest-docs/api/browser/interactivity.md +0 -681
  54. package/public/vendor/vitest-docs/api/browser/locators.md +0 -1171
  55. package/public/vendor/vitest-docs/api/browser/react.md +0 -346
  56. package/public/vendor/vitest-docs/api/browser/svelte.md +0 -292
  57. package/public/vendor/vitest-docs/api/browser/vue.md +0 -222
  58. package/public/vendor/vitest-docs/api/describe.md +0 -374
  59. package/public/vendor/vitest-docs/api/expect-typeof.md +0 -571
  60. package/public/vendor/vitest-docs/api/expect.md +0 -2304
  61. package/public/vendor/vitest-docs/api/hooks.md +0 -463
  62. package/public/vendor/vitest-docs/api/mock.md +0 -701
  63. package/public/vendor/vitest-docs/api/test.md +0 -926
  64. package/public/vendor/vitest-docs/api/vi.md +0 -1372
  65. package/public/vendor/vitest-docs/config/alias.md +0 -13
  66. package/public/vendor/vitest-docs/config/allowonly.md +0 -32
  67. package/public/vendor/vitest-docs/config/api.md +0 -27
  68. package/public/vendor/vitest-docs/config/attachmentsdir.md +0 -6
  69. package/public/vendor/vitest-docs/config/bail.md +0 -9
  70. package/public/vendor/vitest-docs/config/benchmark.md +0 -65
  71. package/public/vendor/vitest-docs/config/browser/api.md +0 -23
  72. package/public/vendor/vitest-docs/config/browser/commands.md +0 -6
  73. package/public/vendor/vitest-docs/config/browser/connecttimeout.md +0 -10
  74. package/public/vendor/vitest-docs/config/browser/detailspanelposition.md +0 -38
  75. package/public/vendor/vitest-docs/config/browser/enabled.md +0 -40
  76. package/public/vendor/vitest-docs/config/browser/expect.md +0 -250
  77. package/public/vendor/vitest-docs/config/browser/headless.md +0 -7
  78. package/public/vendor/vitest-docs/config/browser/instances.md +0 -47
  79. package/public/vendor/vitest-docs/config/browser/isolate.md +0 -11
  80. package/public/vendor/vitest-docs/config/browser/locators.md +0 -24
  81. package/public/vendor/vitest-docs/config/browser/orchestratorscripts.md +0 -39
  82. package/public/vendor/vitest-docs/config/browser/playwright.md +0 -214
  83. package/public/vendor/vitest-docs/config/browser/preview.md +0 -32
  84. package/public/vendor/vitest-docs/config/browser/provider.md +0 -79
  85. package/public/vendor/vitest-docs/config/browser/screenshotdirectory.md +0 -6
  86. package/public/vendor/vitest-docs/config/browser/screenshotfailures.md +0 -6
  87. package/public/vendor/vitest-docs/config/browser/testerhtmlpath.md +0 -5
  88. package/public/vendor/vitest-docs/config/browser/trace.md +0 -43
  89. package/public/vendor/vitest-docs/config/browser/trackunhandlederrors.md +0 -10
  90. package/public/vendor/vitest-docs/config/browser/ui.md +0 -7
  91. package/public/vendor/vitest-docs/config/browser/viewport.md +0 -6
  92. package/public/vendor/vitest-docs/config/browser/webdriverio.md +0 -64
  93. package/public/vendor/vitest-docs/config/cache.md +0 -26
  94. package/public/vendor/vitest-docs/config/chaiconfig.md +0 -29
  95. package/public/vendor/vitest-docs/config/clearmocks.md +0 -22
  96. package/public/vendor/vitest-docs/config/coverage.md +0 -455
  97. package/public/vendor/vitest-docs/config/css.md +0 -47
  98. package/public/vendor/vitest-docs/config/dangerouslyignoreunhandlederrors.md +0 -23
  99. package/public/vendor/vitest-docs/config/deps.md +0 -127
  100. package/public/vendor/vitest-docs/config/detectasyncleaks.md +0 -39
  101. package/public/vendor/vitest-docs/config/diff.md +0 -96
  102. package/public/vendor/vitest-docs/config/dir.md +0 -7
  103. package/public/vendor/vitest-docs/config/disableconsoleintercept.md +0 -15
  104. package/public/vendor/vitest-docs/config/env.md +0 -5
  105. package/public/vendor/vitest-docs/config/environment.md +0 -96
  106. package/public/vendor/vitest-docs/config/environmentoptions.md +0 -30
  107. package/public/vendor/vitest-docs/config/exclude.md +0 -49
  108. package/public/vendor/vitest-docs/config/execargv.md +0 -10
  109. package/public/vendor/vitest-docs/config/expandsnapshotdiff.md +0 -7
  110. package/public/vendor/vitest-docs/config/expect.md +0 -38
  111. package/public/vendor/vitest-docs/config/experimental.md +0 -510
  112. package/public/vendor/vitest-docs/config/faketimers.md +0 -51
  113. package/public/vendor/vitest-docs/config/fileparallelism.md +0 -11
  114. package/public/vendor/vitest-docs/config/forcereruntriggers.md +0 -19
  115. package/public/vendor/vitest-docs/config/globals.md +0 -42
  116. package/public/vendor/vitest-docs/config/globalsetup.md +0 -72
  117. package/public/vendor/vitest-docs/config/hideskippedtests.md +0 -7
  118. package/public/vendor/vitest-docs/config/hooktimeout.md +0 -7
  119. package/public/vendor/vitest-docs/config/include-source.md +0 -115
  120. package/public/vendor/vitest-docs/config/include.md +0 -71
  121. package/public/vendor/vitest-docs/config/includetasklocation.md +0 -17
  122. package/public/vendor/vitest-docs/config/index.md +0 -85
  123. package/public/vendor/vitest-docs/config/isolate.md +0 -13
  124. package/public/vendor/vitest-docs/config/logheapusage.md +0 -7
  125. package/public/vendor/vitest-docs/config/maxconcurrency.md +0 -9
  126. package/public/vendor/vitest-docs/config/maxworkers.md +0 -49
  127. package/public/vendor/vitest-docs/config/mockreset.md +0 -22
  128. package/public/vendor/vitest-docs/config/mode.md +0 -7
  129. package/public/vendor/vitest-docs/config/name.md +0 -111
  130. package/public/vendor/vitest-docs/config/onconsolelog.md +0 -25
  131. package/public/vendor/vitest-docs/config/onstacktrace.md +0 -32
  132. package/public/vendor/vitest-docs/config/onunhandlederror.md +0 -35
  133. package/public/vendor/vitest-docs/config/open.md +0 -7
  134. package/public/vendor/vitest-docs/config/outputfile.md +0 -7
  135. package/public/vendor/vitest-docs/config/passwithnotests.md +0 -7
  136. package/public/vendor/vitest-docs/config/pool.md +0 -45
  137. package/public/vendor/vitest-docs/config/printconsoletrace.md +0 -6
  138. package/public/vendor/vitest-docs/config/projects.md +0 -6
  139. package/public/vendor/vitest-docs/config/provide.md +0 -45
  140. package/public/vendor/vitest-docs/config/reporters.md +0 -69
  141. package/public/vendor/vitest-docs/config/resolvesnapshotpath.md +0 -36
  142. package/public/vendor/vitest-docs/config/restoremocks.md +0 -22
  143. package/public/vendor/vitest-docs/config/retry.md +0 -140
  144. package/public/vendor/vitest-docs/config/root.md +0 -6
  145. package/public/vendor/vitest-docs/config/runner.md +0 -6
  146. package/public/vendor/vitest-docs/config/sequence.md +0 -158
  147. package/public/vendor/vitest-docs/config/server.md +0 -68
  148. package/public/vendor/vitest-docs/config/setupfiles.md +0 -40
  149. package/public/vendor/vitest-docs/config/silent.md +0 -9
  150. package/public/vendor/vitest-docs/config/slowtestthreshold.md +0 -7
  151. package/public/vendor/vitest-docs/config/snapshotenvironment.md +0 -27
  152. package/public/vendor/vitest-docs/config/snapshotformat.md +0 -28
  153. package/public/vendor/vitest-docs/config/snapshotserializers.md +0 -6
  154. package/public/vendor/vitest-docs/config/stricttags.md +0 -30
  155. package/public/vendor/vitest-docs/config/tags.md +0 -141
  156. package/public/vendor/vitest-docs/config/teardowntimeout.md +0 -7
  157. package/public/vendor/vitest-docs/config/testnamepattern.md +0 -21
  158. package/public/vendor/vitest-docs/config/testtimeout.md +0 -7
  159. package/public/vendor/vitest-docs/config/typecheck.md +0 -77
  160. package/public/vendor/vitest-docs/config/ui.md +0 -15
  161. package/public/vendor/vitest-docs/config/unstubenvs.md +0 -20
  162. package/public/vendor/vitest-docs/config/unstubglobals.md +0 -20
  163. package/public/vendor/vitest-docs/config/update.md +0 -16
  164. package/public/vendor/vitest-docs/config/vmmemorylimit.md +0 -30
  165. package/public/vendor/vitest-docs/config/watch.md +0 -11
  166. package/public/vendor/vitest-docs/config/watchtriggerpatterns.md +0 -29
  167. package/public/vendor/vitest-docs/guide/advanced/index.md +0 -147
  168. package/public/vendor/vitest-docs/guide/advanced/pool.md +0 -148
  169. package/public/vendor/vitest-docs/guide/advanced/reporters.md +0 -93
  170. package/public/vendor/vitest-docs/guide/advanced/tests.md +0 -125
  171. package/public/vendor/vitest-docs/guide/browser/aria-snapshots.md +0 -470
  172. package/public/vendor/vitest-docs/guide/browser/component-testing.md +0 -571
  173. package/public/vendor/vitest-docs/guide/browser/index.md +0 -630
  174. package/public/vendor/vitest-docs/guide/browser/multiple-setups.md +0 -121
  175. package/public/vendor/vitest-docs/guide/browser/trace-view.md +0 -126
  176. package/public/vendor/vitest-docs/guide/browser/visual-regression-testing.md +0 -734
  177. package/public/vendor/vitest-docs/guide/cli-generated.md +0 -972
  178. package/public/vendor/vitest-docs/guide/cli.md +0 -234
  179. package/public/vendor/vitest-docs/guide/common-errors.md +0 -163
  180. package/public/vendor/vitest-docs/guide/coverage.md +0 -515
  181. package/public/vendor/vitest-docs/guide/debugging.md +0 -127
  182. package/public/vendor/vitest-docs/guide/environment.md +0 -101
  183. package/public/vendor/vitest-docs/guide/extending-matchers.md +0 -160
  184. package/public/vendor/vitest-docs/guide/features.md +0 -310
  185. package/public/vendor/vitest-docs/guide/filtering.md +0 -175
  186. package/public/vendor/vitest-docs/guide/ide.md +0 -43
  187. package/public/vendor/vitest-docs/guide/improving-performance.md +0 -245
  188. package/public/vendor/vitest-docs/guide/in-source.md +0 -159
  189. package/public/vendor/vitest-docs/guide/index.md +0 -128
  190. package/public/vendor/vitest-docs/guide/learn/async.md +0 -147
  191. package/public/vendor/vitest-docs/guide/learn/debugging-tests.md +0 -210
  192. package/public/vendor/vitest-docs/guide/learn/matchers.md +0 -277
  193. package/public/vendor/vitest-docs/guide/learn/mock-functions.md +0 -277
  194. package/public/vendor/vitest-docs/guide/learn/setup-teardown.md +0 -240
  195. package/public/vendor/vitest-docs/guide/learn/snapshots.md +0 -166
  196. package/public/vendor/vitest-docs/guide/learn/testing-in-practice.md +0 -430
  197. package/public/vendor/vitest-docs/guide/learn/writing-tests-with-ai.md +0 -127
  198. package/public/vendor/vitest-docs/guide/learn/writing-tests.md +0 -231
  199. package/public/vendor/vitest-docs/guide/lifecycle.md +0 -379
  200. package/public/vendor/vitest-docs/guide/migration.md +0 -863
  201. package/public/vendor/vitest-docs/guide/mocking/classes.md +0 -158
  202. package/public/vendor/vitest-docs/guide/mocking/dates.md +0 -52
  203. package/public/vendor/vitest-docs/guide/mocking/file-system.md +0 -74
  204. package/public/vendor/vitest-docs/guide/mocking/functions.md +0 -61
  205. package/public/vendor/vitest-docs/guide/mocking/globals.md +0 -20
  206. package/public/vendor/vitest-docs/guide/mocking/modules.md +0 -414
  207. package/public/vendor/vitest-docs/guide/mocking/requests.md +0 -114
  208. package/public/vendor/vitest-docs/guide/mocking/timers.md +0 -48
  209. package/public/vendor/vitest-docs/guide/mocking.md +0 -239
  210. package/public/vendor/vitest-docs/guide/open-telemetry.md +0 -156
  211. package/public/vendor/vitest-docs/guide/parallelism.md +0 -82
  212. package/public/vendor/vitest-docs/guide/profiling-test-performance.md +0 -243
  213. package/public/vendor/vitest-docs/guide/projects.md +0 -291
  214. package/public/vendor/vitest-docs/guide/recipes.md +0 -59
  215. package/public/vendor/vitest-docs/guide/reporters.md +0 -723
  216. package/public/vendor/vitest-docs/guide/snapshot.md +0 -620
  217. package/public/vendor/vitest-docs/guide/test-annotations.md +0 -103
  218. package/public/vendor/vitest-docs/guide/test-context.md +0 -902
  219. package/public/vendor/vitest-docs/guide/test-tags.md +0 -314
  220. package/public/vendor/vitest-docs/guide/testing-types.md +0 -149
  221. package/public/vendor/vitest-docs/guide/ui.md +0 -160
  222. package/public/vendor/vitest-docs/guide/using-plugins.md +0 -5
  223. package/public/vendor/vitest-docs/manifest.json +0 -1691
  224. package/resources/index.js +0 -166
  225. package/resources/indexes.js +0 -77
  226. package/resources/manifest-schema.js +0 -46
  227. package/resources/paths.js +0 -20
  228. package/resources/patterns.js +0 -22
  229. package/resources/upstream-docs.js +0 -22
@@ -1,243 +0,0 @@
1
- # Profiling Test Performance
2
-
3
- When you run Vitest it reports multiple time metrics of your tests:
4
-
5
- > ```bash
6
- > RUN v2.1.1 /x/vitest/examples/profiling
7
- >
8
- > ✓ test/prime-number.test.ts (1) 4517ms
9
- > ✓ generate prime number 4517ms
10
- >
11
- > Test Files 1 passed (1)
12
- > Tests 1 passed (1)
13
- > Start at 09:32:53
14
- > Duration 4.80s (transform 44ms, setup 0ms, import 35ms, tests 4.52s, environment 0ms)
15
- > # Time metrics ^^
16
- > ```
17
-
18
- - Transform: How much time was spent transforming the files. See [File Transform](#file-transform).
19
- - Setup: Time spent for running the [`setupFiles`](/config/setupfiles) files.
20
- - Import: Time it took to import your test files and their dependencies. This also includes the time spent collecting all tests. Note that this doesn't include dynamic imports inside of tests.
21
- - Tests: Time spent for actually running the test cases.
22
- - Environment: Time spent for setting up the test [`environment`](/config/environment), for example JSDOM.
23
-
24
- ## Test Runner
25
-
26
- In cases where your test execution time is high, you can generate a profile of the test runner. See NodeJS documentation for following options:
27
-
28
- - [`--cpu-prof`](https://nodejs.org/api/cli.html#--cpu-prof)
29
- - [`--heap-prof`](https://nodejs.org/api/cli.html#--heap-prof)
30
- - [`--prof`](https://nodejs.org/api/cli.html#--prof)
31
-
32
- :::warning
33
- The `--prof` option does not work with `pool: 'threads'` due to `node:worker_threads` limitations.
34
- :::
35
-
36
- To pass these options to Vitest's test runner, define `execArgv` in your Vitest configuration:
37
-
38
- ```ts
39
- import { defineConfig } from 'vitest/config'
40
-
41
- export default defineConfig({
42
- test: {
43
- fileParallelism: false,
44
- execArgv: [
45
- '--cpu-prof',
46
- '--cpu-prof-dir=test-runner-profile',
47
- '--heap-prof',
48
- '--heap-prof-dir=test-runner-profile'
49
- ],
50
- },
51
- })
52
- ```
53
-
54
- After the tests have run there should be a `test-runner-profile/*.cpuprofile` and `test-runner-profile/*.heapprofile` files generated. See [Inspecting profiling records](#inspecting-profiling-records) for instructions how to analyze these files.
55
-
56
- See [Profiling | Examples](https://github.com/vitest-dev/vitest/tree/main/examples/profiling) for example.
57
-
58
- ## Main Thread
59
-
60
- Profiling main thread is useful for debugging Vitest's Vite usage and [`globalSetup`](/config/globalsetup) files.
61
- This is also where your Vite plugins are running.
62
-
63
- :::tip
64
- See [Performance | Vite](https://vitejs.dev/guide/performance.html) for more tips about Vite specific profiling.
65
-
66
- We recommend [`vite-plugin-inspect`](https://github.com/antfu-collective/vite-plugin-inspect) for profiling your Vite plugin performance.
67
- :::
68
-
69
- To do this you'll need to pass arguments to the Node process that runs Vitest.
70
-
71
- ```bash
72
- $ node --cpu-prof --cpu-prof-dir=main-profile ./node_modules/vitest/vitest.mjs --run
73
- # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^
74
- # NodeJS arguments Vitest arguments
75
- ```
76
-
77
- After the tests have run there should be a `main-profile/*.cpuprofile` file generated. See [Inspecting profiling records](#inspecting-profiling-records) for instructions how to analyze these files.
78
-
79
- ## File Transform
80
-
81
- This profiling strategy is a good way to identify unnecessary transforms caused by [barrel files](https://vitejs.dev/guide/performance.html#avoid-barrel-files).
82
- If these logs contain files that should not be loaded when your test is run, you might have barrel files that are importing files unnecessarily.
83
-
84
- You can also use [Vitest UI](/guide/ui) to debug slowness caused by barrel file.
85
- The example below shows how importing files without barrel file reduces amount of transformed files by ~85%.
86
-
87
- ::: code-group
88
- ``` [File tree]
89
- ├── src
90
- │ └── utils
91
- │ ├── currency.ts
92
- │ ├── formatters.ts <-- File to test
93
- │ ├── index.ts
94
- │ ├── location.ts
95
- │ ├── math.ts
96
- │ ├── time.ts
97
- │ └── users.ts
98
- ├── test
99
- │ └── formatters.test.ts
100
- └── vitest.config.ts
101
- ```
102
- ```ts [example.test.ts]
103
- import { expect, test } from 'vitest'
104
- import { formatter } from '../src/utils' // [!code --]
105
- import { formatter } from '../src/utils/formatters' // [!code ++]
106
-
107
- test('formatter works', () => {
108
- expect(formatter).not.toThrow()
109
- })
110
- ```
111
- :::
112
-
113
- <img src="/module-graph-barrel-file.png" alt="Vitest UI demonstrating barrel file issues" />
114
-
115
- To see how files are transformed, you can open the "Module Info" view in the UI:
116
-
117
- <img alt="The module info view for an inlined module" img-light src="/ui/light-module-info.png">
118
- <img alt="The module info view for an inlined module" img-dark src="/ui/dark-module-info.png">
119
-
120
- ## File Import
121
-
122
- Some modules just take a long time to load. To identify which modules are the slowest, enable [`experimental.importDurations`](/config/experimental#experimental-importdurations) in your configuration:
123
-
124
- ```ts [vitest.config.ts]
125
- import { defineConfig } from 'vitest/config'
126
-
127
- export default defineConfig({
128
- test: {
129
- experimental: {
130
- importDurations: {
131
- print: true,
132
- },
133
- },
134
- },
135
- })
136
- ```
137
-
138
- This will print a breakdown of the slowest imports after your tests finish:
139
-
140
- ```bash
141
- Import Duration Breakdown (Top 10)
142
-
143
- Module Self Total
144
- my-test.test.ts 5ms 620ms [████████████████████]
145
- date-fns/index.js 500ms 500ms [████████████████░░░░] # [!code error]
146
- src/utils/helpers.ts 10ms 120ms [████████░░░░░░░░░░░░]
147
- ```
148
-
149
- You can also use `--experimental.importDurations.print` from the CLI without changing your configuration:
150
-
151
- ```bash
152
- vitest --experimental.importDurations.print
153
- ```
154
-
155
- Once you've identified the slow modules, there are several strategies to speed up imports:
156
-
157
- ### Use Specific Entry Points
158
-
159
- Many libraries ship multiple entry points. Importing the main entry point (which is often a [barrel file](https://vitejs.dev/guide/performance.html#avoid-barrel-files)) can pull in far more code than you need.
160
-
161
- For example, `date-fns` re-exports hundreds of functions from its main entry point. Instead of importing from the top-level module, import directly from the specific function:
162
-
163
- ```ts
164
- import { format } from 'date-fns' // [!code --]
165
- import { format } from 'date-fns/format' // [!code ++]
166
- ```
167
-
168
- ### Use `resolve.alias` to Redirect Imports
169
-
170
- If a dependency doesn't provide granular entry points, or if third-party code imports the heavy entry point, you can use [`resolve.alias`](https://vite.dev/config/shared-options#resolve-alias) to redirect imports to a lighter alternative:
171
-
172
- ```ts [vitest.config.ts]
173
- import { defineConfig } from 'vitest/config'
174
-
175
- export default defineConfig({
176
- resolve: {
177
- alias: [
178
- {
179
- find: /^date-fns$/,
180
- replacement: join(dirname(require.resolve('date-fns/package.json')), 'index.cjs'),
181
- },
182
- ]
183
- },
184
- })
185
- ```
186
-
187
- ### Use the Dependency Optimizer
188
-
189
- Vitest can bundle external libraries into a single file using [`deps.optimizer`](/config/deps#deps-optimizer), which reduces the overhead of importing packages with many internal modules:
190
-
191
- ```ts [vitest.config.ts]
192
- import { defineConfig } from 'vitest/config'
193
-
194
- export default defineConfig({
195
- test: {
196
- deps: {
197
- optimizer: {
198
- ssr: {
199
- enabled: true,
200
- include: ['date-fns'],
201
- },
202
- },
203
- },
204
- },
205
- })
206
- ```
207
-
208
- This is especially effective for UI libraries and packages with deep import trees. Use `optimizer.ssr` for `node`/`edge` environments and `optimizer.client` for `jsdom`/`happy-dom` environments.
209
-
210
- ## Code Coverage
211
-
212
- If code coverage generation is slow on your project you can use `DEBUG=vitest:coverage` environment variable to enable performance logging.
213
-
214
- ```bash
215
- $ DEBUG=vitest:coverage vitest --run --coverage
216
-
217
- RUN v3.1.1 /x/vitest-example
218
-
219
- vitest:coverage Reading coverage results 2/2
220
- vitest:coverage Converting 1/2
221
- vitest:coverage 4 ms /x/src/multiply.ts
222
- vitest:coverage Converting 2/2
223
- vitest:coverage 552 ms /x/src/add.ts
224
- vitest:coverage Uncovered files 1/2
225
- vitest:coverage File "/x/src/large-file.ts" is taking longer than 3s # [!code error]
226
- vitest:coverage 3027 ms /x/src/large-file.ts
227
- vitest:coverage Uncovered files 2/2
228
- vitest:coverage 4 ms /x/src/untested-file.ts
229
- vitest:coverage Generate coverage total time 3521 ms
230
- ```
231
-
232
- This profiling approach is great for detecting large files that are accidentally picked by coverage providers.
233
- For example if your configuration is accidentally including large built minified Javascript files in code coverage, they should appear in logs.
234
- In these cases you might want to adjust your [`coverage.include`](/config/coverage#coverage-include) and [`coverage.exclude`](/config/coverage#coverage-exclude) options.
235
-
236
- ## Inspecting Profiling Records
237
-
238
- You can inspect the contents of `*.cpuprofile` and `*.heapprofile` with various tools. See list below for examples.
239
-
240
- - [Speedscope](https://www.speedscope.app/)
241
- - [Performance Profiling JavaScript in Visual Studio Code](https://code.visualstudio.com/docs/nodejs/profiling#_analyzing-a-profile)
242
- - [Profile Node.js performance with the Performance panel | developer.chrome.com](https://developer.chrome.com/docs/devtools/performance/nodejs#analyze)
243
- - [Memory panel overview | developer.chrome.com](https://developer.chrome.com/docs/devtools/memory-problems/heap-snapshots#view_snapshots)
@@ -1,291 +0,0 @@
1
- # Test Projects
2
-
3
- ::: tip Sample Project
4
-
5
- [GitHub](https://github.com/vitest-dev/vitest/tree/main/examples/projects) - [Play Online](https://stackblitz.com/fork/github/vitest-dev/vitest/tree/main/examples/projects?initialPath=__vitest__/)
6
-
7
- :::
8
-
9
- ::: warning
10
- This feature is also known as a `workspace`. The `workspace` is deprecated since 3.2 and replaced with the `projects` configuration. They are functionally the same.
11
- :::
12
-
13
- Vitest provides a way to define multiple project configurations within a single Vitest process. This feature is particularly useful for monorepo setups but can also be used to run tests with different configurations, such as `resolve.alias`, `plugins`, or `test.browser` and more.
14
-
15
- ## Defining Projects
16
-
17
- You can define projects in your root [config](/config/):
18
-
19
- ```ts [vitest.config.ts]
20
- import { defineConfig } from 'vitest/config'
21
-
22
- export default defineConfig({
23
- test: {
24
- projects: ['packages/*'],
25
- },
26
- })
27
- ```
28
-
29
- Project configurations are inlined configs, files, or glob patterns referencing your projects. For example, if you have a folder named `packages` that contains your projects, you can define an array in your root Vitest config:
30
-
31
- ```ts [vitest.config.ts]
32
- import { defineConfig } from 'vitest/config'
33
-
34
- export default defineConfig({
35
- test: {
36
- projects: ['packages/*'],
37
- },
38
- })
39
- ```
40
-
41
- Vitest will treat every folder in `packages` as a separate project even if it doesn't have a config file inside. If a project entry resolves to a file (either from a glob pattern or a direct file path), Vitest will validate that the name either:
42
-
43
- - starts with `vitest.config` or `vite.config` (for example, `vitest.config.unit.ts`)
44
- - or matches `vitest.<name>.config.*` / `vite.<name>.config.*`, where `<name>` can contain letters, numbers, `_`, and `-`
45
-
46
- For example, these config files are valid:
47
-
48
- - `vitest.config.ts`
49
- - `vite.config.js`
50
- - `vitest.unit.config.ts`
51
- - `vitest.e2e-node.config.ts`
52
- - `vite.e2e.config.js`
53
- - `vitest.config.unit.js`
54
- - `vite.config.e2e.js`
55
-
56
- To exclude folders and files, you can use the negation pattern:
57
-
58
- ```ts [vitest.config.ts]
59
- import { defineConfig } from 'vitest/config'
60
-
61
- export default defineConfig({
62
- test: {
63
- // include all folders inside "packages" except "excluded"
64
- projects: [
65
- 'packages/*',
66
- '!packages/excluded'
67
- ],
68
- },
69
- })
70
- ```
71
-
72
- If you have a nested structure where some folders need to be projects, but other folders have their own subfolders, you have to use brackets to avoid matching the parent folder:
73
-
74
- ```ts [vitest.config.ts]
75
- import { defineConfig } from 'vitest/config'
76
-
77
- // For example, this will create projects:
78
- // packages/a
79
- // packages/b
80
- // packages/business/c
81
- // packages/business/d
82
- // Notice that "packages/business" is not a project itself
83
-
84
- export default defineConfig({
85
- test: {
86
- projects: [
87
- // matches every folder inside "packages" except "business"
88
- 'packages/!(business)',
89
- // matches every folder inside "packages/business"
90
- 'packages/business/*',
91
- ],
92
- },
93
- })
94
- ```
95
-
96
- ::: warning
97
- Vitest does not treat the root `vitest.config` file as a project unless it is explicitly specified in the configuration. Consequently, the root configuration will only influence global options such as `reporters` and `coverage`. Note that Vitest will always run certain plugin hooks, like `apply`, `config`, `configResolved` or `configureServer`, specified in the root config file. Vitest also uses the same plugins to execute global setups and custom coverage provider.
98
- :::
99
-
100
- You can also reference projects with their config files:
101
-
102
- ```ts [vitest.config.ts]
103
- import { defineConfig } from 'vitest/config'
104
-
105
- export default defineConfig({
106
- test: {
107
- projects: ['packages/*/vitest.config.{e2e,unit}.ts'],
108
- },
109
- })
110
- ```
111
-
112
- This pattern will only include projects with a `vitest.config` file that contains `e2e` or `unit` before the extension.
113
-
114
- You can also define projects using inline configuration. The configuration supports both syntaxes simultaneously.
115
-
116
- ```ts [vitest.config.ts]
117
- import { defineConfig } from 'vitest/config'
118
-
119
- export default defineConfig({
120
- test: {
121
- projects: [
122
- // matches every folder and file inside the `packages` folder
123
- 'packages/*',
124
- {
125
- // add "extends: true" to inherit the options from the root config
126
- extends: true,
127
- test: {
128
- include: ['tests/**/*.{browser}.test.{ts,js}'],
129
- // it is recommended to define a name when using inline configs
130
- name: 'happy-dom',
131
- environment: 'happy-dom',
132
- }
133
- },
134
- {
135
- test: {
136
- include: ['tests/**/*.{node}.test.{ts,js}'],
137
- // color of the name label can be changed
138
- name: { label: 'node', color: 'green' },
139
- environment: 'node',
140
- }
141
- }
142
- ]
143
- }
144
- })
145
- ```
146
-
147
- ::: warning
148
- All projects must have unique names; otherwise, Vitest will throw an error. If a name is not provided in the inline configuration, Vitest will assign a number. For project configurations defined with glob syntax, Vitest will default to using the "name" property in the nearest `package.json` file or, if none exists, the folder name.
149
- :::
150
-
151
- Projects do not support all configuration properties. For better type safety, use the `defineProject` method instead of `defineConfig` within project configuration files:
152
-
153
- ```ts twoslash [packages/a/vitest.config.ts]
154
- // @errors: 2769
155
- import { defineProject } from 'vitest/config'
156
-
157
- export default defineProject({
158
- test: {
159
- environment: 'jsdom',
160
- // "reporters" is not supported in a project config,
161
- // so it will show an error
162
- reporters: ['json']
163
- }
164
- })
165
- ```
166
-
167
- ## Running Tests
168
-
169
- To run tests, define a script in your root `package.json`:
170
-
171
- ```json [package.json]
172
- {
173
- "scripts": {
174
- "test": "vitest"
175
- }
176
- }
177
- ```
178
-
179
- Now tests can be run using your package manager:
180
-
181
- ::: code-group
182
- ```bash [npm]
183
- npm run test
184
- ```
185
- ```bash [yarn]
186
- yarn test
187
- ```
188
- ```bash [pnpm]
189
- pnpm run test
190
- ```
191
- ```bash [bun]
192
- bun run test
193
- ```
194
- :::
195
-
196
- If you need to run tests only inside a single project, use the `--project` CLI option:
197
-
198
- ::: code-group
199
- ```bash [npm]
200
- npm run test --project e2e
201
- ```
202
- ```bash [yarn]
203
- yarn test --project e2e
204
- ```
205
- ```bash [pnpm]
206
- pnpm run test --project e2e
207
- ```
208
- ```bash [bun]
209
- bun run test --project e2e
210
- ```
211
- :::
212
-
213
- ::: tip
214
- CLI option `--project` can be used multiple times to filter out several projects:
215
-
216
- ::: code-group
217
- ```bash [npm]
218
- npm run test --project e2e --project unit
219
- ```
220
- ```bash [yarn]
221
- yarn test --project e2e --project unit
222
- ```
223
- ```bash [pnpm]
224
- pnpm run test --project e2e --project unit
225
- ```
226
- ```bash [bun]
227
- bun run test --project e2e --project unit
228
- ```
229
- :::
230
-
231
- ## Configuration
232
-
233
- None of the configuration options are inherited from the root-level config file. You can create a shared config file and merge it with the project config yourself:
234
-
235
- ```ts [packages/a/vitest.config.ts]
236
- import { defineProject, mergeConfig } from 'vitest/config'
237
- import configShared from '../vitest.shared.js'
238
-
239
- export default mergeConfig(
240
- configShared,
241
- defineProject({
242
- test: {
243
- environment: 'jsdom',
244
- }
245
- })
246
- )
247
- ```
248
-
249
- Additionally, you can use the `extends` option to inherit from your root-level configuration. All options will be merged.
250
-
251
- ```ts [vitest.config.ts]
252
- import { defineConfig } from 'vitest/config'
253
- import react from '@vitejs/plugin-react'
254
-
255
- export default defineConfig({
256
- plugins: [react()],
257
- test: {
258
- pool: 'threads',
259
- projects: [
260
- {
261
- // will inherit options from this config like plugins and pool
262
- extends: true,
263
- test: {
264
- name: 'unit',
265
- include: ['**/*.unit.test.ts'],
266
- },
267
- },
268
- {
269
- // won't inherit any options from this config
270
- // this is the default behaviour
271
- extends: false,
272
- test: {
273
- name: 'integration',
274
- include: ['**/*.integration.test.ts'],
275
- },
276
- },
277
- ],
278
- },
279
- })
280
- ```
281
-
282
- ::: danger Unsupported Options
283
- Some of the configuration options are not allowed in a project config. Most notably:
284
-
285
- - `coverage`: coverage is done for the whole process
286
- - `reporters`: only root-level reporters can be supported
287
- - `resolveSnapshotPath`: only root-level resolver is respected
288
- - all other options that don't affect test runners
289
-
290
- All configuration options that are not supported inside a project configuration are marked with a <CRoot /> icon next to their name. They can only be defined once in the root config file.
291
- :::
@@ -1,59 +0,0 @@
1
- # Recipes
2
-
3
- ## Disabling Isolation for Specific Test Files Only
4
-
5
- You can speed up your test run by disabling isolation for specific set of files by specifying `isolate` per `projects` entries:
6
-
7
- ```ts [vitest.config.ts]
8
- import { defineConfig } from 'vitest/config'
9
-
10
- export default defineConfig({
11
- test: {
12
- projects: [
13
- {
14
- test: {
15
- // Non-isolated unit tests
16
- name: 'Unit tests',
17
- isolate: false,
18
- exclude: ['**.integration.test.ts'],
19
- },
20
- },
21
- {
22
- test: {
23
- // Isolated integration tests
24
- name: 'Integration tests',
25
- include: ['**.integration.test.ts'],
26
- },
27
- },
28
- ],
29
- },
30
- })
31
- ```
32
-
33
- ## Parallel and Sequential Test Files
34
-
35
- You can split test files into parallel and sequential groups by using `projects` option:
36
-
37
- ```ts [vitest.config.ts]
38
- import { defineConfig } from 'vitest/config'
39
-
40
- export default defineConfig({
41
- test: {
42
- projects: [
43
- {
44
- test: {
45
- name: 'Parallel',
46
- exclude: ['**.sequential.test.ts'],
47
- },
48
- },
49
- {
50
- test: {
51
- name: 'Sequential',
52
- include: ['**.sequential.test.ts'],
53
- fileParallelism: false,
54
- },
55
- },
56
- ],
57
- },
58
- })
59
- ```