-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvitest.config.mts
More file actions
183 lines (177 loc) · 4.81 KB
/
vitest.config.mts
File metadata and controls
183 lines (177 loc) · 4.81 KB
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
/**
* @file Configuration - Vitest
* @module config/vitest
* @see https://vitest.dev/config
*/
import Notifier from '#tests/reporters/notifier'
import pathe from '@flex-development/pathe'
import { ok } from 'devlop'
import ci from 'is-ci'
import {
defineConfig,
type ConfigEnv,
type ViteUserConfig
} from 'vitest/config'
import type {
ResolveSnapshotPathHandlerContext,
TypecheckConfig
} from 'vitest/node'
import pkg from './package.json' with { type: 'json' }
import tsconfig from './tsconfig.json' with { type: 'json' }
export default defineConfig(config)
/**
* Create a vitest configuration.
*
* @see {@linkcode ConfigEnv}
* @see {@linkcode ViteUserConfig}
*
* @this {void}
*
* @param {ConfigEnv} env
* Configuration environment
* @return {ViteUserConfig}
* Root vitest configuration object
*/
function config(this: void, env: ConfigEnv): ViteUserConfig {
/**
* Options used to configure typechecks.
*
* @const {Partial<TypecheckConfig>} typecheck
*/
const typecheck: Partial<TypecheckConfig> = {
allowJs: false,
checker: 'tsc',
enabled: env.mode === 'typecheck',
ignoreSourceErrors: false,
include: ['**/__tests__/*.spec-d.mts'],
only: true,
tsconfig: 'tsconfig.json'
}
return {
test: {
allowOnly: !ci,
chaiConfig: {
includeStack: true,
showDiff: true,
truncateThreshold: 0
},
clearMocks: true,
coverage: {
clean: true,
cleanOnRerun: true,
exclude: [
'**/*.d.mts',
'**/__fixtures__/',
'**/__mocks__/',
'**/__tests__/',
'**/interfaces/',
'**/types/'
],
ignoreClassMethods: [],
include: ['src/**/**/*.mts'],
provider: 'v8',
reportOnFailure: !ci,
reporter: env.mode === 'reports'
? ['text']
: [ci ? 'lcovonly' : 'html', 'json-summary', 'text'],
reportsDirectory: './coverage',
skipFull: false,
thresholds: { 100: true, perFile: true }
},
globalSetup: [],
globals: true,
include: ['src/**/__tests__/*.spec.mts'],
mockReset: true,
outputFile: {
blob: pathe.join('.vitest-reports', env.mode + '.blob.json'),
json: pathe.join('__tests__', 'reports', env.mode + '.json'),
junit: pathe.join('__tests__', 'reports', env.mode + '.junit.xml')
},
passWithNoTests: true,
projects: [
{
extends: true,
resolve: {
conditions: [
'browser',
...tsconfig.compilerOptions.customConditions
]
},
test: {
env: { VITEST_ENVIRONMENT: 'happy-dom' },
environment: 'happy-dom',
environmentOptions: {},
name: 'browser',
setupFiles: [],
typecheck
}
},
{
extends: true,
ssr: {
resolve: { conditions: tsconfig.compilerOptions.customConditions }
},
test: {
env: { VITEST_ENVIRONMENT: 'node' },
environment: 'node',
environmentOptions: {},
name: 'node',
setupFiles: [],
typecheck
}
}
],
reporters: JSON.parse(process.env['VITEST_UI'] ?? '0')
? [new Notifier(), ['tree']]
: env.mode === 'reports'
? [['tree']]
: [
ci ? 'github-actions' : new Notifier(),
'blob',
'json',
['junit', { suiteName: pkg.name }],
['tree']
],
/**
* Store snapshots next to the directory of `file`.
*
* @this {void}
*
* @param {string} file
* Path to test file
* @param {string} extension
* Snapshot extension
* @param {ResolveSnapshotPathHandlerContext} context
* Snapshot path handler context
* @return {string}
* Custom snapshot path
*/
resolveSnapshotPath(
this: void,
file: string,
extension: string,
context: ResolveSnapshotPathHandlerContext
): string {
const { VITEST_ENVIRONMENT: environment } = context.config.env
ok(typeof environment === 'string', 'expected `VITEST_ENVIRONMENT`')
ok(environment, 'expected `VITEST_ENVIRONMENT`')
return pathe.resolve(
pathe.dirname(pathe.dirname(file)),
pathe.join('__snapshots__', environment),
pathe.basename(file).replace(/\.spec.mts/, '') + extension
)
},
restoreMocks: true,
setupFiles: ['./__tests__/setup/chai.mts'],
snapshotFormat: {
callToJSON: true,
min: false,
printBasicPrototype: false,
printFunctionName: true
},
snapshotSerializers: [],
unstubEnvs: true,
unstubGlobals: true
}
}
}