@naturalcycles/dev-lib 20.50.0 → 20.51.1

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.
@@ -11,7 +11,11 @@ export class SummaryReporter {
11
11
  let stats = []
12
12
 
13
13
  for (const mod of testModules) {
14
- const name = mod.moduleId.split('/').at(-1)
14
+ // In the monorepo root run testModules span all projects, so prefix with the
15
+ // (short) package name to disambiguate identically-named files across packages.
16
+ const pkg = mod.project?.name?.split('/').at(-1)
17
+ const file = mod.moduleId.split('/').at(-1)
18
+ const name = pkg ? `${pkg} ${file}` : file
15
19
  const diag = mod.diagnostic()
16
20
  stats.push({ name, ms: diag.duration })
17
21
  }
@@ -20,6 +20,13 @@ export function defineVitestConfig(config?: Partial<ViteUserConfig>, cwd?: strin
20
20
  */
21
21
  export function getSharedConfig(cwd?: string): InlineConfig
22
22
 
23
+ /**
24
+ * Reporters for the monorepo root config (Vitest `projects` mode), where
25
+ * `reporters` is a root-only option. Returns the compact 'agent' reporter for
26
+ * agents, otherwise the default reporters plus a monorepo-wide SummaryReporter.
27
+ */
28
+ export function getRootReporters(): InlineConfig['reporters']
29
+
23
30
  export const CollectReporter: any
24
31
 
25
32
  export class SummaryReporter {}
@@ -128,16 +128,10 @@ export function getSharedConfig(cwd) {
128
128
  }
129
129
 
130
130
  function getReporters(junitReporterEnabled, testType) {
131
- // VITEST_REPORTER env var allows overriding the default reporter
132
- const { VITEST_REPORTER, GITHUB_ACTIONS } = process.env
133
- if (VITEST_REPORTER) {
134
- return [VITEST_REPORTER]
135
- }
136
-
137
- if (isAgent) {
138
- return ['agent']
139
- }
131
+ const override = getReporterOverride()
132
+ if (override) return override
140
133
 
134
+ const { GITHUB_ACTIONS } = process.env
141
135
  return [
142
136
  'default',
143
137
  GITHUB_ACTIONS && 'github-actions',
@@ -152,6 +146,50 @@ function getReporters(junitReporterEnabled, testType) {
152
146
  ].filter(Boolean)
153
147
  }
154
148
 
149
+ /**
150
+ * Reporters for the monorepo root config (Vitest `projects` mode).
151
+ *
152
+ * `reporters` is a root-only Vitest option: per-project reporters are ignored
153
+ * when running via `projects`. So the per-package SummaryReporter never runs in
154
+ * the aggregate root run, and - crucially - a root-level SummaryReporter sees
155
+ * the test modules of ALL projects at once, letting it report the slowest tests
156
+ * across the entire monorepo.
157
+ *
158
+ * Use it in the root vitest.config.ts:
159
+ *
160
+ * export default defineConfig({
161
+ * test: {
162
+ * projects: ['./packages/*'],
163
+ * reporters: getRootReporters(),
164
+ * },
165
+ * })
166
+ */
167
+ export function getRootReporters() {
168
+ const override = getReporterOverride()
169
+ if (override) return override
170
+
171
+ const { GITHUB_ACTIONS } = process.env
172
+ return ['default', GITHUB_ACTIONS && 'github-actions', new SummaryReporter()].filter(Boolean)
173
+ }
174
+
175
+ /**
176
+ * Reporter overrides shared by both the per-package and root configs:
177
+ * - VITEST_REPORTER env var fully replaces the reporter set
178
+ * - agents get the compact 'agent' reporter, with no summary
179
+ *
180
+ * Returns `undefined` when no override applies (caller uses its own defaults).
181
+ */
182
+ function getReporterOverride() {
183
+ const { VITEST_REPORTER } = process.env
184
+ if (VITEST_REPORTER) {
185
+ return [VITEST_REPORTER]
186
+ }
187
+ if (isAgent) {
188
+ return ['agent']
189
+ }
190
+ return undefined
191
+ }
192
+
155
193
  function doesItRunInIDE() {
156
194
  // example command line below:
157
195
  // /usr/local/bin/node /Users/some/Idea/some/node_modules/vitest/vitest.mjs --run --reporter /Users/some/Library/Application Support/JetBrains/IntelliJIdea2025.2/plugins/javascript-plugin/helpers/vitest-intellij/node_modules/vitest-intellij-reporter-safe.js --testNamePattern=^ ?case 001: empty data$ /Users/some/Idea/some/src/some/some.integration.test.ts
@@ -47,7 +47,11 @@ const commands = [
47
47
  fn: cleanBuild,
48
48
  desc: 'Cleans ./dist, then runs the build.',
49
49
  },
50
- { name: 'test', fn: runTest, desc: 'Run vitest for *.test.ts files.' },
50
+ {
51
+ name: 'test',
52
+ fn: runTest,
53
+ desc: 'Run vitest for *.test.ts files. Runs once and exits; pass --watch to watch.',
54
+ },
51
55
  {
52
56
  name: 'test-integration',
53
57
  fn: () => runTest({ integration: true }),
@@ -470,6 +470,13 @@ function runVitest(opt) {
470
470
  TEST_TYPE: 'manual',
471
471
  });
472
472
  }
473
+ // Default to "run once and exit" mode, rather than vitest's default of "watch"
474
+ // (which, in an interactive terminal, stays open waiting for input).
475
+ // Pass `--watch` (or `-w`, or the `watch` subcommand) explicitly to opt into watch mode.
476
+ const watch = args.some(a => a === '--watch' || a === '-w' || a === 'watch');
477
+ if (!watch) {
478
+ args.unshift('run');
479
+ }
473
480
  const vitestPath = findPackageBinPath('vitest', 'vitest');
474
481
  exec2.spawn(vitestPath, {
475
482
  args: _uniq(args),
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@naturalcycles/dev-lib",
3
3
  "type": "module",
4
- "version": "20.50.0",
4
+ "version": "20.51.1",
5
5
  "dependencies": {
6
6
  "@naturalcycles/js-lib": "^15",
7
7
  "@naturalcycles/nodejs-lib": "^15",