Skip to content

fix: honor user-supplied test.root instead of clobbering it#37

Draft
gaurav-rk9 wants to merge 1 commit into
fremtind:mainfrom
gaurav-rk9:honor-user-test-root
Draft

fix: honor user-supplied test.root instead of clobbering it#37
gaurav-rk9 wants to merge 1 commit into
fremtind:mainfrom
gaurav-rk9:honor-user-test-root

Conversation

@gaurav-rk9

@gaurav-rk9 gaurav-rk9 commented Jun 29, 2026

Copy link
Copy Markdown

Problem

The generated Vitest config unconditionally set config.test.root to the generated config's directory (the target's Bazel package dir), discarding any test.root set in the user's config:

config.test.root = vitestConfigDir; // always overwrote the user's value

So an explicit test.root in a user config had no effect.

Fix (scoped to honoring an override; default unchanged)

  • An explicit test.root in the user config is now honored; a relative value is resolved against the user config file's directory, matching Vitest's own behavior.
  • When test.root is not set, it still defaults to the generated config's directory (the package dir) — default behavior is unchanged.
  • Coverage include globs resolve against the effective root. Because Vitest silently drops include globs outside test.root (allowExternal: false), a warning is emitted when covered sources fall outside an explicit root, rather than silently producing empty coverage.

Tests

  • case13 — explicit relative test.root; proves the user value is honored and discovery (--dir) stays independent of root.
  • case14 — coverage with a subdirectory config (e2e).
  • case15 — coverage with an explicit test.root (e2e).

All existing tests plus the new cases and coverage e2e pass locally.

@gaurav-rk9 gaurav-rk9 force-pushed the honor-user-test-root branch from 2492f7f to c808c4e Compare June 29, 2026 14:33
The generated vitest config unconditionally set `config.test.root` to the
generated config's directory (the target's package dir), discarding any
`test.root` set in the user's config.

Now an explicit `test.root` in the user config is honored (relative values
resolved against the user config file's directory, as Vitest would). When
`test.root` is not set, it still defaults to the generated config's directory,
so the default behavior is unchanged.

Coverage `include` globs resolve against the effective root, with a warning
when covered sources fall outside an explicit root (Vitest silently drops
such globs).

Adds cases 13-15 covering an explicit relative test.root, coverage with a
subdirectory config, and coverage with an explicit root.
@gaurav-rk9 gaurav-rk9 force-pushed the honor-user-test-root branch from c808c4e to 2b5e416 Compare June 29, 2026 17:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant