@naturalcycles/dev-lib 20.51.2 → 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.
@@ -34,6 +34,14 @@ export function getRootReporters(): InlineConfig['reporters']
34
34
  */
35
35
  export function getRootOutputFile(): InlineConfig['outputFile']
36
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
+
37
45
  export const CollectReporter: any
38
46
 
39
47
  export class SummaryReporter {}
@@ -94,30 +94,7 @@ export function getSharedConfig(cwd) {
94
94
  exclude,
95
95
  reporters: getReporters(junitReporterEnabled, testType),
96
96
  outputFile: getOutputFile(),
97
- coverage: {
98
- enabled: coverageEnabled,
99
- reporter: ['html', 'lcov', 'json', 'json-summary', !isCI && 'text'].filter(Boolean),
100
- include: ['src/**/*.{ts,tsx}'],
101
- exclude: [
102
- '**/__exclude/**',
103
- 'scripts/**',
104
- 'public/**',
105
- 'src/index.{ts,tsx}',
106
- 'src/test/**',
107
- 'src/typings/**',
108
- 'src/{env,environment,environments}/**',
109
- 'src/bin/**',
110
- 'src/vendor/**',
111
- '**/*.test.*',
112
- '**/*.script.*',
113
- '**/*.module.*',
114
- '**/*.mock.*',
115
- '**/*.page.{ts,tsx}',
116
- '**/*.component.{ts,tsx}',
117
- '**/*.directive.{ts,tsx}',
118
- '**/*.modal.{ts,tsx}',
119
- ],
120
- },
97
+ coverage: getCoverageConfig(),
121
98
  }
122
99
  }
123
100
 
@@ -187,6 +164,75 @@ export function getRootOutputFile() {
187
164
  return getOutputFile()
188
165
  }
189
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
+
190
236
  /**
191
237
  * The junit + json reporters, enabled in CI (except for manual tests).
192
238
  * Shared by the per-package (getReporters) and root (getRootReporters) configs.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@naturalcycles/dev-lib",
3
3
  "type": "module",
4
- "version": "20.51.2",
4
+ "version": "20.51.3",
5
5
  "dependencies": {
6
6
  "@naturalcycles/js-lib": "^15",
7
7
  "@naturalcycles/nodejs-lib": "^15",