@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,71 +0,0 @@
1
- # Testing Effect Schema Definitions
2
-
3
- ## When to use
4
-
5
- When you have an Effect Schema (`Schema.Struct`, `Schema.Class`, branded type, transformation) that defines a public-API shape and you want to verify: round-trip encode/decode preserves data, decoding rejects invalid input with useful errors, transformations behave correctly.
6
-
7
- ## Three test patterns
8
-
9
- ### Pattern A: round-trip
10
-
11
- ```typescript
12
- import { Schema } from "effect";
13
- import { describe, expect, it } from "vitest";
14
-
15
- const User = Schema.Struct({
16
- id: Schema.Number,
17
- name: Schema.String,
18
- });
19
-
20
- it("round-trips through encode + decode", () => {
21
- const value = { id: 42, name: "Ada" };
22
- const encoded = Schema.encodeUnknownSync(User)(value);
23
- const decoded = Schema.decodeUnknownSync(User)(encoded);
24
- expect(decoded).toEqual(value);
25
- });
26
- ```
27
-
28
- ### Pattern B: decoding error assertions
29
-
30
- ```typescript
31
- import { Either, Schema } from "effect";
32
- import { describe, expect, it } from "vitest";
33
-
34
- it("rejects invalid input with the expected error path", () => {
35
- const result = Schema.decodeUnknownEither(User)({ id: "not-a-number", name: "Ada" });
36
- expect(Either.isLeft(result)).toBe(true);
37
- if (Either.isLeft(result)) {
38
- const formatted = String(result.left);
39
- expect(formatted).toContain("id");
40
- expect(formatted).toMatch(/expected number/i);
41
- }
42
- });
43
- ```
44
-
45
- ### Pattern C: transformations
46
-
47
- For `Schema.transform` between two shapes (typical for parsing JSON-stringified payloads):
48
-
49
- ```typescript
50
- const Comma = Schema.transform(Schema.String, Schema.Array(Schema.String), {
51
- decode: (s) => s.split(","),
52
- encode: (a) => a.join(","),
53
- });
54
-
55
- it("decodes and encodes the inverse", () => {
56
- expect(Schema.decodeUnknownSync(Comma)("a,b,c")).toEqual(["a", "b", "c"]);
57
- expect(Schema.encodeUnknownSync(Comma)(["a", "b"])).toBe("a,b");
58
- });
59
- ```
60
-
61
- ## Anti-patterns
62
-
63
- - **Don't assert on stringified errors verbatim.** Effect Schema's error formatting can shift between minor versions; assert on substrings or use `ParseResult.TreeFormatter` for stable output.
64
- - **Don't write tests that rely on `Schema.transformOrFail` failing _silently_.** When a transform can fail, exercise the failure path explicitly — `Either` results from `decodeUnknownEither` are the right tool.
65
- - **Don't recreate the schema in the test.** Import the production definition; otherwise the test passes when the production schema drifts.
66
-
67
- ## See also
68
-
69
- - `vitest://docs/api/expect` — Vitest matcher reference for the assertion patterns
70
- - `vitest-agent://patterns/testing-effect-services-with-mock-layers` — Companion pattern; services hand around Schema-typed data
71
- - Effect Schema docs at `https://effect.website/docs/schema/introduction`
@@ -1,63 +0,0 @@
1
- # Testing Effect Services with Mock Layers
2
-
3
- ## When to use
4
-
5
- Reach for this pattern when an Effect service has external dependencies (filesystem, SQLite, network) that you do not want to exercise in unit tests. The codebase under `packages/sdk/src/services/` and `packages/sdk/src/layers/` follows this exact shape.
6
-
7
- ## The shape
8
-
9
- Every Effect service has three pieces:
10
-
11
- 1. **The service tag** (`Context.Tag`) and interface — under `services/`.
12
- 2. **The live layer** — wires real I/O against `@effect/platform` adapters.
13
- 3. **The test layer** — usually a mutable state container that records what the service was asked to do, with read methods you assert against.
14
-
15
- You compose the live layer in production wiring (`ReporterLive`, `CliLive`, `McpLive`); you compose the test layer in tests.
16
-
17
- ## Minimal example
18
-
19
- ```typescript
20
- import { Effect, Layer, Ref } from "effect";
21
- import { describe, expect, it } from "vitest";
22
- import { DataStore } from "@vitest-agent/sdk";
23
-
24
- // Test layer: accumulates writes into a Ref so tests can read them back.
25
- const DataStoreTest = Layer.effect(
26
- DataStore,
27
- Effect.gen(function* () {
28
- const writes = yield* Ref.make<{ runs: ReadonlyArray<unknown> }>({ runs: [] });
29
- return DataStore.of({
30
- writeRun: (input) =>
31
- Ref.update(writes, (s) => ({ runs: [...s.runs, input] })).pipe(
32
- Effect.as(1),
33
- ),
34
- // ... other methods stubbed similarly
35
- });
36
- }),
37
- );
38
-
39
- it("records the run", async () => {
40
- const program = Effect.gen(function* () {
41
- const store = yield* DataStore;
42
- yield* store.writeRun({ project: "x" });
43
- // assert via your accumulator pattern
44
- });
45
- await Effect.runPromise(program.pipe(Effect.provide(DataStoreTest)));
46
- });
47
- ```
48
-
49
- ## Why not mock the FileSystem directly?
50
-
51
- Layer-level swapping is the testable seam Effect was designed around. Mocking `@effect/platform`'s FileSystem implementation works but loses the type checking that ensures your test layer matches the live interface. Layer.effect with the same Tag forces you to satisfy every method.
52
-
53
- ## Anti-patterns
54
-
55
- - **Don't `Effect.runPromise` inside service implementations** — providing `DataStoreTest` and then having the service call `Effect.runPromise` internally bypasses the layer.
56
- - **Don't share `Ref`s across tests** — construct the test layer per-test (or use `beforeEach`) so accumulated state doesn't bleed.
57
- - **Don't assert on layer construction order** — Effect normalizes the merge graph.
58
-
59
- ## See also
60
-
61
- - `vitest://docs/guide/mocking` — Vitest mocking guide (general background)
62
- - `vitest-agent://patterns/testing-effect-schema-definitions` — Companion pattern; most service inputs are Schema-typed
63
- - `packages/sdk/src/layers/DataStoreTest.ts` — The canonical example in this codebase
@@ -1,5 +0,0 @@
1
- # Attribution
2
-
3
- The markdown files under `vendor/vitest-docs/` are vendored from the [Vitest project](https://github.com/vitest-dev/vitest) under the MIT License.
4
-
5
- See `manifest.json` for the exact upstream tag and commit SHA captured.
@@ -1,189 +0,0 @@
1
- # Test Artifacts <Advanced /> <Version type="experimental">4.0.11</Version> <Experimental />
2
-
3
- ::: warning
4
- This is an advanced API. As a user, you most likely want to use [test annotations](/guide/test-annotations) to add notes or context to your tests instead. This is primarily used internally and by library authors.
5
- :::
6
-
7
- Test artifacts allow attaching or recording structured data, files, or metadata during test execution. This is a low-level feature primarily designed for:
8
-
9
- - Internal use ([`annotate`](/guide/test-annotations) is built on top of the artifact system)
10
- - Framework authors creating custom testing tools on top of Vitest
11
-
12
- Each artifact includes:
13
-
14
- - A type discriminator which is a unique identifier for the artifact type
15
- - Custom data, can be any relevant information
16
- - Optional attachments, either files or inline content associated with the artifact
17
- - A source code location indicating where the artifact was created
18
-
19
- Vitest automatically manages attachment serialization (files are copied to [`attachmentsDir`](/config/attachmentsdir)) and injects source location metadata, so you can focus on the data you want to record. All artifacts **must** extend from [`TestArtifactBase`](#testartifactbase) and all attachments from [`TestAttachment`](#testattachment) to be correctly handled internally.
20
-
21
- ## API
22
-
23
- ### `recordArtifact` <Experimental /> {#recordartifact}
24
-
25
- ::: warning
26
- `recordArtifact` is an experimental API. Breaking changes might not follow SemVer, please pin Vitest's version when using it.
27
-
28
- The API surface may change based on feedback. We encourage you to try it out and share your experience with the team.
29
- :::
30
-
31
- ```ts
32
- function recordArtifact<Artifact extends TestArtifact>(task: Test, artifact: Artifact): Promise<Artifact>
33
- ```
34
-
35
- The `recordArtifact` function records an artifact during test execution and returns it. It expects a [task](/api/advanced/runner#tasks) as the first parameter and an object assignable to [`TestArtifact`](#testartifact) as the second.
36
-
37
- ::: info
38
- Artifacts must be recorded before the task is reported. Any artifacts recorded after that will not be included in the task.
39
- :::
40
-
41
- When an artifact is recorded on a test, it emits an `onTestArtifactRecord` runner event and a [`onTestCaseArtifactRecord` reporter event](/api/advanced/reporters#ontestcaseartifactrecord). To retrieve recorded artifacts from a test case, use the [`artifacts()`](/api/advanced/test-case#artifacts) method.
42
-
43
- Note: annotations, [even though they're built on top of this feature](#relationship-with-annotations), won't appear in the `task.artifacts` array for backwards compatibility reasons until the next major version.
44
-
45
- ### `TestArtifact`
46
-
47
- The `TestArtifact` type is a union containing all artifacts Vitest can produce, including custom ones. All artifacts extend from [`TestArtifactBase`](#testartifactbase)
48
-
49
- ### `TestArtifactBase` <Experimental /> {#testartifactbase}
50
-
51
- ```ts
52
- export interface TestArtifactBase {
53
- /** File or data attachments associated with this artifact */
54
- attachments?: TestAttachment[]
55
- /** Source location where this artifact was created */
56
- location?: TestArtifactLocation
57
- }
58
- ```
59
-
60
- The `TestArtifactBase` interface is the base for all test artifacts.
61
-
62
- Extend this interface when creating custom test artifacts. Vitest automatically manages the `attachments` array and injects the `location` property to indicate where the artifact was created in your test code.
63
-
64
- ::: danger
65
- When running with [`api.allowWrite`](/config/api#api-allowwrite) or [`browser.api.allowWrite`](/config/browser/api#api-allowwrite) disabled, Vitest empties the `attachments` array on every artifact before reporting it.
66
-
67
- If your custom artifact narrows the `attachments` type (e.g. to a tuple), include `| []` in the union so the type reflects what actually happens at runtime.
68
- :::
69
-
70
- ### `TestAttachment`
71
-
72
- ```ts
73
- export interface TestAttachment {
74
- /** MIME type of the attachment (e.g., 'image/png', 'text/plain') */
75
- contentType?: string
76
- /** File system path to the attachment */
77
- path?: string
78
- /** Inline attachment content as a string or raw binary data */
79
- body?: string | Uint8Array
80
- /**
81
- * @experimental
82
- * How the string `body` is encoded.
83
- * - `'base64'` (default): body is already base64-encoded
84
- * - `'utf-8'`: body is a utf8 string
85
- */
86
- bodyEncoding?: 'base64' | 'utf-8'
87
- }
88
- ```
89
-
90
- The `TestAttachment` interface represents a file or data attachment associated with a test artifact.
91
-
92
- Attachments can be either file-based (via `path`) or inline content (via `body`). The `contentType` helps consumers understand how to interpret the attachment data.
93
-
94
- If you pass a string `body`, Vitest assumes it is already base64-encoded unless you set `bodyEncoding: 'utf-8'`. When you pass `body` as a `Uint8Array`, Vitest automatically encodes it as base64. The `bodyEncoding` option only applies to inline `body` attachments, not `path` attachments.
95
-
96
- ### `TestArtifactLocation`
97
-
98
- ```ts
99
- export interface TestArtifactLocation {
100
- /** Line number in the source file (1-indexed) */
101
- line: number
102
- /** Column number in the line (1-indexed) */
103
- column: number
104
- /** Path to the source file */
105
- file: string
106
- }
107
- ```
108
-
109
- The `TestArtifactLocation` interface represents the source code location information for a test artifact. It indicates where in the source code the artifact originated from.
110
-
111
- ### `TestArtifactRegistry`
112
-
113
- The `TestArtifactRegistry` interface is a registry for custom test artifact types.
114
-
115
- Augmenting this interface using [TypeScript's module augmentation feature](https://typescriptlang.org/docs/handbook/declaration-merging#module-augmentation) allows registering custom artifact types that tests can produce.
116
-
117
- Each custom artifact should extend [`TestArtifactBase`](#testartifactbase) and include a unique `type` discriminator property.
118
-
119
- Here are a few guidelines or best practices to follow:
120
-
121
- - Try using a `Symbol` as the **registry key** to guarantee uniqueness
122
- - The `type` property should follow the pattern `'package-name:artifact-name'`, **`'internal:'` is a reserved prefix**
123
- - Use `attachments` to include files or data; extend [`TestAttachment`](#testattachment) for custom metadata
124
- - If you narrow the `attachments` type (e.g. to a tuple), include `| []` in the union since Vitest may empty the array at runtime (see [`TestArtifactBase`](#testartifactbase))
125
- - `location` property is automatically injected
126
-
127
- ## Custom Artifacts
128
-
129
- To use and manage artifacts in a type-safe manner, you need to create its type and register it:
130
-
131
- ```ts
132
- import type { TestArtifactBase, TestAttachment } from 'vitest'
133
-
134
- interface A11yReportAttachment extends TestAttachment {
135
- contentType: 'text/html'
136
- path: string
137
- }
138
-
139
- interface AccessibilityArtifact extends TestArtifactBase {
140
- type: 'a11y:report'
141
- passed: boolean
142
- wcagLevel: 'A' | 'AA' | 'AAA'
143
- attachments: [A11yReportAttachment] | []
144
- }
145
-
146
- const a11yReportKey = Symbol('report')
147
-
148
- declare module 'vitest' {
149
- interface TestArtifactRegistry {
150
- [a11yReportKey]: AccessibilityArtifact
151
- }
152
- }
153
- ```
154
-
155
- As long as the types are assignable to their bases and don't have errors, everything should work fine and you should be able to record artifacts using [`recordArtifact`](#recordartifact):
156
-
157
- ```ts
158
- async function toBeAccessible(
159
- this: MatcherState,
160
- actual: Element,
161
- wcagLevel: 'A' | 'AA' | 'AAA' = 'AA'
162
- ): AsyncExpectationResult {
163
- const report = await runAccessibilityAudit(actual, wcagLevel)
164
-
165
- await recordArtifact(this.task, {
166
- type: 'a11y:report',
167
- passed: report.violations.length === 0,
168
- wcagLevel,
169
- attachments: [{
170
- contentType: 'text/html',
171
- path: report.path,
172
- }],
173
- })
174
-
175
- return {
176
- pass: violations.length === 0,
177
- message: () => `Found ${report.violations.length} accessibility violation(s)`
178
- }
179
- }
180
- ```
181
-
182
- ## Relationship with Annotations
183
-
184
- Test annotations are built on top of the artifact system. When using annotations in tests, they create `internal:annotation` artifacts under the hood. However, annotations are:
185
-
186
- - Simpler to use
187
- - Designed for end-users, not developers
188
-
189
- Use annotations if you just want to add notes to your tests. Use artifacts if you need custom data.
@@ -1,68 +0,0 @@
1
- # Task Metadata <Badge type="danger">advanced</Badge>
2
-
3
- If you are developing a custom reporter or using Vitest Node.js API, you might find it useful to pass data from tests that are being executed in various contexts to your reporter or custom Vitest handler.
4
-
5
- To accomplish this, relying on the [test context](/guide/test-context) is not feasible since it cannot be serialized. However, with Vitest, you can utilize the `meta` property available on every task (suite or test) to share data between your tests and the Node.js process. It's important to note that this communication is one-way only, as the `meta` property can only be modified from within the test context. Any changes made within the Node.js context will not be visible in your tests.
6
-
7
- You can populate `meta` property on test context or inside `beforeAll`/`afterAll` hooks for suite tasks.
8
-
9
- ```ts
10
- afterAll((suite) => {
11
- suite.meta.done = true
12
- })
13
-
14
- test('custom', ({ task }) => {
15
- task.meta.custom = 'some-custom-handler'
16
- })
17
- ```
18
-
19
- Once a test is completed, Vitest will send a task including the result and `meta` to the Node.js process using RPC, and then report it in `onTestCaseResult` and other hooks that have access to tasks. To process this test case, you can utilize the `onTestCaseResult` method available in your reporter implementation:
20
-
21
- ```ts [custom-reporter.js]
22
- import type { Reporter, TestCase, TestModule } from 'vitest/node'
23
-
24
- export default {
25
- onTestCaseResult(testCase: TestCase) {
26
- // custom === 'some-custom-handler' ✅
27
- const { custom } = testCase.meta()
28
- },
29
- onTestRunEnd(testModule: TestModule) {
30
- testModule.meta().done === true
31
- testModule.children.at(0).meta().custom === 'some-custom-handler'
32
- }
33
- } satisfies Reporter
34
- ```
35
-
36
- ::: danger BEWARE
37
- Vitest uses different methods to communicate with the Node.js process.
38
-
39
- - If Vitest runs tests inside worker threads, it will send data via [message port](https://developer.mozilla.org/en-US/docs/Web/API/MessagePort)
40
- - If Vitest uses child process, the data will be send as a serialized Buffer via [`process.send`](https://nodejs.org/api/process.html#processsendmessage-sendhandle-options-callback) API
41
- - If Vitest runs tests in the browser, the data will be stringified using [flatted](https://npmx.dev/package/flatted) package
42
-
43
- This property is also present on every test in the `json` reporter, so make sure that data can be serialized into JSON.
44
-
45
- Also, make sure you serialize [Error properties](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm#error_types) before you set them.
46
- :::
47
-
48
- You can also get this information from Vitest state when tests finished running:
49
-
50
- ```ts
51
- const vitest = await createVitest('test')
52
- const { testModules } = await vitest.start()
53
-
54
- const testModule = testModules[0]
55
- testModule.meta().done === true
56
- testModule.children.at(0).meta().custom === 'some-custom-handler'
57
- ```
58
-
59
- It's also possible to extend type definitions when using TypeScript:
60
-
61
- ```ts
62
- declare module 'vitest' {
63
- interface TaskMeta {
64
- done?: boolean
65
- custom?: string
66
- }
67
- }
68
- ```
@@ -1,168 +0,0 @@
1
- # Plugin API <Version>3.1.0</Version> {#plugin-api}
2
-
3
- ::: warning
4
- This is an advanced API. If you just want to [run tests](/guide/), you probably don't need this. It is primarily used by library authors.
5
-
6
- This guide assumes you know how to work with [Vite plugins](https://vite.dev/guide/api-plugin.html).
7
- :::
8
-
9
- Vitest supports a `configureVitest` [plugin](https://vite.dev/guide/api-plugin.html) hook since version 3.1.
10
-
11
- ::: code-group
12
- ```ts [only vitest]
13
- import type { Vite, VitestPluginContext } from 'vitest/node'
14
-
15
- export function plugin(): Vite.Plugin {
16
- return {
17
- name: 'vitest:my-plugin',
18
- configureVitest(context: VitestPluginContext) {
19
- // ...
20
- }
21
- }
22
- }
23
- ```
24
- ```ts [vite and vitest]
25
- /// <reference types="vitest/config" />
26
-
27
- import type { Plugin } from 'vite'
28
-
29
- export function plugin(): Plugin {
30
- return {
31
- name: 'vitest:my-plugin',
32
- transform() {
33
- // ...
34
- },
35
- configureVitest(context) {
36
- // ...
37
- }
38
- }
39
- }
40
- ```
41
- :::
42
-
43
- ::: tip TypeScript
44
- Vitest re-exports all Vite type-only imports via a `Vite` namespace, which you can use to keep your versions in sync. However, if you are writing a plugin for both Vite and Vitest, you can continue using the `Plugin` type from the `vite` entrypoint. Just make sure you have `vitest/config` referenced somewhere so that `configureVitest` is augmented correctly:
45
-
46
- ```ts
47
- /// <reference types="vitest/config" />
48
- ```
49
- :::
50
-
51
- Unlike [`reporter.onInit`](/api/advanced/reporters#oninit), this hooks runs early in Vitest lifecycle allowing you to make changes to configuration like `coverage` and `reporters`. A more notable change is that you can manipulate the global config from a [test project](/guide/projects) if your plugin is defined in the project and not in the global config.
52
-
53
- ## Context
54
-
55
- ### project
56
-
57
- The current [test project](./test-project) that the plugin belongs to.
58
-
59
- ::: warning Browser Mode
60
- Note that if you are relying on a browser feature, the `project.browser` field is not set yet. Use [`reporter.onBrowserInit`](./reporters#onbrowserinit) event instead.
61
- :::
62
-
63
- ### vitest
64
-
65
- The global [Vitest](./vitest) instance. You can change the global configuration by directly mutating the `vitest.config` property:
66
-
67
- ```ts
68
- vitest.config.coverage.enabled = false
69
- vitest.config.reporters.push([['my-reporter', {}]])
70
- ```
71
-
72
- ::: warning Config is Resolved
73
- Note that Vitest already resolved the config, so some types might be different from the usual user configuration. This also means that some properties will not be resolved again, like `setupFile`. If you are adding new files, make sure to resolve it first.
74
-
75
- At this point reporters are not created yet, so modifying `vitest.reporters` will have no effect because it will be overwritten. If you need to inject your own reporter, modify the config instead.
76
- :::
77
-
78
- ### injectTestProjects
79
-
80
- ```ts
81
- function injectTestProjects(
82
- config: TestProjectConfiguration | TestProjectConfiguration[]
83
- ): Promise<TestProject[]>
84
- ```
85
-
86
- This methods accepts a config glob pattern, a filepath to the config or an inline configuration. It returns an array of resolved [test projects](./test-project).
87
-
88
- ```ts
89
- // inject a single project with a custom alias
90
- const newProjects = await injectTestProjects({
91
- // you can inherit the current project config by referencing `extends`
92
- // note that you cannot have a project with the name that already exists,
93
- // so it's a good practice to define a custom name
94
- extends: project.vite.config.configFile,
95
- test: {
96
- name: 'my-custom-alias',
97
- alias: {
98
- customAlias: resolve('./custom-path.js'),
99
- },
100
- },
101
- })
102
- ```
103
-
104
- ::: warning Projects are Filtered
105
- Vitest filters projects during the config resolution, so if the user defined a filter, injected project might not be resolved unless it [matches the filter](./vitest#matchesprojectfilter). You can update the filter via the `vitest.config.project` option to always include your test project:
106
-
107
- ```ts
108
- vitest.config.project.push('my-project-name')
109
- ```
110
-
111
- Note that this will only affect projects injected with [`injectTestProjects`](#injecttestprojects) method.
112
- :::
113
-
114
- ::: tip Referencing the Current Config
115
- If you want to keep the user configuration, you can specify the `extends` property. All other properties will be merged with the user defined config.
116
-
117
- The project's `configFile` can be accessed in Vite's config: `project.vite.config.configFile`.
118
-
119
- Note that this will also inherit the `name` - Vitest doesn't allow multiple projects with the same name, so this will throw an error. Make sure you specified a different name. You can access the current name via the `project.name` property and all used names are available in the `vitest.projects` array.
120
- :::
121
-
122
- ### experimental_defineCacheKeyGenerator <Version type="experimental">4.0.11</Version> <Experimental /> {#definecachekeygenerator}
123
-
124
- ```ts
125
- interface CacheKeyIdGeneratorContext {
126
- environment: DevEnvironment
127
- id: string
128
- sourceCode: string
129
- }
130
-
131
- function experimental_defineCacheKeyGenerator(
132
- callback: (context: CacheKeyIdGeneratorContext) => string | undefined | null | false
133
- ): void
134
- ```
135
-
136
- Define a generator that will be applied before hashing the cache key.
137
-
138
- Use this to make sure Vitest generates correct hash. It is a good idea to define this function if your plugin can be registered with different options.
139
-
140
- This is called only if [`experimental.fsModuleCache`](/config/experimental#experimental-fsmodulecache) is defined.
141
-
142
- ```ts
143
- interface PluginOptions {
144
- replacePropertyKey: string
145
- replacePropertyValue: string
146
- }
147
-
148
- export function plugin(options: PluginOptions) {
149
- return {
150
- name: 'plugin-that-replaces-property',
151
- transform(code) {
152
- return code.replace(
153
- options.replacePropertyKey,
154
- options.replacePropertyValue
155
- )
156
- },
157
- configureVitest({ experimental_defineCacheKeyGenerator }) {
158
- experimental_defineCacheKeyGenerator(() => {
159
- // since these options affect the transform result,
160
- // return them together as a unique string
161
- return options.replacePropertyKey + options.replacePropertyValue
162
- })
163
- }
164
- }
165
- }
166
- ```
167
-
168
- If `false` is returned, the module will not be cached on the file system.