@naturalcycles/dev-lib 20.51.1 → 20.51.2

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.
@@ -27,6 +27,13 @@ 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
+
30
37
  export const CollectReporter: any
31
38
 
32
39
  export class SummaryReporter {}
@@ -93,13 +93,7 @@ export function getSharedConfig(cwd) {
93
93
  include,
94
94
  exclude,
95
95
  reporters: getReporters(junitReporterEnabled, testType),
96
- // outputFile location is specified for compatibility with the previous jest config
97
- outputFile: junitReporterEnabled
98
- ? {
99
- junit: `./tmp/jest/${testType}.xml`,
100
- json: `./tmp/jest/${testType}.json`,
101
- }
102
- : undefined,
96
+ outputFile: getOutputFile(),
103
97
  coverage: {
104
98
  enabled: coverageEnabled,
105
99
  reporter: ['html', 'lcov', 'json', 'json-summary', !isCI && 'text'].filter(Boolean),
@@ -136,13 +130,7 @@ function getReporters(junitReporterEnabled, testType) {
136
130
  'default',
137
131
  GITHUB_ACTIONS && 'github-actions',
138
132
  new SummaryReporter(),
139
- junitReporterEnabled && 'json',
140
- junitReporterEnabled && [
141
- 'junit',
142
- {
143
- suiteName: `${testType} tests`,
144
- },
145
- ],
133
+ ...getJunitReporters(junitReporterEnabled, testType),
146
134
  ].filter(Boolean)
147
135
  }
148
136
 
@@ -169,7 +157,63 @@ export function getRootReporters() {
169
157
  if (override) return override
170
158
 
171
159
  const { GITHUB_ACTIONS } = process.env
172
- return ['default', GITHUB_ACTIONS && 'github-actions', new SummaryReporter()].filter(Boolean)
160
+ return [
161
+ 'default',
162
+ GITHUB_ACTIONS && 'github-actions',
163
+ new SummaryReporter(),
164
+ ...getJunitReporters(junitReporterEnabled, testType),
165
+ ].filter(Boolean)
166
+ }
167
+
168
+ /**
169
+ * `outputFile` for the junit/json reporters at the monorepo root config.
170
+ *
171
+ * Like `reporters`, `outputFile` is a root-only Vitest option: per-project
172
+ * `outputFile` is ignored when running via `projects`. So the root config must
173
+ * set it (alongside getRootReporters) for the junit/json report to be written
174
+ * in the aggregate root run.
175
+ *
176
+ * Use it in the root vitest.config.ts:
177
+ *
178
+ * export default defineConfig({
179
+ * test: {
180
+ * projects: ['./packages/*'],
181
+ * reporters: getRootReporters(),
182
+ * outputFile: getRootOutputFile(),
183
+ * },
184
+ * })
185
+ */
186
+ export function getRootOutputFile() {
187
+ return getOutputFile()
188
+ }
189
+
190
+ /**
191
+ * The junit + json reporters, enabled in CI (except for manual tests).
192
+ * Shared by the per-package (getReporters) and root (getRootReporters) configs.
193
+ */
194
+ function getJunitReporters(junitReporterEnabled, testType) {
195
+ if (!junitReporterEnabled) return []
196
+ return [
197
+ 'json',
198
+ [
199
+ 'junit',
200
+ {
201
+ suiteName: `${testType} tests`,
202
+ },
203
+ ],
204
+ ]
205
+ }
206
+
207
+ /**
208
+ * outputFile location is specified for compatibility with the previous jest config.
209
+ */
210
+ function getOutputFile() {
211
+ return junitReporterEnabled
212
+ ? {
213
+ junit: `./tmp/jest/${testType}.xml`,
214
+ json: `./tmp/jest/${testType}.json`,
215
+ }
216
+ : undefined
173
217
  }
174
218
 
175
219
  /**
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@naturalcycles/dev-lib",
3
3
  "type": "module",
4
- "version": "20.51.1",
4
+ "version": "20.51.2",
5
5
  "dependencies": {
6
6
  "@naturalcycles/js-lib": "^15",
7
7
  "@naturalcycles/nodejs-lib": "^15",