@voidzero-dev/vite-plus-test 0.1.9 → 0.1.10
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/LICENSE.md +181 -1
- package/dist/@vitest/browser/client/.vite/manifest.json +6 -6
- package/dist/@vitest/browser/client/__vitest__/assets/index-Da0hb3oU.css +1 -0
- package/dist/@vitest/browser/client/__vitest__/assets/index-Di71CKDo.js +63 -0
- package/dist/@vitest/browser/client/__vitest__/favicon.ico +0 -0
- package/dist/@vitest/browser/client/__vitest__/favicon.svg +49 -4
- package/dist/@vitest/browser/client/__vitest__/index.html +2 -2
- package/dist/@vitest/browser/client/__vitest_browser__/{orchestrator-S_3e_uzt.js → orchestrator-CXs6qrFe.js} +70 -28
- package/dist/@vitest/browser/client/__vitest_browser__/{tester-k74mgIRa.js → tester-K5NNxh1O.js} +167 -58
- package/dist/@vitest/browser/client/__vitest_browser__/{utils-uxqdqUz8.js → utils-C2ISqq1C.js} +2 -2
- package/dist/@vitest/browser/client/favicon.svg +49 -4
- package/dist/@vitest/browser/client/orchestrator.html +2 -2
- package/dist/@vitest/browser/client/tester/tester.html +2 -2
- package/dist/@vitest/browser/client.js +20 -13
- package/dist/@vitest/browser/context.d.ts +160 -10
- package/dist/@vitest/browser/context.js +108 -22
- package/dist/@vitest/browser/expect-element.js +23 -28
- package/dist/@vitest/browser/index-5Pe7X7sp.js +7 -0
- package/dist/@vitest/browser/index.d.ts +20 -2
- package/dist/@vitest/browser/index.js +5706 -159
- package/dist/@vitest/browser/locators.d.ts +14 -3
- package/dist/@vitest/browser/locators.js +1 -1
- package/dist/@vitest/browser-playwright/index.d.ts +22 -5
- package/dist/@vitest/browser-playwright/index.js +169 -61
- package/dist/@vitest/browser-preview/index.d.ts +14 -1
- package/dist/@vitest/browser-preview/locators.js +31 -18
- package/dist/@vitest/browser-webdriverio/index.d.ts +17 -3
- package/dist/@vitest/browser-webdriverio/index.js +22 -2
- package/dist/@vitest/browser-webdriverio/locators.js +84 -7
- package/dist/@vitest/expect/index.d.ts +172 -54
- package/dist/@vitest/expect/index.js +124 -67
- package/dist/@vitest/mocker/auto-register.js +1 -0
- package/dist/@vitest/mocker/automock.d.ts +1 -0
- package/dist/@vitest/mocker/automock.js +5 -0
- package/dist/@vitest/mocker/browser.d.ts +4 -4
- package/dist/@vitest/mocker/browser.js +1 -0
- package/dist/@vitest/mocker/chunk-automock.js +182 -14
- package/dist/@vitest/mocker/chunk-helpers.js +44 -0
- package/dist/@vitest/mocker/chunk-hoistMocks.js +659 -0
- package/dist/@vitest/mocker/chunk-mocker.js +41 -30
- package/dist/@vitest/mocker/chunk-registry.js +21 -7
- package/dist/@vitest/mocker/chunk-utils.js +18 -7
- package/dist/@vitest/mocker/hoistMocks.d-w2ILr1dG.d.ts +739 -0
- package/dist/@vitest/mocker/{index.d-C-sLYZi-.d.ts → index.d-B41z0AuW.d.ts} +1 -1
- package/dist/@vitest/mocker/index.d.ts +2 -2
- package/dist/@vitest/mocker/index.js +18 -3
- package/dist/@vitest/mocker/{mocker.d-TnKRhz7N.d.ts → mocker.d-QEntlm6J.d.ts} +10 -5
- package/dist/@vitest/mocker/node.d.ts +5 -734
- package/dist/@vitest/mocker/node.js +29 -587
- package/dist/@vitest/mocker/redirect.js +4 -4
- package/dist/@vitest/mocker/register.d.ts +3 -3
- package/dist/@vitest/mocker/register.js +1 -0
- package/dist/@vitest/mocker/transforms.d.ts +6 -0
- package/dist/@vitest/mocker/transforms.js +8 -0
- package/dist/@vitest/mocker/{types.d-B8CCKmHt.d.ts → types.d-BjI5eAwu.d.ts} +23 -7
- package/dist/@vitest/pretty-format/index.d.ts +11 -1
- package/dist/@vitest/pretty-format/index.js +33 -4
- package/dist/@vitest/runner/chunk-tasks.js +305 -37
- package/dist/@vitest/runner/index.d.ts +5 -6
- package/dist/@vitest/runner/index.js +1146 -455
- package/dist/@vitest/runner/{tasks.d-C7UxawJ9.d.ts → tasks.d-D2GKpdwQ.d.ts} +726 -55
- package/dist/@vitest/runner/types.d.ts +2 -182
- package/dist/@vitest/runner/utils.d.ts +16 -8
- package/dist/@vitest/runner/utils.js +1 -1
- package/dist/@vitest/snapshot/{environment.d-DHdQ1Csl.d.ts → environment.d-DOJxxZV9.d.ts} +2 -7
- package/dist/@vitest/snapshot/environment.d.ts +2 -1
- package/dist/@vitest/snapshot/environment.js +1 -1
- package/dist/@vitest/snapshot/index.d.ts +4 -3
- package/dist/@vitest/snapshot/index.js +21 -550
- package/dist/@vitest/snapshot/manager.d.ts +3 -2
- package/dist/@vitest/snapshot/manager.js +1 -1
- package/dist/@vitest/snapshot/{rawSnapshot.d-lFsMJFUd.d.ts → rawSnapshot.d-U2kJUxDr.d.ts} +1 -1
- package/dist/@vitest/spy/index.d.ts +34 -4
- package/dist/@vitest/spy/index.js +69 -19
- package/dist/@vitest/utils/diff.js +11 -9
- package/dist/@vitest/utils/display.d.ts +2 -1
- package/dist/@vitest/utils/display.js +38 -5
- package/dist/@vitest/utils/error.d.ts +2 -1
- package/dist/@vitest/utils/error.js +1 -2
- package/dist/@vitest/utils/helpers.d.ts +4 -1
- package/dist/@vitest/utils/helpers.js +43 -1
- package/dist/@vitest/utils/resolver.js +1 -2
- package/dist/@vitest/utils/serialize.js +6 -6
- package/dist/@vitest/utils/source-map/node.d.ts +6 -0
- package/dist/@vitest/utils/source-map/node.js +23 -0
- package/dist/@vitest/utils/source-map.js +15 -5
- package/dist/browser.d.ts +3 -2
- package/dist/browser.js +2 -2
- package/dist/chunks/acorn.B2iPLyUM.js +5958 -0
- package/dist/chunks/{base.CJ0Y4ePK.js → base.DM0-RqVb.js} +54 -16
- package/dist/chunks/{benchmark.B3N2zMcH.js → benchmark.D0SlKNbZ.js} +1 -1
- package/dist/chunks/{browser.d.ChKACdzH.d.ts → browser.d.X3SXoOCV.d.ts} +4 -1
- package/dist/chunks/{cac.DVeoLl0M.js → cac.CWGDZnXT.js} +979 -20
- package/dist/chunks/{cli-api.B7PN_QUv.js → cli-api.DuT9iuvY.js} +8764 -7898
- package/dist/chunks/{config.d.Cy95HiCx.d.ts → config.d.EJLVE3es.d.ts} +30 -15
- package/dist/chunks/{console.Cf-YriPC.js → console.3WNpx0tS.js} +3 -2
- package/dist/chunks/{constants.D_Q9UYh-.js → constants.CPYnjOGj.js} +4 -2
- package/dist/chunks/coverage.Bri33R1t.js +1050 -0
- package/dist/chunks/{creator.DAmOKTvJ.js → creator.DgVhQm5q.js} +35 -4
- package/dist/chunks/{defaults.BOqNVLsY.js → defaults.CdU2lD-q.js} +4 -3
- package/dist/chunks/{global.d.B15mdLcR.d.ts → global.d.x-ILCfAE.d.ts} +1 -2
- package/dist/chunks/{globals.DOayXfHP.js → globals.BXNGLnTL.js} +11 -10
- package/dist/chunks/{coverage.AVPTjMgw.js → index.BCY_7LL2.js} +5 -959
- package/dist/chunks/{index.C5r1PdPD.js → index.CEzQDJGb.js} +1 -1
- package/dist/chunks/{index.D3XRDfWc.js → index.CMESou6r.js} +26 -1
- package/dist/chunks/{index.6Qv1eEA6.js → index.DGNSnENe.js} +95 -9
- package/dist/chunks/{index.M8mOzt4Y.js → index.DXMFO5MJ.js} +3279 -2914
- package/dist/chunks/{index.Z5E_ObnR.js → index.DlDSLQD3.js} +7 -3
- package/dist/chunks/{index.CyBMJtT7.js → index.EY6TCHpo.js} +10 -8
- package/dist/chunks/{index.D4KonVSU.js → index.og1WyBLx.js} +18 -3
- package/dist/chunks/{init-forks._y3TW739.js → init-forks.DeArv0jT.js} +1 -1
- package/dist/chunks/{init-threads.DBO2kn-p.js → init-threads.-2OUl4Nn.js} +1 -1
- package/dist/chunks/{init.B6MLFIaN.js → init.DICorXCo.js} +52 -13
- package/dist/chunks/native.DPzPHdi5.js +148 -0
- package/dist/chunks/nativeModuleMocker.DndvSdL6.js +206 -0
- package/dist/chunks/nativeModuleRunner.BIakptoF.js +36 -0
- package/dist/chunks/{node.Ce0vMQM7.js → node.COQbm6gK.js} +1 -1
- package/dist/chunks/{plugin.d.CtqpEehP.d.ts → plugin.d.BuW-flqo.d.ts} +1 -1
- package/dist/chunks/{reporters.d.CWXNI2jG.d.ts → reporters.d.DVUYHHhe.d.ts} +328 -79
- package/dist/chunks/rpc.MzXet3jl.js +144 -0
- package/dist/chunks/{rpc.d.RH3apGEf.d.ts → rpc.d.BFMWpdph.d.ts} +10 -2
- package/dist/chunks/{setup-common.Cm-kSBVi.js → setup-common.B41N_kPE.js} +3 -3
- package/dist/chunks/{startModuleRunner.DEj0jb3e.js → startVitestModuleRunner.C3ZR-4J3.js} +265 -405
- package/dist/chunks/{suite.d.BJWk38HB.d.ts → suite.d.udJtyAgw.d.ts} +1 -1
- package/dist/chunks/{vi.2VT5v0um.js → test.CTcmp4Su.js} +538 -181
- package/dist/chunks/{utils.DvEY5TfP.js → utils.BX5Fg8C4.js} +8 -1
- package/dist/chunks/{vm.D3epNOPZ.js → vm.Dh2rTtmP.js} +48 -8
- package/dist/chunks/{worker.d.Dyxm8DEL.d.ts → worker.d.B84sVRy0.d.ts} +2 -2
- package/dist/cli.js +6 -5
- package/dist/client/.vite/manifest.json +6 -6
- package/dist/client/__vitest__/assets/index-Da0hb3oU.css +1 -0
- package/dist/client/__vitest__/assets/index-Di71CKDo.js +63 -0
- package/dist/client/__vitest__/favicon.ico +0 -0
- package/dist/client/__vitest__/favicon.svg +49 -4
- package/dist/client/__vitest__/index.html +2 -2
- package/dist/client/__vitest_browser__/{orchestrator-S_3e_uzt.js → orchestrator-CXs6qrFe.js} +70 -28
- package/dist/client/__vitest_browser__/{tester-k74mgIRa.js → tester-K5NNxh1O.js} +167 -58
- package/dist/client/__vitest_browser__/{utils-uxqdqUz8.js → utils-C2ISqq1C.js} +2 -2
- package/dist/client/favicon.svg +49 -4
- package/dist/client/orchestrator.html +2 -2
- package/dist/client/tester/tester.html +2 -2
- package/dist/client.js +20 -13
- package/dist/config.cjs +3 -2
- package/dist/config.d.ts +13 -12
- package/dist/config.js +2 -2
- package/dist/context.js +108 -22
- package/dist/coverage.d.ts +12 -8
- package/dist/coverage.js +8 -5
- package/dist/environments.js +3 -1
- package/dist/expect-element.js +23 -23
- package/dist/index-5Pe7X7sp.js +7 -0
- package/dist/index.d.ts +66 -27
- package/dist/index.js +10 -9
- package/dist/locators.d.ts +14 -3
- package/dist/locators.js +1 -1
- package/dist/module-evaluator.d.ts +11 -1
- package/dist/module-evaluator.js +43 -26
- package/dist/node.d.ts +28 -14
- package/dist/node.js +42 -40
- package/dist/nodejs-worker-loader.js +41 -0
- package/dist/plugins/mocker-transforms.mjs +2 -0
- package/dist/plugins/utils-source-map-node.mjs +2 -0
- package/dist/reporters.d.ts +8 -8
- package/dist/reporters.js +7 -5
- package/dist/runners.d.ts +24 -5
- package/dist/runners.js +6 -6
- package/dist/runtime.d.ts +6 -0
- package/dist/runtime.js +35 -0
- package/dist/snapshot.js +4 -2
- package/dist/suite.d.ts +1 -1
- package/dist/suite.js +4 -2
- package/dist/vendor/blazediff_core.d.mts +1 -0
- package/dist/vendor/blazediff_core.mjs +117 -0
- package/dist/vendor/chai.mjs +4 -249
- package/dist/vendor/convert-source-map.d.mts +1 -0
- package/dist/vendor/convert-source-map.mjs +150 -0
- package/dist/vendor/expect-type.d.mts +14 -7
- package/dist/vendor/expect-type.mjs +5 -5
- package/dist/vendor/std-env.d.mts +131 -40
- package/dist/vendor/std-env.mjs +114 -117
- package/dist/worker.d.ts +6 -6
- package/dist/worker.js +27 -21
- package/dist/workers/forks.js +23 -17
- package/dist/workers/runVmTests.js +18 -16
- package/dist/workers/threads.js +23 -17
- package/dist/workers/vmForks.js +15 -12
- package/dist/workers/vmThreads.js +15 -12
- package/globals.d.ts +2 -0
- package/package.json +35 -26
- package/suppress-warnings.cjs +1 -0
- package/dist/@vitest/browser/client/__vitest__/assets/index-BUCFJtth.js +0 -57
- package/dist/@vitest/browser/client/__vitest__/assets/index-DlhE0rqZ.css +0 -1
- package/dist/@vitest/browser/index-D6m36C6U.js +0 -11
- package/dist/@vitest/utils/chunk-_commonjsHelpers.js +0 -5
- package/dist/@vitest/utils/highlight.d.ts +0 -9
- package/dist/@vitest/utils/highlight.js +0 -538
- package/dist/chunks/date.Bq6ZW5rf.js +0 -73
- package/dist/chunks/rpc.BoxB0q7B.js +0 -76
- package/dist/chunks/test.B8ej_ZHS.js +0 -254
- package/dist/client/__vitest__/assets/index-BUCFJtth.js +0 -57
- package/dist/client/__vitest__/assets/index-DlhE0rqZ.css +0 -1
- package/dist/index-D6m36C6U.js +0 -6
- package/dist/mocker.d.ts +0 -1
- package/dist/mocker.js +0 -1
- package/dist/module-runner.js +0 -17
|
@@ -1,17 +1,229 @@
|
|
|
1
1
|
import { TestError, Awaitable } from '../utils/index.js';
|
|
2
|
+
import { DiffOptions } from '../utils/diff.js';
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
/**
|
|
5
|
+
* This is a subset of Vitest config that's required for the runner to work.
|
|
6
|
+
*/
|
|
7
|
+
interface VitestRunnerConfig {
|
|
8
|
+
root: string;
|
|
9
|
+
setupFiles: string[];
|
|
10
|
+
name: string | undefined;
|
|
11
|
+
passWithNoTests: boolean;
|
|
12
|
+
testNamePattern: RegExp | undefined;
|
|
13
|
+
allowOnly: boolean;
|
|
14
|
+
sequence: {
|
|
15
|
+
shuffle?: boolean;
|
|
16
|
+
concurrent?: boolean;
|
|
17
|
+
seed: number;
|
|
18
|
+
hooks: SequenceHooks;
|
|
19
|
+
setupFiles: SequenceSetupFiles;
|
|
20
|
+
};
|
|
21
|
+
chaiConfig: {
|
|
22
|
+
truncateThreshold?: number;
|
|
23
|
+
} | undefined;
|
|
24
|
+
maxConcurrency: number;
|
|
25
|
+
testTimeout: number;
|
|
26
|
+
hookTimeout: number;
|
|
27
|
+
retry: SerializableRetry;
|
|
28
|
+
includeTaskLocation: boolean | undefined;
|
|
29
|
+
diffOptions?: DiffOptions;
|
|
30
|
+
tags: TestTagDefinition[];
|
|
31
|
+
tagsFilter: string[] | undefined;
|
|
32
|
+
strictTags: boolean;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Possible options to run a single file in a test.
|
|
36
|
+
*/
|
|
37
|
+
interface FileSpecification {
|
|
38
|
+
filepath: string;
|
|
39
|
+
fileTags?: string[];
|
|
40
|
+
testLocations: number[] | undefined;
|
|
41
|
+
testNamePattern: RegExp | undefined;
|
|
42
|
+
testTagsFilter: string[] | undefined;
|
|
43
|
+
testIds: string[] | undefined;
|
|
44
|
+
}
|
|
45
|
+
interface TestTagDefinition extends Omit<TestOptions, "tags" | "shuffle"> {
|
|
7
46
|
/**
|
|
8
|
-
*
|
|
47
|
+
* The name of the tag. This is what you use in the `tags` array in tests.
|
|
9
48
|
*/
|
|
10
|
-
|
|
49
|
+
name: keyof TestTags extends never ? string : TestTags[keyof TestTags];
|
|
11
50
|
/**
|
|
12
|
-
*
|
|
51
|
+
* A description for the tag. This will be shown in the CLI help and UI.
|
|
13
52
|
*/
|
|
14
|
-
|
|
53
|
+
description?: string;
|
|
54
|
+
/**
|
|
55
|
+
* Priority for merging options when multiple tags with the same options are applied to a test.
|
|
56
|
+
*
|
|
57
|
+
* Lower number means higher priority. E.g., priority 1 takes precedence over priority 3.
|
|
58
|
+
*/
|
|
59
|
+
priority?: number;
|
|
60
|
+
}
|
|
61
|
+
type VitestRunnerImportSource = "collect" | "setup";
|
|
62
|
+
interface VitestRunnerConstructor {
|
|
63
|
+
new (config: VitestRunnerConfig): VitestRunner;
|
|
64
|
+
}
|
|
65
|
+
type CancelReason = "keyboard-input" | "test-failure" | (string & Record<string, never>);
|
|
66
|
+
interface VitestRunner {
|
|
67
|
+
/**
|
|
68
|
+
* First thing that's getting called before actually collecting and running tests.
|
|
69
|
+
*/
|
|
70
|
+
onBeforeCollect?: (paths: string[]) => unknown;
|
|
71
|
+
/**
|
|
72
|
+
* Called after the file task was created but not collected yet.
|
|
73
|
+
*/
|
|
74
|
+
onCollectStart?: (file: File) => unknown;
|
|
75
|
+
/**
|
|
76
|
+
* Called after collecting tests and before "onBeforeRun".
|
|
77
|
+
*/
|
|
78
|
+
onCollected?: (files: File[]) => unknown;
|
|
79
|
+
/**
|
|
80
|
+
* Called when test runner should cancel next test runs.
|
|
81
|
+
* Runner should listen for this method and mark tests and suites as skipped in
|
|
82
|
+
* "onBeforeRunSuite" and "onBeforeRunTask" when called.
|
|
83
|
+
*/
|
|
84
|
+
cancel?: (reason: CancelReason) => unknown;
|
|
85
|
+
/**
|
|
86
|
+
* Called before running a single test. Doesn't have "result" yet.
|
|
87
|
+
*/
|
|
88
|
+
onBeforeRunTask?: (test: Test) => unknown;
|
|
89
|
+
/**
|
|
90
|
+
* Called before actually running the test function. Already has "result" with "state" and "startTime".
|
|
91
|
+
*/
|
|
92
|
+
onBeforeTryTask?: (test: Test, options: {
|
|
93
|
+
retry: number;
|
|
94
|
+
repeats: number;
|
|
95
|
+
}) => unknown;
|
|
96
|
+
/**
|
|
97
|
+
* When the task has finished running, but before cleanup hooks are called
|
|
98
|
+
*/
|
|
99
|
+
onTaskFinished?: (test: Test) => unknown;
|
|
100
|
+
/**
|
|
101
|
+
* Called after result and state are set.
|
|
102
|
+
*/
|
|
103
|
+
onAfterRunTask?: (test: Test) => unknown;
|
|
104
|
+
/**
|
|
105
|
+
* Called right after running the test function. Doesn't have new state yet. Will not be called, if the test function throws.
|
|
106
|
+
*/
|
|
107
|
+
onAfterTryTask?: (test: Test, options: {
|
|
108
|
+
retry: number;
|
|
109
|
+
repeats: number;
|
|
110
|
+
}) => unknown;
|
|
111
|
+
/**
|
|
112
|
+
* Called after the retry resolution happened. Unlike `onAfterTryTask`, the test now has a new state.
|
|
113
|
+
* All `after` hooks were also called by this point.
|
|
114
|
+
*/
|
|
115
|
+
onAfterRetryTask?: (test: Test, options: {
|
|
116
|
+
retry: number;
|
|
117
|
+
repeats: number;
|
|
118
|
+
}) => unknown;
|
|
119
|
+
/**
|
|
120
|
+
* Called before running a single suite. Doesn't have "result" yet.
|
|
121
|
+
*/
|
|
122
|
+
onBeforeRunSuite?: (suite: Suite) => unknown;
|
|
123
|
+
/**
|
|
124
|
+
* Called after running a single suite. Has state and result.
|
|
125
|
+
*/
|
|
126
|
+
onAfterRunSuite?: (suite: Suite) => unknown;
|
|
127
|
+
/**
|
|
128
|
+
* If defined, will be called instead of usual Vitest suite partition and handling.
|
|
129
|
+
* "before" and "after" hooks will not be ignored.
|
|
130
|
+
*/
|
|
131
|
+
runSuite?: (suite: Suite) => Promise<void>;
|
|
132
|
+
/**
|
|
133
|
+
* If defined, will be called instead of usual Vitest handling. Useful, if you have your custom test function.
|
|
134
|
+
* "before" and "after" hooks will not be ignored.
|
|
135
|
+
*/
|
|
136
|
+
runTask?: (test: Test) => Promise<void>;
|
|
137
|
+
/**
|
|
138
|
+
* Called, when a task is updated. The same as "onTaskUpdate" in a reporter, but this is running in the same thread as tests.
|
|
139
|
+
*/
|
|
140
|
+
onTaskUpdate?: (task: TaskResultPack[], events: TaskEventPack[]) => Promise<void>;
|
|
141
|
+
/**
|
|
142
|
+
* Called when annotation is added via the `context.annotate` method.
|
|
143
|
+
*/
|
|
144
|
+
onTestAnnotate?: (test: Test, annotation: TestAnnotation) => Promise<TestAnnotation>;
|
|
145
|
+
/**
|
|
146
|
+
* @experimental
|
|
147
|
+
*
|
|
148
|
+
* Called when artifacts are recorded on tests via the `recordArtifact` utility.
|
|
149
|
+
*/
|
|
150
|
+
onTestArtifactRecord?: <Artifact extends TestArtifact>(test: Test, artifact: Artifact) => Promise<Artifact>;
|
|
151
|
+
/**
|
|
152
|
+
* Called before running all tests in collected paths.
|
|
153
|
+
*/
|
|
154
|
+
onBeforeRunFiles?: (files: File[]) => unknown;
|
|
155
|
+
/**
|
|
156
|
+
* Called right after running all tests in collected paths.
|
|
157
|
+
*/
|
|
158
|
+
onAfterRunFiles?: (files: File[]) => unknown;
|
|
159
|
+
/**
|
|
160
|
+
* Called when new context for a test is defined. Useful if you want to add custom properties to the context.
|
|
161
|
+
* If you only want to define custom context, consider using "beforeAll" in "setupFiles" instead.
|
|
162
|
+
*
|
|
163
|
+
* @see https://vitest.dev/advanced/runner#your-task-function
|
|
164
|
+
*/
|
|
165
|
+
extendTaskContext?: (context: TestContext) => TestContext;
|
|
166
|
+
/**
|
|
167
|
+
* Called when test and setup files are imported. Can be called in two situations: when collecting tests and when importing setup files.
|
|
168
|
+
*/
|
|
169
|
+
importFile: (filepath: string, source: VitestRunnerImportSource) => unknown;
|
|
170
|
+
/**
|
|
171
|
+
* Function that is called when the runner attempts to get the value when `test.extend` is used with `{ injected: true }`
|
|
172
|
+
*/
|
|
173
|
+
injectValue?: (key: string) => unknown;
|
|
174
|
+
/**
|
|
175
|
+
* Gets the time spent importing each individual non-externalized file that Vitest collected.
|
|
176
|
+
*/
|
|
177
|
+
getImportDurations?: () => Record<string, ImportDuration>;
|
|
178
|
+
/**
|
|
179
|
+
* Publicly available configuration.
|
|
180
|
+
*/
|
|
181
|
+
config: VitestRunnerConfig;
|
|
182
|
+
/**
|
|
183
|
+
* The name of the current pool. Can affect how stack trace is inferred on the server side.
|
|
184
|
+
*/
|
|
185
|
+
pool?: string;
|
|
186
|
+
/**
|
|
187
|
+
* The current Vite environment that processes the files on the server.
|
|
188
|
+
*/
|
|
189
|
+
viteEnvironment?: string;
|
|
190
|
+
onCleanupWorkerContext?: (cleanup: () => unknown) => void;
|
|
191
|
+
trace?<T>(name: string, cb: () => T): T;
|
|
192
|
+
trace?<T>(name: string, attributes: Record<string, any>, cb: () => T): T;
|
|
193
|
+
/** @private */
|
|
194
|
+
_currentTaskStartTime?: number;
|
|
195
|
+
/** @private */
|
|
196
|
+
_currentTaskTimeout?: number;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
interface TestFixtureItem extends FixtureOptions {
|
|
200
|
+
name: string;
|
|
201
|
+
value: unknown;
|
|
202
|
+
scope: "test" | "file" | "worker";
|
|
203
|
+
deps: Set<string>;
|
|
204
|
+
parent?: TestFixtureItem;
|
|
205
|
+
}
|
|
206
|
+
type UserFixtures = Record<string, unknown>;
|
|
207
|
+
type FixtureRegistrations = Map<string, TestFixtureItem>;
|
|
208
|
+
declare class TestFixtures {
|
|
209
|
+
private _suiteContexts;
|
|
210
|
+
private _overrides;
|
|
211
|
+
private _registrations;
|
|
212
|
+
private static _definitions;
|
|
213
|
+
private static _builtinFixtures;
|
|
214
|
+
private static _fixtureOptionKeys;
|
|
215
|
+
private static _fixtureScopes;
|
|
216
|
+
private static _workerContextSuite;
|
|
217
|
+
static clearDefinitions(): void;
|
|
218
|
+
static getWorkerContexts(): Record<string, any>[];
|
|
219
|
+
static getFileContexts(file: File): Record<string, any>[];
|
|
220
|
+
constructor(registrations?: FixtureRegistrations);
|
|
221
|
+
extend(runner: VitestRunner, userFixtures: UserFixtures): TestFixtures;
|
|
222
|
+
get(suite: Suite): FixtureRegistrations;
|
|
223
|
+
override(runner: VitestRunner, userFixtures: UserFixtures): void;
|
|
224
|
+
getFileContext(file: File): Record<string, any>;
|
|
225
|
+
getWorkerContext(): Record<string, any>;
|
|
226
|
+
private parseUserFixtures;
|
|
15
227
|
}
|
|
16
228
|
|
|
17
229
|
/**
|
|
@@ -31,7 +243,7 @@ interface FixtureItem extends FixtureOptions {
|
|
|
31
243
|
* });
|
|
32
244
|
* ```
|
|
33
245
|
*/
|
|
34
|
-
declare function beforeAll(fn: BeforeAllListener
|
|
246
|
+
declare function beforeAll<ExtraContext = object>(this: unknown, fn: BeforeAllListener<ExtraContext>, timeout?: number): void;
|
|
35
247
|
/**
|
|
36
248
|
* Registers a callback function to be executed once after all tests within the current suite have completed.
|
|
37
249
|
* This hook is useful for scenarios where you need to perform cleanup operations after all tests in a suite have run, such as closing database connections or cleaning up temporary files.
|
|
@@ -49,7 +261,7 @@ declare function beforeAll(fn: BeforeAllListener, timeout?: number): void;
|
|
|
49
261
|
* });
|
|
50
262
|
* ```
|
|
51
263
|
*/
|
|
52
|
-
declare function afterAll(fn: AfterAllListener
|
|
264
|
+
declare function afterAll<ExtraContext = object>(this: unknown, fn: AfterAllListener<ExtraContext>, timeout?: number): void;
|
|
53
265
|
/**
|
|
54
266
|
* Registers a callback function to be executed before each test within the current suite.
|
|
55
267
|
* This hook is useful for scenarios where you need to reset or reinitialize the test environment before each test runs, such as resetting database states, clearing caches, or reinitializing variables.
|
|
@@ -129,6 +341,61 @@ declare const onTestFailed: TaskHook<OnTestFailedHandler>;
|
|
|
129
341
|
* ```
|
|
130
342
|
*/
|
|
131
343
|
declare const onTestFinished: TaskHook<OnTestFinishedHandler>;
|
|
344
|
+
/**
|
|
345
|
+
* Registers a callback function that wraps around all tests within the current suite.
|
|
346
|
+
* The callback receives a `runSuite` function that must be called to run the suite's tests.
|
|
347
|
+
* This hook is useful for scenarios where you need to wrap an entire suite in a context
|
|
348
|
+
* (e.g., starting a server, opening a database connection that all tests share).
|
|
349
|
+
*
|
|
350
|
+
* **Note:** When multiple `aroundAll` hooks are registered, they are nested inside each other.
|
|
351
|
+
* The first registered hook is the outermost wrapper.
|
|
352
|
+
*
|
|
353
|
+
* @param {Function} fn - The callback function that wraps the suite. Must call `runSuite()` to run the tests.
|
|
354
|
+
* @param {number} [timeout] - Optional timeout in milliseconds for the hook. If not provided, the default hook timeout from the runner's configuration is used.
|
|
355
|
+
* @returns {void}
|
|
356
|
+
* @example
|
|
357
|
+
* ```ts
|
|
358
|
+
* // Example of using aroundAll to wrap suite in a tracing span
|
|
359
|
+
* aroundAll(async (runSuite) => {
|
|
360
|
+
* await tracer.trace('test-suite', runSuite);
|
|
361
|
+
* });
|
|
362
|
+
* ```
|
|
363
|
+
* @example
|
|
364
|
+
* ```ts
|
|
365
|
+
* // Example of using aroundAll with fixtures
|
|
366
|
+
* aroundAll(async (runSuite, { db }) => {
|
|
367
|
+
* await db.transaction(() => runSuite());
|
|
368
|
+
* });
|
|
369
|
+
* ```
|
|
370
|
+
*/
|
|
371
|
+
declare function aroundAll<ExtraContext = object>(this: unknown, fn: AroundAllListener<ExtraContext>, timeout?: number): void;
|
|
372
|
+
/**
|
|
373
|
+
* Registers a callback function that wraps around each test within the current suite.
|
|
374
|
+
* The callback receives a `runTest` function that must be called to run the test.
|
|
375
|
+
* This hook is useful for scenarios where you need to wrap tests in a context (e.g., database transactions).
|
|
376
|
+
*
|
|
377
|
+
* **Note:** When multiple `aroundEach` hooks are registered, they are nested inside each other.
|
|
378
|
+
* The first registered hook is the outermost wrapper.
|
|
379
|
+
*
|
|
380
|
+
* @param {Function} fn - The callback function that wraps the test. Must call `runTest()` to run the test.
|
|
381
|
+
* @param {number} [timeout] - Optional timeout in milliseconds for the hook. If not provided, the default hook timeout from the runner's configuration is used.
|
|
382
|
+
* @returns {void}
|
|
383
|
+
* @example
|
|
384
|
+
* ```ts
|
|
385
|
+
* // Example of using aroundEach to wrap tests in a database transaction
|
|
386
|
+
* aroundEach(async (runTest) => {
|
|
387
|
+
* await database.transaction(() => runTest());
|
|
388
|
+
* });
|
|
389
|
+
* ```
|
|
390
|
+
* @example
|
|
391
|
+
* ```ts
|
|
392
|
+
* // Example of using aroundEach with fixtures
|
|
393
|
+
* aroundEach(async (runTest, { db }) => {
|
|
394
|
+
* await db.transaction(() => runTest());
|
|
395
|
+
* });
|
|
396
|
+
* ```
|
|
397
|
+
*/
|
|
398
|
+
declare function aroundEach<ExtraContext = object>(fn: AroundEachListener<ExtraContext>, timeout?: number): void;
|
|
132
399
|
|
|
133
400
|
type ChainableFunction<
|
|
134
401
|
T extends string,
|
|
@@ -141,7 +408,7 @@ declare function createChainable<
|
|
|
141
408
|
T extends string,
|
|
142
409
|
Args extends any[],
|
|
143
410
|
R = any
|
|
144
|
-
>(keys: T[], fn: (this: Record<T, any>, ...args: Args) => R): ChainableFunction<T, (...args: Args) => R>;
|
|
411
|
+
>(keys: T[], fn: (this: Record<T, any>, ...args: Args) => R, context?: Record<string, any>): ChainableFunction<T, (...args: Args) => R>;
|
|
145
412
|
|
|
146
413
|
type RunMode = "run" | "skip" | "only" | "todo" | "queued";
|
|
147
414
|
type TaskState = RunMode | "pass" | "fail";
|
|
@@ -226,10 +493,12 @@ interface TaskBase {
|
|
|
226
493
|
*/
|
|
227
494
|
result?: TaskResult;
|
|
228
495
|
/**
|
|
229
|
-
*
|
|
496
|
+
* Retry configuration for the task.
|
|
497
|
+
* - If a number, specifies how many times to retry
|
|
498
|
+
* - If an object, allows fine-grained retry control
|
|
230
499
|
* @default 0
|
|
231
500
|
*/
|
|
232
|
-
retry?:
|
|
501
|
+
retry?: Retry;
|
|
233
502
|
/**
|
|
234
503
|
* The amount of times the task should be repeated after the successful run.
|
|
235
504
|
* If the task fails, it will not be retried unless `retry` is specified.
|
|
@@ -241,16 +510,17 @@ interface TaskBase {
|
|
|
241
510
|
* `includeTaskLocation` option is set. It is generated by calling `new Error`
|
|
242
511
|
* and parsing the stack trace, so the location might differ depending on the runtime.
|
|
243
512
|
*/
|
|
244
|
-
location?:
|
|
245
|
-
line: number;
|
|
246
|
-
column: number;
|
|
247
|
-
};
|
|
513
|
+
location?: Location;
|
|
248
514
|
/**
|
|
249
515
|
* If the test was collected by parsing the file AST, and the name
|
|
250
516
|
* is not a static string, this property will be set to `true`.
|
|
251
517
|
* @experimental
|
|
252
518
|
*/
|
|
253
519
|
dynamic?: boolean;
|
|
520
|
+
/**
|
|
521
|
+
* Custom tags of the task. Useful for filtering tasks.
|
|
522
|
+
*/
|
|
523
|
+
tags?: string[];
|
|
254
524
|
}
|
|
255
525
|
interface TaskPopulated extends TaskBase {
|
|
256
526
|
/**
|
|
@@ -335,7 +605,7 @@ interface TaskEventData {
|
|
|
335
605
|
artifact?: TestArtifact | undefined;
|
|
336
606
|
}
|
|
337
607
|
type TaskEventPack = [id: string, event: TaskUpdateEvent, data: TaskEventData | undefined];
|
|
338
|
-
type TaskUpdateEvent = "test-failed-early" | "suite-failed-early" | "test-prepare" | "test-finished" | "test-retried" | "suite-prepare" | "suite-finished" | "before-hook-start" | "before-hook-end" | "after-hook-start" | "after-hook-end" | "test-annotation" | "test-artifact";
|
|
608
|
+
type TaskUpdateEvent = "test-failed-early" | "suite-failed-early" | "test-prepare" | "test-finished" | "test-retried" | "test-cancel" | "suite-prepare" | "suite-finished" | "before-hook-start" | "before-hook-end" | "after-hook-start" | "after-hook-end" | "test-annotation" | "test-artifact";
|
|
339
609
|
interface Suite extends TaskBase {
|
|
340
610
|
type: "suite";
|
|
341
611
|
/**
|
|
@@ -448,18 +718,68 @@ type ChainableTestAPI<ExtraContext = object> = ChainableFunction<"concurrent" |
|
|
|
448
718
|
for: TestForFunction<ExtraContext>;
|
|
449
719
|
}>;
|
|
450
720
|
type TestCollectorOptions = Omit<TestOptions, "shuffle">;
|
|
721
|
+
/**
|
|
722
|
+
* Retry configuration for tests.
|
|
723
|
+
* Can be a number for simple retry count, or an object for advanced retry control.
|
|
724
|
+
*/
|
|
725
|
+
type Retry = number | {
|
|
726
|
+
/**
|
|
727
|
+
* The number of times to retry the test if it fails.
|
|
728
|
+
* @default 0
|
|
729
|
+
*/
|
|
730
|
+
count?: number;
|
|
731
|
+
/**
|
|
732
|
+
* Delay in milliseconds between retry attempts.
|
|
733
|
+
* @default 0
|
|
734
|
+
*/
|
|
735
|
+
delay?: number;
|
|
736
|
+
/**
|
|
737
|
+
* Condition to determine if a test should be retried based on the error.
|
|
738
|
+
* - If a RegExp, it is tested against the error message
|
|
739
|
+
* - If a function, called with the TestError object; return true to retry
|
|
740
|
+
*
|
|
741
|
+
* NOTE: Functions can only be used in test files, not in vitest.config.ts,
|
|
742
|
+
* because the configuration is serialized when passed to worker threads.
|
|
743
|
+
*
|
|
744
|
+
* @default undefined (retry on all errors)
|
|
745
|
+
*/
|
|
746
|
+
condition?: RegExp | ((error: TestError) => boolean);
|
|
747
|
+
};
|
|
748
|
+
/**
|
|
749
|
+
* Serializable retry configuration (used in config files).
|
|
750
|
+
* Functions cannot be serialized, so only string conditions are allowed.
|
|
751
|
+
*/
|
|
752
|
+
type SerializableRetry = number | {
|
|
753
|
+
/**
|
|
754
|
+
* The number of times to retry the test if it fails.
|
|
755
|
+
* @default 0
|
|
756
|
+
*/
|
|
757
|
+
count?: number;
|
|
758
|
+
/**
|
|
759
|
+
* Delay in milliseconds between retry attempts.
|
|
760
|
+
* @default 0
|
|
761
|
+
*/
|
|
762
|
+
delay?: number;
|
|
763
|
+
/**
|
|
764
|
+
* Condition to determine if a test should be retried based on the error.
|
|
765
|
+
* Must be a RegExp tested against the error message.
|
|
766
|
+
*
|
|
767
|
+
* @default undefined (retry on all errors)
|
|
768
|
+
*/
|
|
769
|
+
condition?: RegExp;
|
|
770
|
+
};
|
|
451
771
|
interface TestOptions {
|
|
452
772
|
/**
|
|
453
773
|
* Test timeout.
|
|
454
774
|
*/
|
|
455
775
|
timeout?: number;
|
|
456
776
|
/**
|
|
457
|
-
*
|
|
458
|
-
*
|
|
459
|
-
*
|
|
777
|
+
* Retry configuration for the test.
|
|
778
|
+
* - If a number, specifies how many times to retry
|
|
779
|
+
* - If an object, allows fine-grained retry control
|
|
460
780
|
* @default 0
|
|
461
781
|
*/
|
|
462
|
-
retry?:
|
|
782
|
+
retry?: Retry;
|
|
463
783
|
/**
|
|
464
784
|
* How many times the test will run again.
|
|
465
785
|
* Only inner tests will repeat if set on `describe()`, nested `describe()` will inherit parent's repeat by default.
|
|
@@ -478,10 +798,6 @@ interface TestOptions {
|
|
|
478
798
|
*/
|
|
479
799
|
sequential?: boolean;
|
|
480
800
|
/**
|
|
481
|
-
* Whether the tasks of the suite run in a random order.
|
|
482
|
-
*/
|
|
483
|
-
shuffle?: boolean;
|
|
484
|
-
/**
|
|
485
801
|
* Whether the test should be skipped.
|
|
486
802
|
*/
|
|
487
803
|
skip?: boolean;
|
|
@@ -497,20 +813,164 @@ interface TestOptions {
|
|
|
497
813
|
* Whether the test is expected to fail. If it does, the test will pass, otherwise it will fail.
|
|
498
814
|
*/
|
|
499
815
|
fails?: boolean;
|
|
816
|
+
/**
|
|
817
|
+
* Custom tags of the test. Useful for filtering tests.
|
|
818
|
+
*/
|
|
819
|
+
tags?: keyof TestTags extends never ? string[] | string : TestTags[keyof TestTags] | TestTags[keyof TestTags][];
|
|
820
|
+
/**
|
|
821
|
+
* Custom test metadata available to reporters.
|
|
822
|
+
*/
|
|
823
|
+
meta?: Partial<TaskMeta>;
|
|
824
|
+
}
|
|
825
|
+
interface TestTags {}
|
|
826
|
+
interface SuiteOptions extends TestOptions {
|
|
827
|
+
/**
|
|
828
|
+
* Whether the tasks of the suite run in a random order.
|
|
829
|
+
*/
|
|
830
|
+
shuffle?: boolean;
|
|
500
831
|
}
|
|
501
832
|
interface ExtendedAPI<ExtraContext> {
|
|
502
833
|
skipIf: (condition: any) => ChainableTestAPI<ExtraContext>;
|
|
503
834
|
runIf: (condition: any) => ChainableTestAPI<ExtraContext>;
|
|
504
835
|
}
|
|
505
836
|
interface Hooks<ExtraContext> {
|
|
506
|
-
|
|
507
|
-
|
|
837
|
+
/**
|
|
838
|
+
* Suite-level hooks only receive file/worker scoped fixtures.
|
|
839
|
+
* Test-scoped fixtures are NOT available in beforeAll/afterAll/aroundAll.
|
|
840
|
+
*/
|
|
841
|
+
beforeAll: typeof beforeAll<ExtractSuiteContext<ExtraContext>>;
|
|
842
|
+
afterAll: typeof afterAll<ExtractSuiteContext<ExtraContext>>;
|
|
843
|
+
aroundAll: typeof aroundAll<ExtractSuiteContext<ExtraContext>>;
|
|
844
|
+
/**
|
|
845
|
+
* Test-level hooks receive all fixtures including test-scoped ones.
|
|
846
|
+
*/
|
|
508
847
|
beforeEach: typeof beforeEach<ExtraContext>;
|
|
509
848
|
afterEach: typeof afterEach<ExtraContext>;
|
|
849
|
+
aroundEach: typeof aroundEach<ExtraContext>;
|
|
510
850
|
}
|
|
511
851
|
type TestAPI<ExtraContext = object> = ChainableTestAPI<ExtraContext> & ExtendedAPI<ExtraContext> & Hooks<ExtraContext> & {
|
|
512
|
-
|
|
513
|
-
|
|
852
|
+
/**
|
|
853
|
+
* Extend the test API with custom fixtures.
|
|
854
|
+
*
|
|
855
|
+
* @example
|
|
856
|
+
* ```ts
|
|
857
|
+
* // Simple test fixtures (backward compatible)
|
|
858
|
+
* const myTest = test.extend<{ foo: string }>({
|
|
859
|
+
* foo: 'value',
|
|
860
|
+
* })
|
|
861
|
+
*
|
|
862
|
+
* // With scoped fixtures - use $test/$file/$worker structure
|
|
863
|
+
* const myTest = test.extend<{
|
|
864
|
+
* $test: { testData: string }
|
|
865
|
+
* $file: { fileDb: Database }
|
|
866
|
+
* $worker: { workerConfig: Config }
|
|
867
|
+
* }>({
|
|
868
|
+
* testData: async ({ fileDb }, use) => {
|
|
869
|
+
* await use(await fileDb.getData())
|
|
870
|
+
* },
|
|
871
|
+
* fileDb: [async ({ workerConfig }, use) => {
|
|
872
|
+
* // File fixture can only access workerConfig, NOT testData
|
|
873
|
+
* const db = new Database(workerConfig)
|
|
874
|
+
* await use(db)
|
|
875
|
+
* await db.close()
|
|
876
|
+
* }, { scope: 'file' }],
|
|
877
|
+
* workerConfig: [async ({}, use) => {
|
|
878
|
+
* // Worker fixture can only access other worker fixtures
|
|
879
|
+
* await use(loadConfig())
|
|
880
|
+
* }, { scope: 'worker' }],
|
|
881
|
+
* })
|
|
882
|
+
*
|
|
883
|
+
* // Builder pattern with automatic type inference
|
|
884
|
+
* const myTest = test
|
|
885
|
+
* .extend('config', { scope: 'worker' }, async ({}) => {
|
|
886
|
+
* return { port: 3000 } // Type inferred as { port: number }
|
|
887
|
+
* })
|
|
888
|
+
* .extend('db', { scope: 'file' }, async ({ config }, { onCleanup }) => {
|
|
889
|
+
* // TypeScript knows config is { port: number }
|
|
890
|
+
* const db = new Database(config.port)
|
|
891
|
+
* onCleanup(() => db.close()) // Register cleanup
|
|
892
|
+
* return db // Type inferred as Database
|
|
893
|
+
* })
|
|
894
|
+
* .extend('data', async ({ db }) => {
|
|
895
|
+
* // TypeScript knows db is Database
|
|
896
|
+
* return await db.getData() // Type inferred from return
|
|
897
|
+
* })
|
|
898
|
+
* ```
|
|
899
|
+
*/
|
|
900
|
+
extend: {
|
|
901
|
+
<
|
|
902
|
+
K extends string,
|
|
903
|
+
T extends (K extends keyof ExtraContext ? ExtraContext[K] : unknown)
|
|
904
|
+
>(name: K, options: WorkerScopeFixtureOptions, fn: BuilderFixtureFn<T, WorkerScopeContext<ExtraContext>>): TestAPI<AddBuilderWorker<ExtraContext, K, T>>;
|
|
905
|
+
<
|
|
906
|
+
K extends string,
|
|
907
|
+
T extends (K extends keyof ExtraContext ? ExtraContext[K] : unknown)
|
|
908
|
+
>(name: K, options: FileScopeFixtureOptions, fn: BuilderFixtureFn<T, FileScopeContext<ExtraContext>>): TestAPI<AddBuilderFile<ExtraContext, K, T>>;
|
|
909
|
+
<
|
|
910
|
+
K extends string,
|
|
911
|
+
T extends (K extends keyof ExtraContext ? ExtraContext[K] : unknown)
|
|
912
|
+
>(name: K, options: TestScopeFixtureOptions, fn: BuilderFixtureFn<T, TestScopeContext<ExtraContext>>): TestAPI<AddBuilderTest<ExtraContext, K, T>>;
|
|
913
|
+
<
|
|
914
|
+
K extends string,
|
|
915
|
+
T extends (K extends keyof ExtraContext ? ExtraContext[K] : unknown)
|
|
916
|
+
>(name: K, fn: BuilderFixtureFn<T, TestScopeContext<ExtraContext>>): TestAPI<AddBuilderTest<ExtraContext, K, T>>;
|
|
917
|
+
<
|
|
918
|
+
K extends string,
|
|
919
|
+
T extends (K extends keyof ExtraContext ? ExtraContext[K] : unknown)
|
|
920
|
+
>(name: K, options: WorkerScopeFixtureOptions, value: T extends (...args: any[]) => any ? never : T): TestAPI<AddBuilderWorker<ExtraContext, K, T>>;
|
|
921
|
+
<
|
|
922
|
+
K extends string,
|
|
923
|
+
T extends (K extends keyof ExtraContext ? ExtraContext[K] : unknown)
|
|
924
|
+
>(name: K, options: FileScopeFixtureOptions, value: T extends (...args: any[]) => any ? never : T): TestAPI<AddBuilderFile<ExtraContext, K, T>>;
|
|
925
|
+
<
|
|
926
|
+
K extends string,
|
|
927
|
+
T extends (K extends keyof ExtraContext ? ExtraContext[K] : unknown)
|
|
928
|
+
>(name: K, options: TestScopeFixtureOptions, value: T extends (...args: any[]) => any ? never : T): TestAPI<AddBuilderTest<ExtraContext, K, T>>;
|
|
929
|
+
<
|
|
930
|
+
K extends string,
|
|
931
|
+
T extends (K extends keyof ExtraContext ? ExtraContext[K] : unknown)
|
|
932
|
+
>(name: K, value: T extends (...args: any[]) => any ? never : T): TestAPI<AddBuilderTest<ExtraContext, K, T>>;
|
|
933
|
+
<T extends ScopedFixturesDef>(fixtures: ScopedFixturesObject<T, ExtraContext>): TestAPI<ExtractScopedFixtures<T> & ExtraContext>;
|
|
934
|
+
<T extends Record<string, any> = object>(fixtures: Fixtures<T, ExtraContext>): TestAPI<{ [K in keyof T | keyof ExtraContext] : K extends keyof T ? T[K] : K extends keyof ExtraContext ? ExtraContext[K] : never }>;
|
|
935
|
+
};
|
|
936
|
+
/**
|
|
937
|
+
* Overwrite fixture values for the current suite scope.
|
|
938
|
+
* Supports both object syntax and builder pattern.
|
|
939
|
+
*
|
|
940
|
+
* @example
|
|
941
|
+
* ```ts
|
|
942
|
+
* describe('with custom config', () => {
|
|
943
|
+
* // Object syntax
|
|
944
|
+
* test.override({ config: { port: 4000 } })
|
|
945
|
+
*
|
|
946
|
+
* // Builder pattern - value
|
|
947
|
+
* test.override('config', { port: 4000 })
|
|
948
|
+
*
|
|
949
|
+
* // Builder pattern - function
|
|
950
|
+
* test.override('config', () => ({ port: 4000 }))
|
|
951
|
+
*
|
|
952
|
+
* // Builder pattern - function with cleanup
|
|
953
|
+
* test.override('db', async ({ config }, { onCleanup }) => {
|
|
954
|
+
* const db = await createDb(config)
|
|
955
|
+
* onCleanup(() => db.close())
|
|
956
|
+
* return db
|
|
957
|
+
* })
|
|
958
|
+
* })
|
|
959
|
+
* ```
|
|
960
|
+
*/
|
|
961
|
+
override: {
|
|
962
|
+
<K extends keyof ExtraContext>(name: K, options: FixtureOptions, fn: BuilderFixtureFn<ExtraContext[K], ExtraContext & TestContext>): TestAPI<ExtraContext>;
|
|
963
|
+
<K extends keyof ExtraContext>(name: K, fn: BuilderFixtureFn<ExtraContext[K], ExtraContext & TestContext>): TestAPI<ExtraContext>;
|
|
964
|
+
<K extends keyof ExtraContext>(name: K, options: FixtureOptions, value: ExtraContext[K] extends (...args: any[]) => any ? never : ExtraContext[K]): TestAPI<ExtraContext>;
|
|
965
|
+
<K extends keyof ExtraContext>(name: K, value: ExtraContext[K] extends (...args: any[]) => any ? never : ExtraContext[K]): TestAPI<ExtraContext>;
|
|
966
|
+
(fixtures: Partial<Fixtures<ExtraContext>>): TestAPI<ExtraContext>;
|
|
967
|
+
};
|
|
968
|
+
/**
|
|
969
|
+
* @deprecated Use `test.override()` instead
|
|
970
|
+
*/
|
|
971
|
+
scoped: (fixtures: Partial<Fixtures<ExtraContext>>) => TestAPI<ExtraContext>;
|
|
972
|
+
describe: SuiteAPI<ExtraContext>;
|
|
973
|
+
suite: SuiteAPI<ExtraContext>;
|
|
514
974
|
};
|
|
515
975
|
interface FixtureOptions {
|
|
516
976
|
/**
|
|
@@ -533,7 +993,141 @@ interface FixtureOptions {
|
|
|
533
993
|
*/
|
|
534
994
|
scope?: "test" | "worker" | "file";
|
|
535
995
|
}
|
|
996
|
+
/**
|
|
997
|
+
* Options for test-scoped fixtures.
|
|
998
|
+
* Test fixtures are set up before each test and have access to all fixtures.
|
|
999
|
+
*/
|
|
1000
|
+
interface TestScopeFixtureOptions extends Omit<FixtureOptions, "scope"> {
|
|
1001
|
+
/**
|
|
1002
|
+
* @default 'test'
|
|
1003
|
+
*/
|
|
1004
|
+
scope?: "test";
|
|
1005
|
+
}
|
|
1006
|
+
/**
|
|
1007
|
+
* Options for file-scoped fixtures.
|
|
1008
|
+
* File fixtures are set up once per file and can only access other file fixtures and worker fixtures.
|
|
1009
|
+
*/
|
|
1010
|
+
interface FileScopeFixtureOptions extends Omit<FixtureOptions, "scope"> {
|
|
1011
|
+
/**
|
|
1012
|
+
* Must be 'file' for file-scoped fixtures.
|
|
1013
|
+
*/
|
|
1014
|
+
scope: "file";
|
|
1015
|
+
}
|
|
1016
|
+
/**
|
|
1017
|
+
* Options for worker-scoped fixtures.
|
|
1018
|
+
* Worker fixtures are set up once per worker and can only access other worker fixtures.
|
|
1019
|
+
*/
|
|
1020
|
+
interface WorkerScopeFixtureOptions extends Omit<FixtureOptions, "scope"> {
|
|
1021
|
+
/**
|
|
1022
|
+
* Must be 'worker' for worker-scoped fixtures.
|
|
1023
|
+
*/
|
|
1024
|
+
scope: "worker";
|
|
1025
|
+
}
|
|
536
1026
|
type Use<T> = (value: T) => Promise<void>;
|
|
1027
|
+
/**
|
|
1028
|
+
* Cleanup registration function for builder pattern fixtures.
|
|
1029
|
+
* Call this to register a cleanup function that runs after the test/file/worker completes.
|
|
1030
|
+
*
|
|
1031
|
+
* **Note:** This function can only be called once per fixture. If you need multiple
|
|
1032
|
+
* cleanup operations, either combine them into a single cleanup function or split
|
|
1033
|
+
* your fixture into multiple smaller fixtures.
|
|
1034
|
+
*/
|
|
1035
|
+
type OnCleanup = (cleanup: () => Awaitable<void>) => void;
|
|
1036
|
+
/**
|
|
1037
|
+
* Builder pattern fixture function with automatic type inference.
|
|
1038
|
+
* Returns the fixture value directly (type is inferred from return).
|
|
1039
|
+
* Use onCleanup to register teardown logic.
|
|
1040
|
+
*
|
|
1041
|
+
* Parameters can be omitted if not needed:
|
|
1042
|
+
* - `async () => value` - no dependencies, no cleanup
|
|
1043
|
+
* - `async ({ dep }) => value` - with dependencies, no cleanup
|
|
1044
|
+
* - `async ({ dep }, { onCleanup }) => value` - with dependencies and cleanup
|
|
1045
|
+
*/
|
|
1046
|
+
type BuilderFixtureFn<
|
|
1047
|
+
T,
|
|
1048
|
+
Context
|
|
1049
|
+
> = (context: Context, fixture: {
|
|
1050
|
+
onCleanup: OnCleanup;
|
|
1051
|
+
}) => T | Promise<T>;
|
|
1052
|
+
type ExtractSuiteContext<C> = C extends {
|
|
1053
|
+
$__worker?: any;
|
|
1054
|
+
} | {
|
|
1055
|
+
$__file?: any;
|
|
1056
|
+
} | {
|
|
1057
|
+
$__test?: any;
|
|
1058
|
+
} ? ExtractBuilderWorker<C> & ExtractBuilderFile<C> : C;
|
|
1059
|
+
/**
|
|
1060
|
+
* Extracts worker-scoped fixtures from a context that includes scope info.
|
|
1061
|
+
*/
|
|
1062
|
+
type ExtractBuilderWorker<C> = C extends {
|
|
1063
|
+
$__worker?: infer W;
|
|
1064
|
+
} ? W extends Record<string, any> ? W : object : object;
|
|
1065
|
+
/**
|
|
1066
|
+
* Extracts file-scoped fixtures from a context that includes scope info.
|
|
1067
|
+
*/
|
|
1068
|
+
type ExtractBuilderFile<C> = C extends {
|
|
1069
|
+
$__file?: infer F;
|
|
1070
|
+
} ? F extends Record<string, any> ? F : object : object;
|
|
1071
|
+
/**
|
|
1072
|
+
* Extracts test-scoped fixtures from a context that includes scope info.
|
|
1073
|
+
*/
|
|
1074
|
+
type ExtractBuilderTest<C> = C extends {
|
|
1075
|
+
$__test?: infer T;
|
|
1076
|
+
} ? T extends Record<string, any> ? T : object : object;
|
|
1077
|
+
/**
|
|
1078
|
+
* Adds a worker fixture to the context with proper scope tracking.
|
|
1079
|
+
*/
|
|
1080
|
+
type AddBuilderWorker<
|
|
1081
|
+
C,
|
|
1082
|
+
K extends string,
|
|
1083
|
+
V
|
|
1084
|
+
> = Omit<C, "$__worker"> & Record<K, V> & {
|
|
1085
|
+
readonly $__worker?: ExtractBuilderWorker<C> & Record<K, V>;
|
|
1086
|
+
readonly $__file?: ExtractBuilderFile<C>;
|
|
1087
|
+
readonly $__test?: ExtractBuilderTest<C>;
|
|
1088
|
+
};
|
|
1089
|
+
/**
|
|
1090
|
+
* Adds a file fixture to the context with proper scope tracking.
|
|
1091
|
+
*/
|
|
1092
|
+
type AddBuilderFile<
|
|
1093
|
+
C,
|
|
1094
|
+
K extends string,
|
|
1095
|
+
V
|
|
1096
|
+
> = Omit<C, "$__file"> & Record<K, V> & {
|
|
1097
|
+
readonly $__worker?: ExtractBuilderWorker<C>;
|
|
1098
|
+
readonly $__file?: ExtractBuilderFile<C> & Record<K, V>;
|
|
1099
|
+
readonly $__test?: ExtractBuilderTest<C>;
|
|
1100
|
+
};
|
|
1101
|
+
/**
|
|
1102
|
+
* Adds a test fixture to the context with proper scope tracking.
|
|
1103
|
+
*/
|
|
1104
|
+
type AddBuilderTest<
|
|
1105
|
+
C,
|
|
1106
|
+
K extends string,
|
|
1107
|
+
V
|
|
1108
|
+
> = Omit<C, "$__test"> & Record<K, V> & {
|
|
1109
|
+
readonly $__worker?: ExtractBuilderWorker<C>;
|
|
1110
|
+
readonly $__file?: ExtractBuilderFile<C>;
|
|
1111
|
+
readonly $__test?: ExtractBuilderTest<C> & Record<K, V>;
|
|
1112
|
+
};
|
|
1113
|
+
/**
|
|
1114
|
+
* Context available to worker-scoped fixtures.
|
|
1115
|
+
* Worker fixtures can only access other worker fixtures.
|
|
1116
|
+
* They do NOT have access to test context (task, expect, onTestFailed, etc.)
|
|
1117
|
+
* since they run once per worker, outside of any specific test.
|
|
1118
|
+
*/
|
|
1119
|
+
type WorkerScopeContext<C> = ExtractBuilderWorker<C>;
|
|
1120
|
+
/**
|
|
1121
|
+
* Context available to file-scoped fixtures.
|
|
1122
|
+
* File fixtures can access worker and other file fixtures.
|
|
1123
|
+
* They do NOT have access to test context (task, expect, onTestFailed, etc.)
|
|
1124
|
+
* since they run once per file, outside of any specific test.
|
|
1125
|
+
*/
|
|
1126
|
+
type FileScopeContext<C> = ExtractBuilderWorker<C> & ExtractBuilderFile<C>;
|
|
1127
|
+
/**
|
|
1128
|
+
* Context available to test-scoped fixtures (all fixtures + test context).
|
|
1129
|
+
*/
|
|
1130
|
+
type TestScopeContext<C> = C & TestContext;
|
|
537
1131
|
type FixtureFn<
|
|
538
1132
|
T,
|
|
539
1133
|
K extends keyof T,
|
|
@@ -544,14 +1138,59 @@ type Fixture<
|
|
|
544
1138
|
K extends keyof T,
|
|
545
1139
|
ExtraContext = object
|
|
546
1140
|
> = ((...args: any) => any) extends T[K] ? T[K] extends any ? FixtureFn<T, K, Omit<ExtraContext, Exclude<keyof T, K>>> : never : T[K] | (T[K] extends any ? FixtureFn<T, K, Omit<ExtraContext, Exclude<keyof T, K>>> : never);
|
|
1141
|
+
/**
|
|
1142
|
+
* Fixture function with explicit context type for scoped fixtures.
|
|
1143
|
+
*/
|
|
1144
|
+
type ScopedFixtureFn<
|
|
1145
|
+
Value,
|
|
1146
|
+
Context
|
|
1147
|
+
> = (context: Context, use: Use<Value>) => Promise<void>;
|
|
1148
|
+
/**
|
|
1149
|
+
* Fixtures definition for backward compatibility.
|
|
1150
|
+
* All fixtures are in T and any scope is allowed.
|
|
1151
|
+
*/
|
|
547
1152
|
type Fixtures<
|
|
548
1153
|
T,
|
|
549
1154
|
ExtraContext = object
|
|
550
1155
|
> = { [K in keyof T] : Fixture<T, K, ExtraContext & TestContext> | [Fixture<T, K, ExtraContext & TestContext>, FixtureOptions?] };
|
|
1156
|
+
/**
|
|
1157
|
+
* Scoped fixtures definition using a single generic with optional scope keys.
|
|
1158
|
+
* This provides better ergonomics than multiple generics.
|
|
1159
|
+
* Uses $ prefix to avoid conflicts with fixture names.
|
|
1160
|
+
*
|
|
1161
|
+
* @example
|
|
1162
|
+
* ```ts
|
|
1163
|
+
* test.extend<{
|
|
1164
|
+
* $worker?: { config: Config }
|
|
1165
|
+
* $file?: { db: Database }
|
|
1166
|
+
* $test?: { data: string }
|
|
1167
|
+
* }>({ ... })
|
|
1168
|
+
* ```
|
|
1169
|
+
*/
|
|
1170
|
+
interface ScopedFixturesDef {
|
|
1171
|
+
$test?: Record<string, any>;
|
|
1172
|
+
$file?: Record<string, any>;
|
|
1173
|
+
$worker?: Record<string, any>;
|
|
1174
|
+
}
|
|
1175
|
+
/**
|
|
1176
|
+
* Extracts fixture types from a ScopedFixturesDef.
|
|
1177
|
+
* Handles optional properties by using Exclude to remove undefined.
|
|
1178
|
+
*/
|
|
1179
|
+
type ExtractScopedFixtures<T extends ScopedFixturesDef> = ([Exclude<T["$test"], undefined>] extends [never] ? object : Exclude<T["$test"], undefined>) & ([Exclude<T["$file"], undefined>] extends [never] ? object : Exclude<T["$file"], undefined>) & ([Exclude<T["$worker"], undefined>] extends [never] ? object : Exclude<T["$worker"], undefined>);
|
|
1180
|
+
/**
|
|
1181
|
+
* Creates the fixtures object type for ScopedFixturesDef with proper scope validation.
|
|
1182
|
+
* - Test fixtures: can be defined as value, function, or tuple with optional scope
|
|
1183
|
+
* - File fixtures: MUST have { scope: 'file' }
|
|
1184
|
+
* - Worker fixtures: MUST have { scope: 'worker' }
|
|
1185
|
+
*/
|
|
1186
|
+
type ScopedFixturesObject<
|
|
1187
|
+
T extends ScopedFixturesDef,
|
|
1188
|
+
ExtraContext = object
|
|
1189
|
+
> = { [K in keyof NonNullable<T["$test"]>] : NonNullable<T["$test"]>[K] | ScopedFixtureFn<NonNullable<T["$test"]>[K], ExtractScopedFixtures<T> & ExtraContext & TestContext> | [ScopedFixtureFn<NonNullable<T["$test"]>[K], ExtractScopedFixtures<T> & ExtraContext & TestContext>, TestScopeFixtureOptions?] } & { [K in keyof NonNullable<T["$file"]>] : [ScopedFixtureFn<NonNullable<T["$file"]>[K], (NonNullable<T["$file"]> & NonNullable<T["$worker"]>) & ExtraContext>, FileScopeFixtureOptions] } & { [K in keyof NonNullable<T["$worker"]>] : [ScopedFixtureFn<NonNullable<T["$worker"]>[K], NonNullable<T["$worker"]> & ExtraContext>, WorkerScopeFixtureOptions] };
|
|
551
1190
|
type InferFixturesTypes<T> = T extends TestAPI<infer C> ? C : T;
|
|
552
1191
|
interface SuiteCollectorCallable<ExtraContext = object> {
|
|
553
1192
|
<OverrideExtraContext extends ExtraContext = ExtraContext>(name: string | Function, fn?: SuiteFactory<OverrideExtraContext>, options?: number): SuiteCollector<OverrideExtraContext>;
|
|
554
|
-
<OverrideExtraContext extends ExtraContext = ExtraContext>(name: string | Function, options:
|
|
1193
|
+
<OverrideExtraContext extends ExtraContext = ExtraContext>(name: string | Function, options: SuiteOptions, fn?: SuiteFactory<OverrideExtraContext>): SuiteCollector<OverrideExtraContext>;
|
|
555
1194
|
}
|
|
556
1195
|
type ChainableSuiteAPI<ExtraContext = object> = ChainableFunction<"concurrent" | "sequential" | "only" | "skip" | "todo" | "shuffle", SuiteCollectorCallable<ExtraContext>, {
|
|
557
1196
|
each: TestEachFunction;
|
|
@@ -561,11 +1200,11 @@ type SuiteAPI<ExtraContext = object> = ChainableSuiteAPI<ExtraContext> & {
|
|
|
561
1200
|
skipIf: (condition: any) => ChainableSuiteAPI<ExtraContext>;
|
|
562
1201
|
runIf: (condition: any) => ChainableSuiteAPI<ExtraContext>;
|
|
563
1202
|
};
|
|
564
|
-
interface BeforeAllListener {
|
|
565
|
-
(suite: Readonly<Suite | File>): Awaitable<unknown>;
|
|
1203
|
+
interface BeforeAllListener<ExtraContext = object> {
|
|
1204
|
+
(context: ExtraContext, suite: Readonly<Suite | File>): Awaitable<unknown>;
|
|
566
1205
|
}
|
|
567
|
-
interface AfterAllListener {
|
|
568
|
-
(suite: Readonly<Suite | File>): Awaitable<unknown>;
|
|
1206
|
+
interface AfterAllListener<ExtraContext = object> {
|
|
1207
|
+
(context: ExtraContext, suite: Readonly<Suite | File>): Awaitable<unknown>;
|
|
569
1208
|
}
|
|
570
1209
|
interface BeforeEachListener<ExtraContext = object> {
|
|
571
1210
|
(context: TestContext & ExtraContext, suite: Readonly<Suite>): Awaitable<unknown>;
|
|
@@ -573,11 +1212,25 @@ interface BeforeEachListener<ExtraContext = object> {
|
|
|
573
1212
|
interface AfterEachListener<ExtraContext = object> {
|
|
574
1213
|
(context: TestContext & ExtraContext, suite: Readonly<Suite>): Awaitable<unknown>;
|
|
575
1214
|
}
|
|
1215
|
+
interface AroundEachListener<ExtraContext = object> {
|
|
1216
|
+
(runTest: () => Promise<void>, context: TestContext & ExtraContext, suite: Readonly<Suite>): Awaitable<unknown>;
|
|
1217
|
+
}
|
|
1218
|
+
interface AroundAllListener<ExtraContext = object> {
|
|
1219
|
+
(runSuite: () => Promise<void>, context: ExtraContext, suite: Readonly<Suite | File>): Awaitable<unknown>;
|
|
1220
|
+
}
|
|
1221
|
+
interface RegisteredAllListener {
|
|
1222
|
+
(suite: Readonly<Suite | File>): Awaitable<unknown>;
|
|
1223
|
+
}
|
|
1224
|
+
interface RegisteredAroundAllListener {
|
|
1225
|
+
(runSuite: () => Promise<void>, suite: Readonly<Suite | File>): Awaitable<unknown>;
|
|
1226
|
+
}
|
|
576
1227
|
interface SuiteHooks<ExtraContext = object> {
|
|
577
|
-
beforeAll:
|
|
578
|
-
afterAll:
|
|
1228
|
+
beforeAll: RegisteredAllListener[];
|
|
1229
|
+
afterAll: RegisteredAllListener[];
|
|
1230
|
+
aroundAll: RegisteredAroundAllListener[];
|
|
579
1231
|
beforeEach: BeforeEachListener<ExtraContext>[];
|
|
580
1232
|
afterEach: AfterEachListener<ExtraContext>[];
|
|
1233
|
+
aroundEach: AroundEachListener<ExtraContext>[];
|
|
581
1234
|
}
|
|
582
1235
|
interface TaskCustomOptions extends TestOptions {
|
|
583
1236
|
/**
|
|
@@ -585,13 +1238,9 @@ interface TaskCustomOptions extends TestOptions {
|
|
|
585
1238
|
*/
|
|
586
1239
|
each?: boolean;
|
|
587
1240
|
/**
|
|
588
|
-
* Custom metadata for the task that will be assigned to `task.meta`.
|
|
589
|
-
*/
|
|
590
|
-
meta?: Record<string, unknown>;
|
|
591
|
-
/**
|
|
592
1241
|
* Task fixtures.
|
|
593
1242
|
*/
|
|
594
|
-
fixtures?:
|
|
1243
|
+
fixtures?: TestFixtures;
|
|
595
1244
|
/**
|
|
596
1245
|
* Function that will be called when the task is executed.
|
|
597
1246
|
* If nothing is provided, the runner will try to get the function using `getFn(task)`.
|
|
@@ -602,13 +1251,11 @@ interface TaskCustomOptions extends TestOptions {
|
|
|
602
1251
|
interface SuiteCollector<ExtraContext = object> {
|
|
603
1252
|
readonly name: string;
|
|
604
1253
|
readonly mode: RunMode;
|
|
605
|
-
options?:
|
|
1254
|
+
options?: SuiteOptions;
|
|
606
1255
|
type: "collector";
|
|
607
1256
|
test: TestAPI<ExtraContext>;
|
|
608
1257
|
tasks: (Suite | Test<ExtraContext> | SuiteCollector<ExtraContext>)[];
|
|
609
|
-
|
|
610
|
-
fixtures: () => FixtureItem[] | undefined;
|
|
611
|
-
file?: File;
|
|
1258
|
+
file: File;
|
|
612
1259
|
suite?: Suite;
|
|
613
1260
|
task: (name: string, options?: TaskCustomOptions) => Test<ExtraContext>;
|
|
614
1261
|
collect: (file: File) => Promise<Suite>;
|
|
@@ -685,12 +1332,13 @@ interface TestAttachment {
|
|
|
685
1332
|
/** Inline attachment content as a string or raw binary data */
|
|
686
1333
|
body?: string | Uint8Array;
|
|
687
1334
|
}
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
1335
|
+
interface Location {
|
|
1336
|
+
/** Line number in the source file (1-indexed) */
|
|
1337
|
+
line: number;
|
|
1338
|
+
/** Column number in the line (1-indexed) */
|
|
1339
|
+
column: number;
|
|
1340
|
+
}
|
|
1341
|
+
interface FileLocation extends Location {
|
|
694
1342
|
/** Line number in the source file (1-indexed) */
|
|
695
1343
|
line: number;
|
|
696
1344
|
/** Column number in the line (1-indexed) */
|
|
@@ -699,11 +1347,19 @@ interface TestArtifactLocation {
|
|
|
699
1347
|
file: string;
|
|
700
1348
|
}
|
|
701
1349
|
/**
|
|
1350
|
+
* Source code location information for a test artifact.
|
|
1351
|
+
*
|
|
1352
|
+
* Indicates where in the source code the artifact originated from.
|
|
1353
|
+
*/
|
|
1354
|
+
interface TestArtifactLocation extends FileLocation {}
|
|
1355
|
+
/**
|
|
702
1356
|
* @experimental
|
|
703
1357
|
*
|
|
704
1358
|
* Base interface for all test artifacts.
|
|
705
1359
|
*
|
|
706
1360
|
* 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.
|
|
1361
|
+
*
|
|
1362
|
+
* **Important**: when running with [`api.allowWrite`](https://vitest.dev/config/api#api-allowwrite) or [`browser.api.allowWrite`](https://vitest.dev/config/browser/api#api-allowwrite) disabled, Vitest empties the `attachments` array on every artifact before reporting it.
|
|
707
1363
|
*/
|
|
708
1364
|
interface TestArtifactBase {
|
|
709
1365
|
/** File or data attachments associated with this artifact */
|
|
@@ -748,6 +1404,21 @@ interface VisualRegressionArtifact extends TestArtifactBase {
|
|
|
748
1404
|
message: string;
|
|
749
1405
|
attachments: VisualRegressionArtifactAttachment[];
|
|
750
1406
|
}
|
|
1407
|
+
interface FailureScreenshotArtifactAttachment extends TestAttachment {
|
|
1408
|
+
path: string;
|
|
1409
|
+
/** Original file system path to the screenshot, before attachment resolution */
|
|
1410
|
+
originalPath: string;
|
|
1411
|
+
body?: undefined;
|
|
1412
|
+
}
|
|
1413
|
+
/**
|
|
1414
|
+
* @experimental
|
|
1415
|
+
*
|
|
1416
|
+
* Artifact type for failure screenshots.
|
|
1417
|
+
*/
|
|
1418
|
+
interface FailureScreenshotArtifact extends TestArtifactBase {
|
|
1419
|
+
type: "internal:failureScreenshot";
|
|
1420
|
+
attachments: [FailureScreenshotArtifactAttachment] | [];
|
|
1421
|
+
}
|
|
751
1422
|
/**
|
|
752
1423
|
* @experimental
|
|
753
1424
|
* @advanced
|
|
@@ -828,7 +1499,7 @@ interface TestArtifactRegistry {}
|
|
|
828
1499
|
*
|
|
829
1500
|
* This type automatically includes all artifacts registered via {@link TestArtifactRegistry}.
|
|
830
1501
|
*/
|
|
831
|
-
type TestArtifact = TestAnnotationArtifact | VisualRegressionArtifact | TestArtifactRegistry[keyof TestArtifactRegistry];
|
|
1502
|
+
type TestArtifact = FailureScreenshotArtifact | TestAnnotationArtifact | VisualRegressionArtifact | TestArtifactRegistry[keyof TestArtifactRegistry];
|
|
832
1503
|
|
|
833
|
-
export {
|
|
834
|
-
export type {
|
|
1504
|
+
export { afterAll as a8, afterEach as a9, aroundAll as aa, aroundEach as ab, beforeAll as ac, beforeEach as ad, onTestFailed as ae, onTestFinished as af, createChainable as ah };
|
|
1505
|
+
export type { TestFunction as $, AfterAllListener as A, BeforeAllListener as B, CancelReason as C, TaskBase as D, TaskCustomOptions as E, FileSpecification as F, TaskEventPack as G, TaskHook as H, ImportDuration as I, TaskMeta as J, TaskPopulated as K, TaskResult as L, TaskResultPack as M, TaskState as N, OnTestFailedHandler as O, TestAnnotation as P, TestAnnotationArtifact as Q, Retry as R, Suite as S, TestArtifact as T, TestAnnotationLocation as U, VitestRunner as V, TestArtifactBase as W, TestArtifactLocation as X, TestArtifactRegistry as Y, TestAttachment as Z, TestContext as _, Test as a, TestOptions as a0, TestTagDefinition as a1, TestTags as a2, Use as a3, VisualRegressionArtifact as a4, VitestRunnerConfig as a5, VitestRunnerConstructor as a6, VitestRunnerImportSource as a7, ChainableFunction as ag, SuiteHooks as b, File as c, TaskUpdateEvent as d, Task as e, TestAPI as f, SuiteAPI as g, SuiteCollector as h, AfterEachListener as i, AroundAllListener as j, AroundEachListener as k, BeforeEachListener as l, FailureScreenshotArtifact as m, Fixture as n, FixtureFn as o, FixtureOptions as p, Fixtures as q, InferFixturesTypes as r, OnTestFinishedHandler as s, RunMode as t, RuntimeContext as u, SequenceHooks as v, SequenceSetupFiles as w, SerializableRetry as x, SuiteFactory as y, SuiteOptions as z };
|