@naturalcycles/dev-lib 20.51.1 → 20.51.3
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/cfg/vitest.config.d.ts +15 -0
- package/cfg/vitest.config.js +129 -39
- package/package.json +1 -1
package/cfg/vitest.config.d.ts
CHANGED
|
@@ -27,6 +27,21 @@ export function getSharedConfig(cwd?: string): InlineConfig
|
|
|
27
27
|
*/
|
|
28
28
|
export function getRootReporters(): InlineConfig['reporters']
|
|
29
29
|
|
|
30
|
+
/**
|
|
31
|
+
* `outputFile` for the junit/json reporters at the monorepo root config (Vitest
|
|
32
|
+
* `projects` mode), where `outputFile` is a root-only option. Pair it with
|
|
33
|
+
* getRootReporters so the junit/json report is written in the aggregate root run.
|
|
34
|
+
*/
|
|
35
|
+
export function getRootOutputFile(): InlineConfig['outputFile']
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* `coverage` for the monorepo root config (Vitest `projects` mode), where
|
|
39
|
+
* `coverage` is a root-only option. Without it on the root config no coverage
|
|
40
|
+
* report is produced when running via `projects`. Produces a single unified
|
|
41
|
+
* report spanning all projects.
|
|
42
|
+
*/
|
|
43
|
+
export function getRootCoverage(): InlineConfig['coverage']
|
|
44
|
+
|
|
30
45
|
export const CollectReporter: any
|
|
31
46
|
|
|
32
47
|
export class SummaryReporter {}
|
package/cfg/vitest.config.js
CHANGED
|
@@ -93,37 +93,8 @@ export function getSharedConfig(cwd) {
|
|
|
93
93
|
include,
|
|
94
94
|
exclude,
|
|
95
95
|
reporters: getReporters(junitReporterEnabled, testType),
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
? {
|
|
99
|
-
junit: `./tmp/jest/${testType}.xml`,
|
|
100
|
-
json: `./tmp/jest/${testType}.json`,
|
|
101
|
-
}
|
|
102
|
-
: undefined,
|
|
103
|
-
coverage: {
|
|
104
|
-
enabled: coverageEnabled,
|
|
105
|
-
reporter: ['html', 'lcov', 'json', 'json-summary', !isCI && 'text'].filter(Boolean),
|
|
106
|
-
include: ['src/**/*.{ts,tsx}'],
|
|
107
|
-
exclude: [
|
|
108
|
-
'**/__exclude/**',
|
|
109
|
-
'scripts/**',
|
|
110
|
-
'public/**',
|
|
111
|
-
'src/index.{ts,tsx}',
|
|
112
|
-
'src/test/**',
|
|
113
|
-
'src/typings/**',
|
|
114
|
-
'src/{env,environment,environments}/**',
|
|
115
|
-
'src/bin/**',
|
|
116
|
-
'src/vendor/**',
|
|
117
|
-
'**/*.test.*',
|
|
118
|
-
'**/*.script.*',
|
|
119
|
-
'**/*.module.*',
|
|
120
|
-
'**/*.mock.*',
|
|
121
|
-
'**/*.page.{ts,tsx}',
|
|
122
|
-
'**/*.component.{ts,tsx}',
|
|
123
|
-
'**/*.directive.{ts,tsx}',
|
|
124
|
-
'**/*.modal.{ts,tsx}',
|
|
125
|
-
],
|
|
126
|
-
},
|
|
96
|
+
outputFile: getOutputFile(),
|
|
97
|
+
coverage: getCoverageConfig(),
|
|
127
98
|
}
|
|
128
99
|
}
|
|
129
100
|
|
|
@@ -136,13 +107,7 @@ function getReporters(junitReporterEnabled, testType) {
|
|
|
136
107
|
'default',
|
|
137
108
|
GITHUB_ACTIONS && 'github-actions',
|
|
138
109
|
new SummaryReporter(),
|
|
139
|
-
junitReporterEnabled
|
|
140
|
-
junitReporterEnabled && [
|
|
141
|
-
'junit',
|
|
142
|
-
{
|
|
143
|
-
suiteName: `${testType} tests`,
|
|
144
|
-
},
|
|
145
|
-
],
|
|
110
|
+
...getJunitReporters(junitReporterEnabled, testType),
|
|
146
111
|
].filter(Boolean)
|
|
147
112
|
}
|
|
148
113
|
|
|
@@ -169,7 +134,132 @@ export function getRootReporters() {
|
|
|
169
134
|
if (override) return override
|
|
170
135
|
|
|
171
136
|
const { GITHUB_ACTIONS } = process.env
|
|
172
|
-
return [
|
|
137
|
+
return [
|
|
138
|
+
'default',
|
|
139
|
+
GITHUB_ACTIONS && 'github-actions',
|
|
140
|
+
new SummaryReporter(),
|
|
141
|
+
...getJunitReporters(junitReporterEnabled, testType),
|
|
142
|
+
].filter(Boolean)
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* `outputFile` for the junit/json reporters at the monorepo root config.
|
|
147
|
+
*
|
|
148
|
+
* Like `reporters`, `outputFile` is a root-only Vitest option: per-project
|
|
149
|
+
* `outputFile` is ignored when running via `projects`. So the root config must
|
|
150
|
+
* set it (alongside getRootReporters) for the junit/json report to be written
|
|
151
|
+
* in the aggregate root run.
|
|
152
|
+
*
|
|
153
|
+
* Use it in the root vitest.config.ts:
|
|
154
|
+
*
|
|
155
|
+
* export default defineConfig({
|
|
156
|
+
* test: {
|
|
157
|
+
* projects: ['./packages/*'],
|
|
158
|
+
* reporters: getRootReporters(),
|
|
159
|
+
* outputFile: getRootOutputFile(),
|
|
160
|
+
* },
|
|
161
|
+
* })
|
|
162
|
+
*/
|
|
163
|
+
export function getRootOutputFile() {
|
|
164
|
+
return getOutputFile()
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* `coverage` config for the monorepo root config (Vitest `projects` mode).
|
|
169
|
+
*
|
|
170
|
+
* Like `reporters` and `outputFile`, `coverage` is a root-only Vitest option:
|
|
171
|
+
* it is read from the root project only (see Vitest's `getRootProject().
|
|
172
|
+
* serializedConfig.coverage`), so the per-package `coverage` set in
|
|
173
|
+
* getSharedConfig is IGNORED when running via `projects`. Without this on the
|
|
174
|
+
* root config no coverage report is produced at all (e.g. the CI upload of
|
|
175
|
+
* ./coverage/coverage-summary.json finds nothing).
|
|
176
|
+
*
|
|
177
|
+
* The report is a single, unified one spanning all projects: Vitest tracks
|
|
178
|
+
* coverage per-project internally but emits one report under `./coverage`.
|
|
179
|
+
* Per-project coverage `include` globs are matched unanchored against absolute
|
|
180
|
+
* paths, so executed files under `packages/<pkg>/src/**` are still included.
|
|
181
|
+
*
|
|
182
|
+
* Use it in the root vitest.config.ts:
|
|
183
|
+
*
|
|
184
|
+
* export default defineConfig({
|
|
185
|
+
* test: {
|
|
186
|
+
* projects: ['./packages/*'],
|
|
187
|
+
* reporters: getRootReporters(),
|
|
188
|
+
* outputFile: getRootOutputFile(),
|
|
189
|
+
* coverage: getRootCoverage(),
|
|
190
|
+
* },
|
|
191
|
+
* })
|
|
192
|
+
*/
|
|
193
|
+
export function getRootCoverage() {
|
|
194
|
+
return getCoverageConfig()
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* The coverage config, shared by the per-package (getSharedConfig) and root
|
|
199
|
+
* (getRootCoverage) configs. Only enabled for CI unit-test runs.
|
|
200
|
+
*/
|
|
201
|
+
function getCoverageConfig() {
|
|
202
|
+
return {
|
|
203
|
+
enabled: coverageEnabled,
|
|
204
|
+
reporter: ['html', 'lcov', 'json', 'json-summary', !isCI && 'text'].filter(Boolean),
|
|
205
|
+
// `**/src/**` (not root-anchored `src/**`) so the report covers `src/` at the
|
|
206
|
+
// repo root AND in every monorepo package (`packages/<pkg>/src/**`). This
|
|
207
|
+
// matters in `projects` mode, where coverage is produced once at the root:
|
|
208
|
+
// a root-anchored glob would list only root `src/` as untested files, and
|
|
209
|
+
// package sources that no test imports would silently drop off the report.
|
|
210
|
+
// Vitest always appends `**/node_modules/**` to exclude, so `**/src/**` is
|
|
211
|
+
// safe. The exclude globs below are likewise `**/`-prefixed so they keep
|
|
212
|
+
// matching inside packages (e.g. `packages/<pkg>/src/test/**`).
|
|
213
|
+
include: ['**/src/**/*.{ts,tsx}'],
|
|
214
|
+
exclude: [
|
|
215
|
+
'**/__exclude/**',
|
|
216
|
+
'**/scripts/**',
|
|
217
|
+
'**/public/**',
|
|
218
|
+
'**/src/index.{ts,tsx}',
|
|
219
|
+
'**/src/test/**',
|
|
220
|
+
'**/src/typings/**',
|
|
221
|
+
'**/src/{env,environment,environments}/**',
|
|
222
|
+
'**/src/bin/**',
|
|
223
|
+
'**/src/vendor/**',
|
|
224
|
+
'**/*.test.*',
|
|
225
|
+
'**/*.script.*',
|
|
226
|
+
'**/*.module.*',
|
|
227
|
+
'**/*.mock.*',
|
|
228
|
+
'**/*.page.{ts,tsx}',
|
|
229
|
+
'**/*.component.{ts,tsx}',
|
|
230
|
+
'**/*.directive.{ts,tsx}',
|
|
231
|
+
'**/*.modal.{ts,tsx}',
|
|
232
|
+
],
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* The junit + json reporters, enabled in CI (except for manual tests).
|
|
238
|
+
* Shared by the per-package (getReporters) and root (getRootReporters) configs.
|
|
239
|
+
*/
|
|
240
|
+
function getJunitReporters(junitReporterEnabled, testType) {
|
|
241
|
+
if (!junitReporterEnabled) return []
|
|
242
|
+
return [
|
|
243
|
+
'json',
|
|
244
|
+
[
|
|
245
|
+
'junit',
|
|
246
|
+
{
|
|
247
|
+
suiteName: `${testType} tests`,
|
|
248
|
+
},
|
|
249
|
+
],
|
|
250
|
+
]
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* outputFile location is specified for compatibility with the previous jest config.
|
|
255
|
+
*/
|
|
256
|
+
function getOutputFile() {
|
|
257
|
+
return junitReporterEnabled
|
|
258
|
+
? {
|
|
259
|
+
junit: `./tmp/jest/${testType}.xml`,
|
|
260
|
+
json: `./tmp/jest/${testType}.json`,
|
|
261
|
+
}
|
|
262
|
+
: undefined
|
|
173
263
|
}
|
|
174
264
|
|
|
175
265
|
/**
|