@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,147 +0,0 @@
1
- # Getting Started <Badge type="danger">advanced</Badge> {#getting-started}
2
-
3
- ::: warning
4
- This guide lists advanced APIs to run tests via a Node.js script. If you just want to [run tests](/guide/), you probably don't need this. It is primarily used by library authors.
5
- :::
6
-
7
- You can import any method from the `vitest/node` entry-point.
8
-
9
- ## startVitest
10
-
11
- ```ts
12
- function startVitest(
13
- mode: VitestRunMode,
14
- cliFilters: string[] = [],
15
- options: CliOptions = {},
16
- viteOverrides?: ViteUserConfig,
17
- vitestOptions?: VitestOptions,
18
- ): Promise<Vitest>
19
- ```
20
-
21
- You can start running Vitest tests using its Node API:
22
-
23
- ```js
24
- import { startVitest } from 'vitest/node'
25
-
26
- const vitest = await startVitest('test')
27
-
28
- await vitest.close()
29
- ```
30
-
31
- `startVitest` function returns [`Vitest`](/api/advanced/vitest) instance if tests can be started.
32
-
33
- If watch mode is not enabled, Vitest will call `close` method automatically.
34
-
35
- If watch mode is enabled and the terminal supports TTY, Vitest will register console shortcuts.
36
-
37
- You can pass down a list of filters as a second argument. Vitest will run only tests that contain at least one of the passed-down strings in their file path.
38
-
39
- Additionally, you can use the third argument to pass in CLI arguments, which will override any test config options. Alternatively, you can pass in the complete Vite config as the fourth argument, which will take precedence over any other user-defined options.
40
-
41
- After running the tests, you can get the results from the [`state.getTestModules`](/api/advanced/test-module) API:
42
-
43
- ```ts
44
- import type { TestModule } from 'vitest/node'
45
-
46
- const vitest = await startVitest('test')
47
-
48
- console.log(vitest.state.getTestModules()) // [TestModule]
49
- ```
50
-
51
- ::: tip
52
- The ["Running Tests"](/guide/advanced/tests#startvitest) guide has a usage example.
53
- :::
54
-
55
- ## createVitest
56
-
57
- ```ts
58
- function createVitest(
59
- mode: VitestRunMode,
60
- options: CliOptions,
61
- viteOverrides: ViteUserConfig = {},
62
- vitestOptions: VitestOptions = {},
63
- ): Promise<Vitest>
64
- ```
65
-
66
- You can create Vitest instance by using `createVitest` function. It returns the same [`Vitest`](/api/advanced/vitest) instance as `startVitest`, but it doesn't start tests and doesn't validate installed packages.
67
-
68
- ```js
69
- import { createVitest } from 'vitest/node'
70
-
71
- const vitest = await createVitest('test', {
72
- watch: false,
73
- })
74
- ```
75
-
76
- ::: tip
77
- The ["Running Tests"](/guide/advanced/tests#createvitest) guide has a usage example.
78
- :::
79
-
80
- ## resolveConfig
81
-
82
- ```ts
83
- function resolveConfig(
84
- options: UserConfig = {},
85
- viteOverrides: ViteUserConfig = {},
86
- ): Promise<{
87
- vitestConfig: ResolvedConfig
88
- viteConfig: ResolvedViteConfig
89
- }>
90
- ```
91
-
92
- This method resolves the config with custom parameters. If no parameters are given, the `root` will be `process.cwd()`.
93
-
94
- ```ts
95
- import { resolveConfig } from 'vitest/node'
96
-
97
- // vitestConfig only has resolved "test" properties
98
- const { vitestConfig, viteConfig } = await resolveConfig({
99
- mode: 'custom',
100
- configFile: false,
101
- resolve: {
102
- conditions: ['custom']
103
- },
104
- test: {
105
- setupFiles: ['/my-setup-file.js'],
106
- pool: 'threads',
107
- },
108
- })
109
- ```
110
-
111
- ::: info
112
- Due to how Vite's `createServer` works, Vitest has to resolve the config during the plugin's `configResolve` hook. Therefore, this method is not actually used internally and is exposed exclusively as a public API.
113
-
114
- If you pass down the config to the `startVitest` or `createVitest` APIs, Vitest will still resolve the config again.
115
- :::
116
-
117
- ::: warning
118
- The `resolveConfig` doesn't resolve `projects`. To resolve projects configs, Vitest needs an established Vite server.
119
-
120
- Also note that `viteConfig.test` will not be fully resolved. If you need Vitest config, use `vitestConfig` instead.
121
- :::
122
-
123
- ## parseCLI
124
-
125
- ```ts
126
- function parseCLI(argv: string | string[], config: CliParseOptions = {}): {
127
- filter: string[]
128
- options: CliOptions
129
- }
130
- ```
131
-
132
- You can use this method to parse CLI arguments. It accepts a string (where arguments are split by a single space) or a strings array of CLI arguments in the same format that Vitest CLI uses. It returns a filter and `options` that you can later pass down to `createVitest` or `startVitest` methods.
133
-
134
- ```ts
135
- import { parseCLI } from 'vitest/node'
136
-
137
- const result = parseCLI('vitest ./files.ts --coverage --browser=chrome')
138
-
139
- result.options
140
- // {
141
- // coverage: { enabled: true },
142
- // browser: { name: 'chrome', enabled: true }
143
- // }
144
-
145
- result.filter
146
- // ['./files.ts']
147
- ```
@@ -1,148 +0,0 @@
1
- # Custom Pool <Badge type="danger">advanced</Badge> {#custom-pool}
2
-
3
- ::: warning
4
- This is an advanced, experimental and very low-level API. If you just want to [run tests](/guide/), you probably don't need this. It is primarily used by library authors.
5
- :::
6
-
7
- Vitest runs tests in a pool. By default, there are several pool runners:
8
-
9
- - `threads` to run tests using `node:worker_threads` (isolation is provided with a new worker context)
10
- - `forks` to run tests using `node:child_process` (isolation is provided with a new `child_process.fork` process)
11
- - `vmThreads` to run tests using `node:worker_threads` (but isolation is provided with `vm` module instead of a new worker context)
12
- - `browser` to run tests using browser providers
13
- - `typescript` to run typechecking on tests
14
-
15
- ::: tip
16
- See [`vitest-pool-example`](https://npmx.dev/package/vitest-pool-example) for example of a custom pool runner implementation.
17
- :::
18
-
19
- ## Usage
20
-
21
- You can provide your own pool runner by a function that returns `PoolRunnerInitializer`.
22
-
23
- ```ts [vitest.config.ts]
24
- import { defineConfig } from 'vitest/config'
25
- import customPool from './my-custom-pool.ts'
26
-
27
- export default defineConfig({
28
- test: {
29
- // will run every file with a custom pool by default
30
- pool: customPool({
31
- customProperty: true,
32
- })
33
- },
34
- })
35
- ```
36
-
37
- If you need to run tests in different pools, use the [`projects`](/guide/projects) feature:
38
-
39
- ```ts [vitest.config.ts]
40
- import customPool from './my-custom-pool.ts'
41
-
42
- export default defineConfig({
43
- test: {
44
- projects: [
45
- {
46
- extends: true,
47
- test: {
48
- pool: 'threads',
49
- },
50
- },
51
- {
52
- extends: true,
53
- test: {
54
- pool: customPool({
55
- customProperty: true,
56
- })
57
- }
58
- }
59
- ],
60
- },
61
- })
62
- ```
63
-
64
- ## API
65
-
66
- The `pool` option accepts a `PoolRunnerInitializer` that can be used for custom pool runners. The `name` property should indicate name of the custom pool runner. It should be identical with your worker's `name` property.
67
-
68
- ```ts [my-custom-pool.ts]
69
- import type { PoolRunnerInitializer } from 'vitest/node'
70
-
71
- export function customPool(customOptions: CustomOptions): PoolRunnerInitializer {
72
- return {
73
- name: 'custom-pool',
74
- createPoolWorker: options => new CustomPoolWorker(options, customOptions),
75
- }
76
- }
77
- ```
78
-
79
- In your `CustomPoolWorker` you need to define all required methods:
80
-
81
- ```ts [my-custom-pool.ts]
82
- import type { PoolOptions, PoolWorker, WorkerRequest } from 'vitest/node'
83
-
84
- class CustomPoolWorker implements PoolWorker {
85
- name = 'custom-pool'
86
- private customOptions: CustomOptions
87
-
88
- constructor(options: PoolOptions, customOptions: CustomOptions) {
89
- this.customOptions = customOptions
90
- }
91
-
92
- send(message: WorkerRequest): void {
93
- // Provide way to send your worker a message
94
- }
95
-
96
- on(event: string, callback: (arg: any) => void): void {
97
- // Provide way to listen to your workers events, e.g. message, error, exit
98
- }
99
-
100
- off(event: string, callback: (arg: any) => void): void {
101
- // Provide way to unsubscribe `on` listeners
102
- }
103
-
104
- async start() {
105
- // do something when the worker is started
106
- }
107
-
108
- async stop() {
109
- // cleanup the state
110
- }
111
-
112
- deserialize(data) {
113
- return data
114
- }
115
- }
116
- ```
117
-
118
- Your `CustomPoolRunner` will be controlling how your custom test runner worker life cycles and communication channel works. For example, your `CustomPoolRunner` could launch a `node:worker_threads` `Worker`, and provide communication via `Worker.postMessage` and `parentPort`.
119
-
120
- In your worker file, you can import helper utilities from `vitest/worker`:
121
-
122
- ```ts [my-worker.ts]
123
- import { init, runBaseTests, setupEnvironment } from 'vitest/worker'
124
-
125
- init({
126
- post: (response) => {
127
- // Provide way to send this message to CustomPoolRunner's onWorker as message event
128
- },
129
- on: (callback) => {
130
- // Provide a way to listen CustomPoolRunner's "postMessage" calls
131
- },
132
- off: (callback) => {
133
- // Optional, provide a way to remove listeners added by "on" calls
134
- },
135
- teardown: () => {
136
- // Optional, provide a way to teardown worker, e.g. unsubscribe all the `on` listeners
137
- },
138
- serialize: (value) => {
139
- // Optional, provide custom serializer for `post` calls
140
- },
141
- deserialize: (value) => {
142
- // Optional, provide custom deserializer for `on` callbacks
143
- },
144
- runTests: (state, traces) => runBaseTests('run', state, traces),
145
- collectTests: (state, traces) => runBaseTests('collect', state, traces),
146
- setup: setupEnvironment,
147
- })
148
- ```
@@ -1,93 +0,0 @@
1
- # Extending Reporters <Badge type="danger">advanced</Badge> {#extending-reporters}
2
-
3
- ::: warning
4
- This is an advanced API. If you just want to configure built-in reporters, read the ["Reporters"](/guide/reporters) guide.
5
- :::
6
-
7
- You can import reporters from `vitest/node` and extend them to create your custom reporters.
8
-
9
- ## Extending Built-in Reporters
10
-
11
- In general, you don't need to create your reporter from scratch. `vitest` comes with several default reporting programs that you can extend.
12
-
13
- ```ts
14
- import { DefaultReporter } from 'vitest/node'
15
-
16
- export default class MyDefaultReporter extends DefaultReporter {
17
- // do something
18
- }
19
- ```
20
-
21
- ::: warning
22
- However, note that exposed reports are not considered stable and can change the shape of their API within a minor version.
23
- :::
24
-
25
- Of course, you can create your reporter from scratch. Just implement the [`Reporter`](/api/advanced/reporters) interface:
26
-
27
- And here is an example of a custom reporter:
28
-
29
- ```ts [custom-reporter.js]
30
- import type { Reporter } from 'vitest/node'
31
-
32
- export default class CustomReporter implements Reporter {
33
- onTestModuleCollected(testModule) {
34
- console.log(testModule.moduleId, 'is finished')
35
-
36
- for (const test of testModule.children.allTests()) {
37
- console.log(test.name, test.result().state)
38
- }
39
- }
40
- }
41
- ```
42
-
43
- Then you can use your custom reporter in the `vitest.config.ts` file:
44
-
45
- ```ts [vitest.config.ts]
46
- import { defineConfig } from 'vitest/config'
47
- import CustomReporter from './custom-reporter.js'
48
-
49
- export default defineConfig({
50
- test: {
51
- reporters: [new CustomReporter()],
52
- },
53
- })
54
- ```
55
-
56
- ## Reported Tasks
57
-
58
- Reported [events](/api/advanced/reporters) receive tasks for [tests](/api/advanced/test-case), [suites](/api/advanced/test-suite) and [modules](/api/advanced/test-module):
59
-
60
- ```ts twoslash
61
- import type { Reporter, TestModule } from 'vitest/node'
62
-
63
- class MyReporter implements Reporter {
64
- onTestRunEnd(testModules: ReadonlyArray<TestModule>) {
65
- for (const testModule of testModules) {
66
- for (const task of testModule.children) {
67
- // ^?
68
- console.log('test run end', task.type, task.fullName)
69
- }
70
- }
71
- }
72
- }
73
- ```
74
-
75
- ## Exported Reporters
76
-
77
- `vitest` comes with a few [built-in reporters](/guide/reporters) that you can use out of the box.
78
-
79
- ### Built-in reporters:
80
-
81
- 1. `DefaultReporter`
82
- 2. `DotReporter`
83
- 3. `JsonReporter`
84
- 4. `VerboseReporter`
85
- 5. `TapReporter`
86
- 6. `JUnitReporter`
87
- 7. `TapFlatReporter`
88
- 8. `HangingProcessReporter`
89
- 9. `TreeReporter`
90
-
91
- ### Interface reporters:
92
-
93
- 1. `Reporter`
@@ -1,125 +0,0 @@
1
- # Running Tests <Badge type="danger">advanced</Badge> {#running-tests}
2
-
3
- ::: warning
4
- This guide explains how to use the advanced API to run tests via a Node.js script. If you just want to [run tests](/guide/), you probably don't need this. It is primarily used by library authors.
5
- :::
6
-
7
- Vitest exposes two methods to initiate Vitest:
8
-
9
- - `startVitest` initiates Vitest, validates the packages are installed and runs tests immediately
10
- - `createVitest` only initiates Vitest and doesn't run any tests
11
-
12
- ## `startVitest`
13
-
14
- ```ts
15
- import { startVitest } from 'vitest/node'
16
-
17
- const vitest = await startVitest(
18
- 'test',
19
- [], // CLI filters
20
- {}, // override test config
21
- {}, // override Vite config
22
- {}, // custom Vitest options
23
- )
24
- const testModules = vitest.state.getTestModules()
25
- for (const testModule of testModules) {
26
- console.log(testModule.moduleId, testModule.ok() ? 'passed' : 'failed')
27
- }
28
- ```
29
-
30
- ## `createVitest`
31
-
32
- Creates a [Vitest](/api/advanced/vitest) instances without running tests.
33
-
34
- `createVitest` method doesn't validate that required packages are installed. It also doesn't respect `config.standalone` or `config.mergeReports`. Vitest won't be closed automatically even if `watch` is disabled.
35
-
36
- ```ts
37
- import { createVitest } from 'vitest/node'
38
-
39
- const vitest = await createVitest(
40
- 'test',
41
- {}, // override test config
42
- {}, // override Vite config
43
- {}, // custom Vitest options
44
- )
45
-
46
- // called when `vitest.cancelCurrentRun()` is invoked
47
- vitest.onCancel(() => {})
48
- // called during `vitest.close()` call
49
- vitest.onClose(() => {})
50
- // called when Vitest reruns test files
51
- vitest.onTestsRerun((files) => {})
52
-
53
- try {
54
- // this will set process.exitCode to 1 if tests failed,
55
- // and won't close the process automatically
56
- await vitest.start(['my-filter'])
57
- }
58
- catch (err) {
59
- // this can throw
60
- // "FilesNotFoundError" if no files were found
61
- // "GitNotFoundError" with `--changed` and repository is not initialized
62
- }
63
- finally {
64
- await vitest.close()
65
- }
66
- ```
67
-
68
- If you intend to keep the `Vitest` instance, make sure to at least call [`init`](/api/advanced/vitest#init). This will initialise reporters and the coverage provider, but won't run any tests. It is also recommended to enable the `watch` mode even if you don't intend to use the Vitest watcher, but want to keep the instance running. Vitest relies on this flag for some of its features to work correctly in a continuous process.
69
-
70
- After reporters are initialised, use [`runTestSpecifications`](/api/advanced/vitest#runtestspecifications) or [`rerunTestSpecifications`](/api/advanced/vitest#reruntestspecifications) to run tests if manual run is required:
71
-
72
- ```ts
73
- watcher.on('change', async (file) => {
74
- const specifications = vitest.getModuleSpecifications(file)
75
- if (specifications.length) {
76
- vitest.invalidateFile(file)
77
- // you can use runTestSpecifications if "reporter.onWatcher*" hooks
78
- // should not be invoked
79
- await vitest.rerunTestSpecifications(specifications)
80
- }
81
- })
82
- ```
83
-
84
- ::: warning
85
- The example above shows a potential use-case if you disable the default watcher behaviour. By default, Vitest already reruns tests if files change.
86
-
87
- Also note that `getModuleSpecifications` will not resolve test files unless they were already processed by `globTestSpecifications`. If the file was just created, use `project.matchesGlobPattern` instead:
88
-
89
- ```ts
90
- watcher.on('add', async (file) => {
91
- const specifications = []
92
- for (const project of vitest.projects) {
93
- if (project.matchesGlobPattern(file)) {
94
- specifications.push(project.createSpecification(file))
95
- }
96
- }
97
-
98
- if (specifications.length) {
99
- await vitest.rerunTestSpecifications(specifications)
100
- }
101
- })
102
- ```
103
- :::
104
-
105
- In cases where you need to disable the watcher, you can pass down `server.watch: null` since Vite 5.3 or `server.watch: { ignored: ['*/*'] }` to a Vite config:
106
-
107
- ```ts
108
- await createVitest(
109
- 'test',
110
- {},
111
- {
112
- plugins: [
113
- {
114
- name: 'stop-watcher',
115
- async configureServer(server) {
116
- await server.watcher.close()
117
- }
118
- }
119
- ],
120
- server: {
121
- watch: null,
122
- },
123
- }
124
- )
125
- ```