@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.
- package/README.md +1 -2
- package/bin/vitest-agent-mcp.js +1 -17
- package/index.d.ts +324 -315
- package/index.js +2 -4
- package/middleware/idempotency.js +1 -1
- package/package.json +2 -2
- package/server.js +2 -4
- package/tools/acceptance-metrics.js +1 -1
- package/tools/cache-health.js +1 -1
- package/tools/commit-changes.js +1 -1
- package/tools/configure.js +1 -1
- package/tools/coverage.js +1 -1
- package/tools/errors.js +1 -1
- package/tools/failure-signature-get.js +1 -1
- package/tools/file-coverage.js +1 -1
- package/tools/history.js +1 -1
- package/tools/inventory.js +1 -1
- package/tools/overview.js +1 -1
- package/tools/run-tests.js +15 -3
- package/tools/settings-list.js +1 -1
- package/tools/status.js +1 -1
- package/tools/tdd-artifact.js +1 -1
- package/tools/tdd-task.js +1 -1
- package/tools/test.js +1 -1
- package/tools/trends.js +1 -1
- package/tools/turn-search.js +1 -1
- package/public/patterns/_meta.json +0 -67
- package/public/patterns/authoring-a-custom-vitest-agent-reporter.md +0 -82
- package/public/patterns/known-issues-and-caveats.md +0 -52
- package/public/patterns/operating-vitest-agent-as-an-agent.md +0 -53
- package/public/patterns/running-tests-via-mcp.md +0 -58
- package/public/patterns/silencing-leaking-output-in-tests.md +0 -91
- package/public/patterns/testing-effect-schema-definitions.md +0 -71
- package/public/patterns/testing-effect-services-with-mock-layers.md +0 -63
- package/public/vendor/vitest-docs/ATTRIBUTION.md +0 -5
- package/public/vendor/vitest-docs/api/advanced/artifacts.md +0 -189
- package/public/vendor/vitest-docs/api/advanced/metadata.md +0 -68
- package/public/vendor/vitest-docs/api/advanced/plugin.md +0 -168
- package/public/vendor/vitest-docs/api/advanced/reporters.md +0 -342
- package/public/vendor/vitest-docs/api/advanced/runner.md +0 -334
- package/public/vendor/vitest-docs/api/advanced/test-case.md +0 -302
- package/public/vendor/vitest-docs/api/advanced/test-collection.md +0 -89
- package/public/vendor/vitest-docs/api/advanced/test-module.md +0 -140
- package/public/vendor/vitest-docs/api/advanced/test-project.md +0 -321
- package/public/vendor/vitest-docs/api/advanced/test-specification.md +0 -96
- package/public/vendor/vitest-docs/api/advanced/test-suite.md +0 -230
- package/public/vendor/vitest-docs/api/advanced/vitest.md +0 -684
- package/public/vendor/vitest-docs/api/assert-type.md +0 -22
- package/public/vendor/vitest-docs/api/assert.md +0 -1960
- package/public/vendor/vitest-docs/api/browser/assertions.md +0 -1277
- package/public/vendor/vitest-docs/api/browser/commands.md +0 -154
- package/public/vendor/vitest-docs/api/browser/context.md +0 -338
- package/public/vendor/vitest-docs/api/browser/interactivity.md +0 -681
- package/public/vendor/vitest-docs/api/browser/locators.md +0 -1171
- package/public/vendor/vitest-docs/api/browser/react.md +0 -346
- package/public/vendor/vitest-docs/api/browser/svelte.md +0 -292
- package/public/vendor/vitest-docs/api/browser/vue.md +0 -222
- package/public/vendor/vitest-docs/api/describe.md +0 -374
- package/public/vendor/vitest-docs/api/expect-typeof.md +0 -571
- package/public/vendor/vitest-docs/api/expect.md +0 -2304
- package/public/vendor/vitest-docs/api/hooks.md +0 -463
- package/public/vendor/vitest-docs/api/mock.md +0 -701
- package/public/vendor/vitest-docs/api/test.md +0 -926
- package/public/vendor/vitest-docs/api/vi.md +0 -1372
- package/public/vendor/vitest-docs/config/alias.md +0 -13
- package/public/vendor/vitest-docs/config/allowonly.md +0 -32
- package/public/vendor/vitest-docs/config/api.md +0 -27
- package/public/vendor/vitest-docs/config/attachmentsdir.md +0 -6
- package/public/vendor/vitest-docs/config/bail.md +0 -9
- package/public/vendor/vitest-docs/config/benchmark.md +0 -65
- package/public/vendor/vitest-docs/config/browser/api.md +0 -23
- package/public/vendor/vitest-docs/config/browser/commands.md +0 -6
- package/public/vendor/vitest-docs/config/browser/connecttimeout.md +0 -10
- package/public/vendor/vitest-docs/config/browser/detailspanelposition.md +0 -38
- package/public/vendor/vitest-docs/config/browser/enabled.md +0 -40
- package/public/vendor/vitest-docs/config/browser/expect.md +0 -250
- package/public/vendor/vitest-docs/config/browser/headless.md +0 -7
- package/public/vendor/vitest-docs/config/browser/instances.md +0 -47
- package/public/vendor/vitest-docs/config/browser/isolate.md +0 -11
- package/public/vendor/vitest-docs/config/browser/locators.md +0 -24
- package/public/vendor/vitest-docs/config/browser/orchestratorscripts.md +0 -39
- package/public/vendor/vitest-docs/config/browser/playwright.md +0 -214
- package/public/vendor/vitest-docs/config/browser/preview.md +0 -32
- package/public/vendor/vitest-docs/config/browser/provider.md +0 -79
- package/public/vendor/vitest-docs/config/browser/screenshotdirectory.md +0 -6
- package/public/vendor/vitest-docs/config/browser/screenshotfailures.md +0 -6
- package/public/vendor/vitest-docs/config/browser/testerhtmlpath.md +0 -5
- package/public/vendor/vitest-docs/config/browser/trace.md +0 -43
- package/public/vendor/vitest-docs/config/browser/trackunhandlederrors.md +0 -10
- package/public/vendor/vitest-docs/config/browser/ui.md +0 -7
- package/public/vendor/vitest-docs/config/browser/viewport.md +0 -6
- package/public/vendor/vitest-docs/config/browser/webdriverio.md +0 -64
- package/public/vendor/vitest-docs/config/cache.md +0 -26
- package/public/vendor/vitest-docs/config/chaiconfig.md +0 -29
- package/public/vendor/vitest-docs/config/clearmocks.md +0 -22
- package/public/vendor/vitest-docs/config/coverage.md +0 -455
- package/public/vendor/vitest-docs/config/css.md +0 -47
- package/public/vendor/vitest-docs/config/dangerouslyignoreunhandlederrors.md +0 -23
- package/public/vendor/vitest-docs/config/deps.md +0 -127
- package/public/vendor/vitest-docs/config/detectasyncleaks.md +0 -39
- package/public/vendor/vitest-docs/config/diff.md +0 -96
- package/public/vendor/vitest-docs/config/dir.md +0 -7
- package/public/vendor/vitest-docs/config/disableconsoleintercept.md +0 -15
- package/public/vendor/vitest-docs/config/env.md +0 -5
- package/public/vendor/vitest-docs/config/environment.md +0 -96
- package/public/vendor/vitest-docs/config/environmentoptions.md +0 -30
- package/public/vendor/vitest-docs/config/exclude.md +0 -49
- package/public/vendor/vitest-docs/config/execargv.md +0 -10
- package/public/vendor/vitest-docs/config/expandsnapshotdiff.md +0 -7
- package/public/vendor/vitest-docs/config/expect.md +0 -38
- package/public/vendor/vitest-docs/config/experimental.md +0 -510
- package/public/vendor/vitest-docs/config/faketimers.md +0 -51
- package/public/vendor/vitest-docs/config/fileparallelism.md +0 -11
- package/public/vendor/vitest-docs/config/forcereruntriggers.md +0 -19
- package/public/vendor/vitest-docs/config/globals.md +0 -42
- package/public/vendor/vitest-docs/config/globalsetup.md +0 -72
- package/public/vendor/vitest-docs/config/hideskippedtests.md +0 -7
- package/public/vendor/vitest-docs/config/hooktimeout.md +0 -7
- package/public/vendor/vitest-docs/config/include-source.md +0 -115
- package/public/vendor/vitest-docs/config/include.md +0 -71
- package/public/vendor/vitest-docs/config/includetasklocation.md +0 -17
- package/public/vendor/vitest-docs/config/index.md +0 -85
- package/public/vendor/vitest-docs/config/isolate.md +0 -13
- package/public/vendor/vitest-docs/config/logheapusage.md +0 -7
- package/public/vendor/vitest-docs/config/maxconcurrency.md +0 -9
- package/public/vendor/vitest-docs/config/maxworkers.md +0 -49
- package/public/vendor/vitest-docs/config/mockreset.md +0 -22
- package/public/vendor/vitest-docs/config/mode.md +0 -7
- package/public/vendor/vitest-docs/config/name.md +0 -111
- package/public/vendor/vitest-docs/config/onconsolelog.md +0 -25
- package/public/vendor/vitest-docs/config/onstacktrace.md +0 -32
- package/public/vendor/vitest-docs/config/onunhandlederror.md +0 -35
- package/public/vendor/vitest-docs/config/open.md +0 -7
- package/public/vendor/vitest-docs/config/outputfile.md +0 -7
- package/public/vendor/vitest-docs/config/passwithnotests.md +0 -7
- package/public/vendor/vitest-docs/config/pool.md +0 -45
- package/public/vendor/vitest-docs/config/printconsoletrace.md +0 -6
- package/public/vendor/vitest-docs/config/projects.md +0 -6
- package/public/vendor/vitest-docs/config/provide.md +0 -45
- package/public/vendor/vitest-docs/config/reporters.md +0 -69
- package/public/vendor/vitest-docs/config/resolvesnapshotpath.md +0 -36
- package/public/vendor/vitest-docs/config/restoremocks.md +0 -22
- package/public/vendor/vitest-docs/config/retry.md +0 -140
- package/public/vendor/vitest-docs/config/root.md +0 -6
- package/public/vendor/vitest-docs/config/runner.md +0 -6
- package/public/vendor/vitest-docs/config/sequence.md +0 -158
- package/public/vendor/vitest-docs/config/server.md +0 -68
- package/public/vendor/vitest-docs/config/setupfiles.md +0 -40
- package/public/vendor/vitest-docs/config/silent.md +0 -9
- package/public/vendor/vitest-docs/config/slowtestthreshold.md +0 -7
- package/public/vendor/vitest-docs/config/snapshotenvironment.md +0 -27
- package/public/vendor/vitest-docs/config/snapshotformat.md +0 -28
- package/public/vendor/vitest-docs/config/snapshotserializers.md +0 -6
- package/public/vendor/vitest-docs/config/stricttags.md +0 -30
- package/public/vendor/vitest-docs/config/tags.md +0 -141
- package/public/vendor/vitest-docs/config/teardowntimeout.md +0 -7
- package/public/vendor/vitest-docs/config/testnamepattern.md +0 -21
- package/public/vendor/vitest-docs/config/testtimeout.md +0 -7
- package/public/vendor/vitest-docs/config/typecheck.md +0 -77
- package/public/vendor/vitest-docs/config/ui.md +0 -15
- package/public/vendor/vitest-docs/config/unstubenvs.md +0 -20
- package/public/vendor/vitest-docs/config/unstubglobals.md +0 -20
- package/public/vendor/vitest-docs/config/update.md +0 -16
- package/public/vendor/vitest-docs/config/vmmemorylimit.md +0 -30
- package/public/vendor/vitest-docs/config/watch.md +0 -11
- package/public/vendor/vitest-docs/config/watchtriggerpatterns.md +0 -29
- package/public/vendor/vitest-docs/guide/advanced/index.md +0 -147
- package/public/vendor/vitest-docs/guide/advanced/pool.md +0 -148
- package/public/vendor/vitest-docs/guide/advanced/reporters.md +0 -93
- package/public/vendor/vitest-docs/guide/advanced/tests.md +0 -125
- package/public/vendor/vitest-docs/guide/browser/aria-snapshots.md +0 -470
- package/public/vendor/vitest-docs/guide/browser/component-testing.md +0 -571
- package/public/vendor/vitest-docs/guide/browser/index.md +0 -630
- package/public/vendor/vitest-docs/guide/browser/multiple-setups.md +0 -121
- package/public/vendor/vitest-docs/guide/browser/trace-view.md +0 -126
- package/public/vendor/vitest-docs/guide/browser/visual-regression-testing.md +0 -734
- package/public/vendor/vitest-docs/guide/cli-generated.md +0 -972
- package/public/vendor/vitest-docs/guide/cli.md +0 -234
- package/public/vendor/vitest-docs/guide/common-errors.md +0 -163
- package/public/vendor/vitest-docs/guide/coverage.md +0 -515
- package/public/vendor/vitest-docs/guide/debugging.md +0 -127
- package/public/vendor/vitest-docs/guide/environment.md +0 -101
- package/public/vendor/vitest-docs/guide/extending-matchers.md +0 -160
- package/public/vendor/vitest-docs/guide/features.md +0 -310
- package/public/vendor/vitest-docs/guide/filtering.md +0 -175
- package/public/vendor/vitest-docs/guide/ide.md +0 -43
- package/public/vendor/vitest-docs/guide/improving-performance.md +0 -245
- package/public/vendor/vitest-docs/guide/in-source.md +0 -159
- package/public/vendor/vitest-docs/guide/index.md +0 -128
- package/public/vendor/vitest-docs/guide/learn/async.md +0 -147
- package/public/vendor/vitest-docs/guide/learn/debugging-tests.md +0 -210
- package/public/vendor/vitest-docs/guide/learn/matchers.md +0 -277
- package/public/vendor/vitest-docs/guide/learn/mock-functions.md +0 -277
- package/public/vendor/vitest-docs/guide/learn/setup-teardown.md +0 -240
- package/public/vendor/vitest-docs/guide/learn/snapshots.md +0 -166
- package/public/vendor/vitest-docs/guide/learn/testing-in-practice.md +0 -430
- package/public/vendor/vitest-docs/guide/learn/writing-tests-with-ai.md +0 -127
- package/public/vendor/vitest-docs/guide/learn/writing-tests.md +0 -231
- package/public/vendor/vitest-docs/guide/lifecycle.md +0 -379
- package/public/vendor/vitest-docs/guide/migration.md +0 -863
- package/public/vendor/vitest-docs/guide/mocking/classes.md +0 -158
- package/public/vendor/vitest-docs/guide/mocking/dates.md +0 -52
- package/public/vendor/vitest-docs/guide/mocking/file-system.md +0 -74
- package/public/vendor/vitest-docs/guide/mocking/functions.md +0 -61
- package/public/vendor/vitest-docs/guide/mocking/globals.md +0 -20
- package/public/vendor/vitest-docs/guide/mocking/modules.md +0 -414
- package/public/vendor/vitest-docs/guide/mocking/requests.md +0 -114
- package/public/vendor/vitest-docs/guide/mocking/timers.md +0 -48
- package/public/vendor/vitest-docs/guide/mocking.md +0 -239
- package/public/vendor/vitest-docs/guide/open-telemetry.md +0 -156
- package/public/vendor/vitest-docs/guide/parallelism.md +0 -82
- package/public/vendor/vitest-docs/guide/profiling-test-performance.md +0 -243
- package/public/vendor/vitest-docs/guide/projects.md +0 -291
- package/public/vendor/vitest-docs/guide/recipes.md +0 -59
- package/public/vendor/vitest-docs/guide/reporters.md +0 -723
- package/public/vendor/vitest-docs/guide/snapshot.md +0 -620
- package/public/vendor/vitest-docs/guide/test-annotations.md +0 -103
- package/public/vendor/vitest-docs/guide/test-context.md +0 -902
- package/public/vendor/vitest-docs/guide/test-tags.md +0 -314
- package/public/vendor/vitest-docs/guide/testing-types.md +0 -149
- package/public/vendor/vitest-docs/guide/ui.md +0 -160
- package/public/vendor/vitest-docs/guide/using-plugins.md +0 -5
- package/public/vendor/vitest-docs/manifest.json +0 -1691
- package/resources/index.js +0 -166
- package/resources/indexes.js +0 -77
- package/resources/manifest-schema.js +0 -46
- package/resources/paths.js +0 -20
- package/resources/patterns.js +0 -22
- package/resources/upstream-docs.js +0 -22
|
@@ -1,302 +0,0 @@
|
|
|
1
|
-
# TestCase
|
|
2
|
-
|
|
3
|
-
The `TestCase` class represents a single test. This class is only available in the main thread. Refer to the ["Runner API"](/api/advanced/runner#tasks) if you are working with runtime tasks.
|
|
4
|
-
|
|
5
|
-
The `TestCase` instance always has a `type` property with the value of `test`. You can use it to distinguish between different task types:
|
|
6
|
-
|
|
7
|
-
```ts
|
|
8
|
-
if (task.type === 'test') {
|
|
9
|
-
task // TestCase
|
|
10
|
-
}
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
## project
|
|
14
|
-
|
|
15
|
-
This references the [`TestProject`](/api/advanced/test-project) that the test belongs to.
|
|
16
|
-
|
|
17
|
-
## module
|
|
18
|
-
|
|
19
|
-
This is a direct reference to the [`TestModule`](/api/advanced/test-module) where the test is defined.
|
|
20
|
-
|
|
21
|
-
## name
|
|
22
|
-
|
|
23
|
-
This is a test name that was passed to the `test` function.
|
|
24
|
-
|
|
25
|
-
```ts
|
|
26
|
-
import { test } from 'vitest'
|
|
27
|
-
|
|
28
|
-
// [!code word:'the validation works correctly']
|
|
29
|
-
test('the validation works correctly', () => {
|
|
30
|
-
// ...
|
|
31
|
-
})
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
## fullName
|
|
35
|
-
|
|
36
|
-
The name of the test including all parent suites separated with `>` symbol. This test has a full name "the validation logic > the validation works correctly":
|
|
37
|
-
|
|
38
|
-
```ts
|
|
39
|
-
import { describe, test } from 'vitest'
|
|
40
|
-
|
|
41
|
-
// [!code word:'the validation works correctly']
|
|
42
|
-
// [!code word:'the validation logic']
|
|
43
|
-
describe('the validation logic', () => {
|
|
44
|
-
test('the validation works correctly', () => {
|
|
45
|
-
// ...
|
|
46
|
-
})
|
|
47
|
-
})
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
## id
|
|
51
|
-
|
|
52
|
-
This is test's unique identifier. This ID is deterministic and will be the same for the same test across multiple runs. The ID is based on the [project](/api/advanced/test-project) name, module ID and test order.
|
|
53
|
-
|
|
54
|
-
The ID looks like this:
|
|
55
|
-
|
|
56
|
-
```
|
|
57
|
-
1223128da3_0_0
|
|
58
|
-
^^^^^^^^^^ the file hash
|
|
59
|
-
^ suite index
|
|
60
|
-
^ test index
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
::: tip
|
|
64
|
-
You can generate file hash with `generateFileHash` function from `vitest/node` which is available since Vitest 3:
|
|
65
|
-
|
|
66
|
-
```ts
|
|
67
|
-
import { generateFileHash } from 'vitest/node'
|
|
68
|
-
|
|
69
|
-
const hash = generateFileHash(
|
|
70
|
-
'/file/path.js', // relative path
|
|
71
|
-
undefined, // the project name or `undefined` is not set
|
|
72
|
-
)
|
|
73
|
-
```
|
|
74
|
-
:::
|
|
75
|
-
|
|
76
|
-
::: danger
|
|
77
|
-
Don't try to parse the ID. It can have a minus at the start: `-1223128da3_0_0_0`.
|
|
78
|
-
:::
|
|
79
|
-
|
|
80
|
-
## location
|
|
81
|
-
|
|
82
|
-
The location in the module where the test was defined. Locations are collected only if [`includeTaskLocation`](/config/includetasklocation) is enabled in the config. Note that this option is automatically enabled if `--reporter=html`, `--ui` or `--browser` flags are used.
|
|
83
|
-
|
|
84
|
-
The location of this test will be equal to `{ line: 3, column: 1 }`:
|
|
85
|
-
|
|
86
|
-
```ts:line-numbers {3}
|
|
87
|
-
import { test } from 'vitest'
|
|
88
|
-
|
|
89
|
-
test('the validation works correctly', () => {
|
|
90
|
-
// ...
|
|
91
|
-
})
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
## parent
|
|
95
|
-
|
|
96
|
-
Parent [suite](/api/advanced/test-suite). If the test was called directly inside the [module](/api/advanced/test-module), the parent will be the module itself.
|
|
97
|
-
|
|
98
|
-
## options
|
|
99
|
-
|
|
100
|
-
```ts
|
|
101
|
-
interface TaskOptions {
|
|
102
|
-
readonly each: boolean | undefined
|
|
103
|
-
readonly fails: boolean | undefined
|
|
104
|
-
readonly concurrent: boolean | undefined
|
|
105
|
-
readonly shuffle: boolean | undefined
|
|
106
|
-
readonly retry: number | undefined
|
|
107
|
-
readonly repeats: number | undefined
|
|
108
|
-
readonly tags: string[] | undefined
|
|
109
|
-
readonly timeout: number | undefined
|
|
110
|
-
readonly mode: 'run' | 'only' | 'skip' | 'todo'
|
|
111
|
-
}
|
|
112
|
-
```
|
|
113
|
-
|
|
114
|
-
The options that test was collected with.
|
|
115
|
-
|
|
116
|
-
## tags <Version>4.1.0</Version> {#tags}
|
|
117
|
-
|
|
118
|
-
[Tags](/guide/test-tags) that were implicitly or explicitly assigned to the test.
|
|
119
|
-
|
|
120
|
-
## ok
|
|
121
|
-
|
|
122
|
-
```ts
|
|
123
|
-
function ok(): boolean
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
Checks if the test did not fail the suite. If the test is not finished yet or was skipped, it will return `true`.
|
|
127
|
-
|
|
128
|
-
## meta
|
|
129
|
-
|
|
130
|
-
```ts
|
|
131
|
-
function meta(): TaskMeta
|
|
132
|
-
```
|
|
133
|
-
|
|
134
|
-
Custom [metadata](/api/advanced/metadata) that was attached to the test during its execution. The meta can be attached by assigning a property to the `ctx.task.meta` object during a test run:
|
|
135
|
-
|
|
136
|
-
```ts {3,6}
|
|
137
|
-
import { test } from 'vitest'
|
|
138
|
-
|
|
139
|
-
test('the validation works correctly', ({ task }) => {
|
|
140
|
-
// ...
|
|
141
|
-
|
|
142
|
-
task.meta.decorated = false
|
|
143
|
-
})
|
|
144
|
-
```
|
|
145
|
-
|
|
146
|
-
If the test did not finish running yet, the meta will be an empty object, unless it has static meta:
|
|
147
|
-
|
|
148
|
-
```ts
|
|
149
|
-
test('the validation works correctly', { meta: { decorated: true } })
|
|
150
|
-
```
|
|
151
|
-
|
|
152
|
-
Since Vitest 4.1, Vitest inherits [`meta`](/api/advanced/test-suite#meta) property defined on the [suite](/api/advanced/test-suite).
|
|
153
|
-
|
|
154
|
-
## result
|
|
155
|
-
|
|
156
|
-
```ts
|
|
157
|
-
function result(): TestResult
|
|
158
|
-
```
|
|
159
|
-
|
|
160
|
-
Test results. If test is not finished yet or was just collected, it will be equal to `TestResultPending`:
|
|
161
|
-
|
|
162
|
-
```ts
|
|
163
|
-
export interface TestResultPending {
|
|
164
|
-
/**
|
|
165
|
-
* The test was collected, but didn't finish running yet.
|
|
166
|
-
*/
|
|
167
|
-
readonly state: 'pending'
|
|
168
|
-
/**
|
|
169
|
-
* Pending tests have no errors.
|
|
170
|
-
*/
|
|
171
|
-
readonly errors: undefined
|
|
172
|
-
}
|
|
173
|
-
```
|
|
174
|
-
|
|
175
|
-
If the test was skipped, the return value will be `TestResultSkipped`:
|
|
176
|
-
|
|
177
|
-
```ts
|
|
178
|
-
interface TestResultSkipped {
|
|
179
|
-
/**
|
|
180
|
-
* The test was skipped with `skip` or `todo` flag.
|
|
181
|
-
* You can see which one was used in the `options.mode` option.
|
|
182
|
-
*/
|
|
183
|
-
readonly state: 'skipped'
|
|
184
|
-
/**
|
|
185
|
-
* Skipped tests have no errors.
|
|
186
|
-
*/
|
|
187
|
-
readonly errors: undefined
|
|
188
|
-
/**
|
|
189
|
-
* A custom note passed down to `ctx.skip(note)`.
|
|
190
|
-
*/
|
|
191
|
-
readonly note: string | undefined
|
|
192
|
-
}
|
|
193
|
-
```
|
|
194
|
-
|
|
195
|
-
::: tip
|
|
196
|
-
If the test was skipped because another test has `only` flag, the `options.mode` will be equal to `skip`.
|
|
197
|
-
:::
|
|
198
|
-
|
|
199
|
-
If the test failed, the return value will be `TestResultFailed`:
|
|
200
|
-
|
|
201
|
-
```ts
|
|
202
|
-
interface TestResultFailed {
|
|
203
|
-
/**
|
|
204
|
-
* The test failed to execute.
|
|
205
|
-
*/
|
|
206
|
-
readonly state: 'failed'
|
|
207
|
-
/**
|
|
208
|
-
* Errors that were thrown during the test execution.
|
|
209
|
-
*/
|
|
210
|
-
readonly errors: ReadonlyArray<TestError>
|
|
211
|
-
}
|
|
212
|
-
```
|
|
213
|
-
|
|
214
|
-
If the test passed, the return value will be `TestResultPassed`:
|
|
215
|
-
|
|
216
|
-
```ts
|
|
217
|
-
interface TestResultPassed {
|
|
218
|
-
/**
|
|
219
|
-
* The test passed successfully.
|
|
220
|
-
*/
|
|
221
|
-
readonly state: 'passed'
|
|
222
|
-
/**
|
|
223
|
-
* Errors that were thrown during the test execution.
|
|
224
|
-
*/
|
|
225
|
-
readonly errors: ReadonlyArray<TestError> | undefined
|
|
226
|
-
}
|
|
227
|
-
```
|
|
228
|
-
|
|
229
|
-
::: warning
|
|
230
|
-
Note that the test with `passed` state can still have errors attached - this can happen if `retry` was triggered at least once.
|
|
231
|
-
:::
|
|
232
|
-
|
|
233
|
-
## diagnostic
|
|
234
|
-
|
|
235
|
-
```ts
|
|
236
|
-
function diagnostic(): TestDiagnostic | undefined
|
|
237
|
-
```
|
|
238
|
-
|
|
239
|
-
Useful information about the test like duration, memory usage, etc:
|
|
240
|
-
|
|
241
|
-
```ts
|
|
242
|
-
interface TestDiagnostic {
|
|
243
|
-
/**
|
|
244
|
-
* If the duration of the test is above `slowTestThreshold`.
|
|
245
|
-
*/
|
|
246
|
-
readonly slow: boolean
|
|
247
|
-
/**
|
|
248
|
-
* The amount of memory used by the test in bytes.
|
|
249
|
-
* This value is only available if the test was executed with `logHeapUsage` flag.
|
|
250
|
-
*/
|
|
251
|
-
readonly heap: number | undefined
|
|
252
|
-
/**
|
|
253
|
-
* The time it takes to execute the test in ms.
|
|
254
|
-
*/
|
|
255
|
-
readonly duration: number
|
|
256
|
-
/**
|
|
257
|
-
* The time in ms when the test started.
|
|
258
|
-
*/
|
|
259
|
-
readonly startTime: number
|
|
260
|
-
/**
|
|
261
|
-
* The amount of times the test was retried.
|
|
262
|
-
*/
|
|
263
|
-
readonly retryCount: number
|
|
264
|
-
/**
|
|
265
|
-
* The amount of times the test was repeated as configured by `repeats` option.
|
|
266
|
-
* This value can be lower if the test failed during the repeat and no `retry` is configured.
|
|
267
|
-
*/
|
|
268
|
-
readonly repeatCount: number
|
|
269
|
-
/**
|
|
270
|
-
* If test passed on a second retry.
|
|
271
|
-
*/
|
|
272
|
-
readonly flaky: boolean
|
|
273
|
-
}
|
|
274
|
-
```
|
|
275
|
-
|
|
276
|
-
::: info
|
|
277
|
-
`diagnostic()` will return `undefined` if the test was not scheduled to run yet.
|
|
278
|
-
:::
|
|
279
|
-
|
|
280
|
-
## annotations
|
|
281
|
-
|
|
282
|
-
```ts
|
|
283
|
-
function annotations(): ReadonlyArray<TestAnnotation>
|
|
284
|
-
```
|
|
285
|
-
|
|
286
|
-
[Test annotations](/guide/test-annotations) added via the [`task.annotate`](/guide/test-context#annotate) API during the test execution.
|
|
287
|
-
|
|
288
|
-
## artifacts <Version type="experimental">4.0.11</Version> <Experimental /> {#artifacts}
|
|
289
|
-
|
|
290
|
-
```ts
|
|
291
|
-
function artifacts(): ReadonlyArray<TestArtifact>
|
|
292
|
-
```
|
|
293
|
-
|
|
294
|
-
[Test artifacts](/api/advanced/artifacts) recorded via the `recordArtifact` API during the test execution.
|
|
295
|
-
|
|
296
|
-
## toTestSpecification <Version>4.1.0</Version> {#totestspecification}
|
|
297
|
-
|
|
298
|
-
```ts
|
|
299
|
-
function toTestSpecification(): TestSpecification
|
|
300
|
-
```
|
|
301
|
-
|
|
302
|
-
Returns a new [test specification](/api/advanced/test-specification) that can be used to filter or run this specific test case.
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
# TestCollection
|
|
2
|
-
|
|
3
|
-
`TestCollection` represents a collection of top-level [suites](/api/advanced/test-suite) and [tests](/api/advanced/test-case) in a suite or a module. It also provides useful methods to iterate over itself.
|
|
4
|
-
|
|
5
|
-
::: info
|
|
6
|
-
Most methods return an iterator instead of an array for better performance in case you don't need every item in the collection. If you prefer working with array, you can spread the iterator: `[...children.allSuites()]`.
|
|
7
|
-
|
|
8
|
-
Also note that the collection itself is an iterator:
|
|
9
|
-
|
|
10
|
-
```ts
|
|
11
|
-
for (const child of module.children) {
|
|
12
|
-
console.log(child.type, child.name)
|
|
13
|
-
}
|
|
14
|
-
```
|
|
15
|
-
:::
|
|
16
|
-
|
|
17
|
-
## size
|
|
18
|
-
|
|
19
|
-
The number of tests and suites in the collection.
|
|
20
|
-
|
|
21
|
-
::: warning
|
|
22
|
-
This number includes only tests and suites at the top-level, it doesn't include nested suites and tests.
|
|
23
|
-
:::
|
|
24
|
-
|
|
25
|
-
## at
|
|
26
|
-
|
|
27
|
-
```ts
|
|
28
|
-
function at(index: number): TestCase | TestSuite | undefined
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
Returns the test or suite at a specific index. This method accepts negative indexes.
|
|
32
|
-
|
|
33
|
-
## array
|
|
34
|
-
|
|
35
|
-
```ts
|
|
36
|
-
function array(): (TestCase | TestSuite)[]
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
The same collection but as an array. This is useful if you want to use `Array` methods like `map` and `filter` that are not supported by the `TaskCollection` implementation.
|
|
40
|
-
|
|
41
|
-
## allSuites
|
|
42
|
-
|
|
43
|
-
```ts
|
|
44
|
-
function allSuites(): Generator<TestSuite, undefined, void>
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
Filters all suites that are part of this collection and its children.
|
|
48
|
-
|
|
49
|
-
```ts
|
|
50
|
-
for (const suite of module.children.allSuites()) {
|
|
51
|
-
if (suite.errors().length) {
|
|
52
|
-
console.log('failed to collect', suite.errors())
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
## allTests
|
|
58
|
-
|
|
59
|
-
```ts
|
|
60
|
-
function allTests(state?: TestState): Generator<TestCase, undefined, void>
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
Filters all tests that are part of this collection and its children.
|
|
64
|
-
|
|
65
|
-
```ts
|
|
66
|
-
for (const test of module.children.allTests()) {
|
|
67
|
-
if (test.result().state === 'pending') {
|
|
68
|
-
console.log('test', test.fullName, 'did not finish')
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
You can pass down a `state` value to filter tests by the state.
|
|
74
|
-
|
|
75
|
-
## tests
|
|
76
|
-
|
|
77
|
-
```ts
|
|
78
|
-
function tests(state?: TestState): Generator<TestCase, undefined, void>
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
Filters only the tests that are part of this collection. You can pass down a `state` value to filter tests by the state.
|
|
82
|
-
|
|
83
|
-
## suites
|
|
84
|
-
|
|
85
|
-
```ts
|
|
86
|
-
function suites(): Generator<TestSuite, undefined, void>
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
Filters only the suites that are part of this collection.
|
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
# TestModule
|
|
2
|
-
|
|
3
|
-
The `TestModule` class represents a single module in a single project. This class is only available in the main thread. Refer to the ["Runner API"](/api/advanced/runner#tasks) if you are working with runtime tasks.
|
|
4
|
-
|
|
5
|
-
The `TestModule` instance always has a `type` property with the value of `module`. You can use it to distinguish between different task types:
|
|
6
|
-
|
|
7
|
-
```ts
|
|
8
|
-
if (task.type === 'module') {
|
|
9
|
-
task // TestModule
|
|
10
|
-
}
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
::: warning Extending Suite Methods
|
|
14
|
-
The `TestModule` class inherits all methods and properties from the [`TestSuite`](/api/advanced/test-suite). This guide will only list methods and properties unique to the `TestModule`.
|
|
15
|
-
:::
|
|
16
|
-
|
|
17
|
-
## moduleId
|
|
18
|
-
|
|
19
|
-
This is usually an absolute unix file path (even on Windows). It can be a virtual id if the file is not on the disk. This value corresponds to Vite's `ModuleGraph` id.
|
|
20
|
-
|
|
21
|
-
```ts
|
|
22
|
-
'C:/Users/Documents/project/example.test.ts' // ✅
|
|
23
|
-
'/Users/mac/project/example.test.ts' // ✅
|
|
24
|
-
'C:\\Users\\Documents\\project\\example.test.ts' // ❌
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
## relativeModuleId
|
|
28
|
-
|
|
29
|
-
Module id relative to the project. This is the same as `task.name` in the deprecated API.
|
|
30
|
-
|
|
31
|
-
```ts
|
|
32
|
-
'project/example.test.ts' // ✅
|
|
33
|
-
'example.test.ts' // ✅
|
|
34
|
-
'project\\example.test.ts' // ❌
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
## state
|
|
38
|
-
|
|
39
|
-
```ts
|
|
40
|
-
function state(): TestModuleState
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
Works the same way as [`testSuite.state()`](/api/advanced/test-suite#state), but can also return `queued` if module wasn't executed yet.
|
|
44
|
-
|
|
45
|
-
## meta <Version>3.1.0</Version> {#meta}
|
|
46
|
-
|
|
47
|
-
```ts
|
|
48
|
-
function meta(): TaskMeta
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
Custom [metadata](/api/advanced/metadata) that was attached to the module during its execution or collection. The meta can be attached by assigning a property to the `task.meta` object during a test run:
|
|
52
|
-
|
|
53
|
-
```ts {5,10}
|
|
54
|
-
import { test } from 'vitest'
|
|
55
|
-
|
|
56
|
-
describe('the validation works correctly', (task) => {
|
|
57
|
-
// assign "decorated" during collection
|
|
58
|
-
task.file.meta.decorated = false
|
|
59
|
-
|
|
60
|
-
test('some test', ({ task }) => {
|
|
61
|
-
// assign "decorated" during test run, it will be available
|
|
62
|
-
// only in onTestCaseReady hook
|
|
63
|
-
task.file.meta.decorated = false
|
|
64
|
-
})
|
|
65
|
-
})
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
:::tip
|
|
69
|
-
If metadata was attached during collection (outside of the `test` function), then it will be available in [`onTestModuleCollected`](./reporters#ontestmodulecollected) hook in the custom reporter.
|
|
70
|
-
:::
|
|
71
|
-
|
|
72
|
-
## diagnostic
|
|
73
|
-
|
|
74
|
-
```ts
|
|
75
|
-
function diagnostic(): ModuleDiagnostic
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
Useful information about the module like duration, memory usage, etc. If the module was not executed yet, all diagnostic values will return `0`.
|
|
79
|
-
|
|
80
|
-
```ts
|
|
81
|
-
interface ModuleDiagnostic {
|
|
82
|
-
/**
|
|
83
|
-
* The time it takes to import and initiate an environment.
|
|
84
|
-
*/
|
|
85
|
-
readonly environmentSetupDuration: number
|
|
86
|
-
/**
|
|
87
|
-
* The time it takes Vitest to setup test harness (runner, mocks, etc.).
|
|
88
|
-
*/
|
|
89
|
-
readonly prepareDuration: number
|
|
90
|
-
/**
|
|
91
|
-
* The time it takes to import the test module.
|
|
92
|
-
* This includes importing everything in the module and executing suite callbacks.
|
|
93
|
-
*/
|
|
94
|
-
readonly collectDuration: number
|
|
95
|
-
/**
|
|
96
|
-
* The time it takes to import the setup module.
|
|
97
|
-
*/
|
|
98
|
-
readonly setupDuration: number
|
|
99
|
-
/**
|
|
100
|
-
* Accumulated duration of all tests and hooks in the module.
|
|
101
|
-
*/
|
|
102
|
-
readonly duration: number
|
|
103
|
-
/**
|
|
104
|
-
* The amount of memory used by the module in bytes.
|
|
105
|
-
* This value is only available if the test was executed with `logHeapUsage` flag.
|
|
106
|
-
*/
|
|
107
|
-
readonly heap: number | undefined
|
|
108
|
-
/**
|
|
109
|
-
* The time spent importing every non-externalized dependency that Vitest has processed.
|
|
110
|
-
*/
|
|
111
|
-
readonly importDurations: Record<string, ImportDuration>
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/** The time spent importing & executing a non-externalized file. */
|
|
115
|
-
interface ImportDuration {
|
|
116
|
-
/** The time spent importing & executing the file itself, not counting all non-externalized imports that the file does. */
|
|
117
|
-
selfTime: number
|
|
118
|
-
|
|
119
|
-
/** The time spent importing & executing the file and all its imports. */
|
|
120
|
-
totalTime: number
|
|
121
|
-
}
|
|
122
|
-
```
|
|
123
|
-
|
|
124
|
-
## viteEnvironment <Version>4.1.0</Version> {#viteenvironment}
|
|
125
|
-
|
|
126
|
-
This is a Vite's [`DevEnvironment`](https://vite.dev/guide/api-environment) that transforms all files inside of the test module.
|
|
127
|
-
|
|
128
|
-
::: details History
|
|
129
|
-
- `v4.0.15`: added as experimental
|
|
130
|
-
:::
|
|
131
|
-
|
|
132
|
-
## toTestSpecification <Version>4.1.0</Version> {#totestspecification}
|
|
133
|
-
|
|
134
|
-
```ts
|
|
135
|
-
function toTestSpecification(testCases?: TestCase[]): TestSpecification
|
|
136
|
-
```
|
|
137
|
-
|
|
138
|
-
Returns a new [test specification](/api/advanced/test-specification) that can be used to filter or run this specific test module.
|
|
139
|
-
|
|
140
|
-
It accepts an optional array of test cases that should be filtered.
|