Skip to content

fix(test): pass --passWithNoTests to vitest#1240

Merged
John-David Dalton (jdalton) merged 2 commits intomainfrom
fix/test-passwithNoTests
Apr 21, 2026
Merged

fix(test): pass --passWithNoTests to vitest#1240
John-David Dalton (jdalton) merged 2 commits intomainfrom
fix/test-passwithNoTests

Conversation

@jdalton
Copy link
Copy Markdown
Contributor

@jdalton John-David Dalton (jdalton) commented Apr 18, 2026

Summary

  • When a scoped test run (pre-commit hook with `--staged`, or an edit that doesn't touch testable code) produces glob/arg patterns that match no test files, `vitest` exits with code 1 and "No test files found".
  • That's a false failure — a scope that happens to produce zero matches should succeed, not block a commit.
  • Add `--passWithNoTests` to the vitest args in `packages/cli/scripts/test-wrapper.mts` so the exit code reflects actual test outcomes.

Context

This is part of a cross-repo consistency pass — the same fix has been applied to socket-btm, socket-lib, socket-registry, socket-sdxgen, socket-packageurl-js, socket-tui, and socket-repo-template. socket-sdk-js has its own PR: SocketDev/socket-sdk-js#598

Test plan

  • Run `pnpm test` on a change that only touches non-test files (e.g. a README edit) — should no longer error
  • Run `pnpm test` that does touch tests — should still run and fail/pass correctly
  • Pre-commit hook passes on commits that don't affect tests

Note

Low Risk
Low risk: only changes the Vitest invocation flag so scoped runs with zero matched tests exit successfully; no production code paths are affected.

Overview
Updates the CLI test-wrapper.mts to always run Vitest with --passWithNoTests, so scoped/globbed test runs that match no files no longer fail with a non-zero exit code.

Adds a short inline comment explaining the pre-commit/scoped-run motivation.

Reviewed by Cursor Bugbot for commit 5748ddf. Configure here.

When a scoped test run (e.g. pre-commit hook with --staged, or an edit
that doesn't touch testable code) produces glob/arg patterns that match
no test files, vitest exits 1 with "No test files found". That's a false
positive — a scope producing zero matches should succeed, not block a
commit.

Add --passWithNoTests so the exit code reflects test outcomes, not
whether the patterns happened to match files.
`result?.code || 0` coerced a `null` exit code (signal-killed, e.g.
SIGKILL / SIGABRT) into 0, so a crashed test runner reported success
to the pre-commit hook. Check for a numeric code and fall back to
exitCode=1 otherwise.
@jdalton John-David Dalton (jdalton) merged commit d1f0266 into main Apr 21, 2026
13 checks passed
@jdalton John-David Dalton (jdalton) deleted the fix/test-passwithNoTests branch April 21, 2026 14:51
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.

2 participants