/
coverage.ts
214 lines (184 loc) · 4.42 KB
/
coverage.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
import type { TransformPluginContext, TransformResult } from 'rollup'
import type { Vitest } from '../node'
import type { Arrayable } from './general'
import type { AfterSuiteRunMeta } from './worker'
export interface CoverageProvider {
name: string
initialize(ctx: Vitest): Promise<void> | void
resolveOptions(): ResolvedCoverageOptions
clean(clean?: boolean): void | Promise<void>
onBeforeFilesRun?(): void | Promise<void>
onAfterSuiteRun(meta: AfterSuiteRunMeta): void | Promise<void>
reportCoverage(): void | Promise<void>
onFileTransform?(
sourceCode: string,
id: string,
pluginCtx: TransformPluginContext
): TransformResult | Promise<TransformResult>
}
export interface CoverageProviderModule {
/**
* Factory for creating a new coverage provider
*/
getProvider(): CoverageProvider | Promise<CoverageProvider>
/**
* Executed on after each run in the worker thread. Possible to return a payload passed to the provider
*/
takeCoverage?(): unknown | Promise<unknown>
}
export type CoverageReporter =
| 'clover'
| 'cobertura'
| 'html-spa'
| 'html'
| 'json-summary'
| 'json'
| 'lcov'
| 'lcovonly'
| 'none'
| 'teamcity'
| 'text-lcov'
| 'text-summary'
| 'text'
export type CoverageOptions =
| BaseCoverageOptions & { provider?: null | CoverageProviderModule }
| CoverageC8Options & { provider?: 'c8' }
| CoverageIstanbulOptions & { provider?: 'istanbul' }
export type ResolvedCoverageOptions =
& { tempDirectory: string }
& Required<CoverageOptions>
export interface BaseCoverageOptions {
/**
* Enables coverage collection. Can be overriden using `--coverage` CLI option.
*
* @default false
*/
enabled?: boolean
/**
* List of files included in coverage as glob patterns
*
* @default ['**']
*/
include?: string[]
/**
* Extensions for files to be included in coverage
*
* @default ['.js', '.cjs', '.mjs', '.ts', '.tsx', '.jsx', '.vue', '.svelte']
*/
extension?: string | string[]
/**
* List of files excluded from coverage as glob patterns
*/
exclude?: string[]
/**
* Whether to include all files, including the untested ones into report
*
* @default false
*/
all?: boolean
/**
* Clean coverage results before running tests
*
* @default true
*/
clean?: boolean
/**
* Clean coverage report on watch rerun
*
* @default true
*/
cleanOnRerun?: boolean
/**
* Directory to write coverage report to
*/
reportsDirectory?: string
/**
* Coverage reporters to use.
* See [istanbul documentation](https://istanbul.js.org/docs/advanced/alternative-reporters/) for detailed list of all reporters.
*
* @default ['text', 'html', 'clover', 'json']
*/
reporter?: Arrayable<CoverageReporter>
/**
* Do not show files with 100% statement, branch, and function coverage
*
* @default false
*/
skipFull?: boolean
/**
* Check thresholds per file.
* See `lines`, `functions`, `branches` and `statements` for the actual thresholds.
*
* @default false
*/
perFile?: boolean
/**
* Threshold for lines
*
* @default undefined
*/
lines?: number
/**
* Threshold for functions
*
* @default undefined
*/
functions?: number
/**
* Threshold for branches
*
* @default undefined
*/
branches?: number
/**
* Threshold for statements
*
* @default undefined
*/
statements?: number
}
export interface CoverageIstanbulOptions extends BaseCoverageOptions {
/**
* Set to array of class method names to ignore for coverage
*
* @default []
*/
ignoreClassMethods?: string[]
/**
* Watermarks for statements, lines, branches and functions.
*
* Default value is `[50,80]` for each property.
*/
watermarks?: {
statements?: [number, number]
functions?: [number, number]
branches?: [number, number]
lines?: [number, number]
}
}
export interface CoverageC8Options extends BaseCoverageOptions {
/**
* Allow files from outside of your cwd.
*
* @default false
*/
allowExternal?: boolean
/**
* Exclude coverage under `/node_modules/`
*
* @default true
*/
excludeNodeModules?: boolean
/**
* Specifies the directories that are used when `--all` is enabled.
*
* @default cwd
*/
src?: string[]
/**
* Shortcut for `--check-coverage --lines 100 --functions 100 --branches 100 --statements 100`
*
* @default false
*/
100?: boolean
}