Skip to content

fix: add --roots flag to Jest to include test file directories#1212

Merged
misrasaurabh1 merged 2 commits into
mainfrom
fix/jest-roots-configuration
Jan 31, 2026
Merged

fix: add --roots flag to Jest to include test file directories#1212
misrasaurabh1 merged 2 commits into
mainfrom
fix/jest-roots-configuration

Conversation

@misrasaurabh1

Copy link
Copy Markdown
Contributor

Summary

  • Add --roots flag to Jest commands to include directories containing test files
  • This ensures Jest can find tests even when projects configure restricted roots (e.g., roots: ["<rootDir>/src"])

Problem

Some TypeScript/JavaScript projects configure Jest with roots: ["<rootDir>/src"] which excludes the test/ directory where codeflash writes generated tests. Even with --runTestsByPath, Jest validates that files exist within the configured roots, resulting in "No tests found" errors.

Solution

When running Jest with --runTestsByPath, also add --roots flags for each directory containing test files. This explicitly tells Jest to include those directories in its root paths, bypassing the project's restrictive configuration.

Test plan

  • Tested on appsmith project with roots: ["<rootDir>/src"] Jest config
  • Jest now finds and runs tests written to the test/ directory
  • Fix applied to all three Jest runner functions: behavioral, benchmarking, and line profiling

🤖 Generated with Claude Code

Some projects configure Jest with restricted roots (e.g., roots: ["<rootDir>/src"])
which prevents Jest from finding tests written to other directories like "test/".
Even with --runTestsByPath, Jest validates that files exist within the configured
roots.

This fix adds the --roots flag to explicitly include the directories containing
the test files being run, ensuring Jest can find and execute them regardless of
the project's roots configuration.

Fixes issue where "No tests found" error occurs on projects with custom Jest
roots configuration.
Add unit tests to verify that the --roots flag is properly added to Jest
commands for all three runner functions: behavioral, benchmarking, and
line profiling.
@misrasaurabh1 misrasaurabh1 merged commit 7cde435 into main Jan 31, 2026
22 of 24 checks passed
@misrasaurabh1 misrasaurabh1 deleted the fix/jest-roots-configuration branch January 31, 2026 01:31
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