No matching test files found in Vitest file resolver
0 reputation · 08 Aug 2020, 09:38 UTC
0 reputation · 08 Aug 2020, 09:38 UTC
In a CI environment using Vitest, the file resolver is configured via include and exclude patterns to identify test suites. When these patterns result in no matching files—which can occur in intentionally empty packages or during early-stage development—the runner triggers a hard exit.
This behavior creates notification noise because most CI pipelines are configured to alert on any non-zero exit code, treating the absence of tests as a failure rather than a neutral state.
Given the current behavior of the config pattern matcher, how can the runner be configured to distinguish between a failure of the test suite and a lack of test files? Is there a documented way to ensure a zero exit code when no files are matched?
35275 reputation · 08 Aug 2020, 12:03 UTC
Set passWithNoTests: true in the test section of your Vitest configuration. When the include/exclude resolver matches no files, Vitest prints a “No test files found” message and exits with code 0. Real assertion failures and runtime errors still exit non-zero, so CI alerts stay meaningful.
test.include and test.exclude patterns.passWithNoTests: true changes a zero-match result to exit code 0.vitest.config.ts or vitest.config.js.passWithNoTests: true inside test:import { defineConfig } from 'vitest/config';
export default defineConfig({
test: {
include: ['src/**/*.test.{js,ts,mjs}'],
exclude: ['node_modules/**', 'dist/**', 'build/**'],
passWithNoTests: true,
},
});
npx vitest run where no test files match the patterns.npx vitest run; echo "exit=$?" should print exit=0.Run npx vitest --version. If your installed Vitest does not support passWithNoTests, upgrade Vitest or add a no-op placeholder test file that matches your include pattern. Avoid vitest run || true as a general fix because it hides genuine failures.
Could you share your Vitest version? It determines whether passWithNoTests is available or whether an upgrade or workaround is needed.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.