π§ͺ Jest Test & Coverage Commands
The Early CLI agent uses customizable commands to run tests and collect coverage, allowing you to align with your projectβs Jest setup.
βοΈ Default Behaviorβ
The CLI agent expects two commands:
--test-command: Runs your Jest tests (after test generation)--coverage-command: Collects coverage data (used before and after test generation)
β Defaultsβ
If not specified, the agent uses:
--test-command "npx jest $early_filename --no-coverage --silent --json --forceExit --maxWorkers=1"
--coverage-command "npx jest --coverage --coverageProvider=v8 \
--coveragePathIgnorePatterns "node_modules" "dist" ".*\\.early\\.(spec|test)\\.[tj]sx?$" \
--coverageDirectory=$early_coverage_dir \
--silent --passWithNoTests --maxWorkers=2"
π¦ Behavior on Test Failuresβ
By default, if the test command reports any failing tests, the CLI will stop and the run will fail.
You can override this with:
--continue-on-test-errors
When this flag is present:
- The agent will continue generating tests, even if existing tests fail.
- However, if Jest itself fails to execute (for example, due to a configuration error or runtime crash), the agent will still stop.
π§© Purpose of Each Commandβ
1. π Coverage Command (Pre-generation)β
Before generating tests, the agent runs the coverage command to understand existing coverage across your codebase.
- The agent uses this data to focus on functions that are under-tested.
- If coverage collection fails, the agent will stop and report an error.
2. π§ͺ Test Command (Post-generation)β
After generating test files, the agent runs the test command to validate that:
- Generated tests are valid Jest tests
- All tests run and pass
- There are no syntax or runtime errors
The --test-command may run multiple times on the same file as the agent iteratively refines and validates generated tests before committing them. This ensures the final committed version passes successfully.
If
--continue-on-test-errorsis not provided, any test failures will halt the run.
Use this flag to allow test generation to proceed even when existing tests are broken.
3. π Coverage Command (Post-validation)β
Finally, the agent runs the coverage command again to compare coverage before and after test generation.
π Overriding the Commandsβ
You can override either or both commands using CLI flags:
--test-command "npx jest $early_filename --no-coverage --silent --json --forceExit --maxWorkers=1"
--coverage-command "npx jest --coverage --coverageProvider=v8 \
--coveragePathIgnorePatterns "node_modules" "dist" ".*\\.early\\.(spec|test)\\.[tj]sx?$" \
--coverageDirectory=$early_coverage_dir \
--silent --passWithNoTests --maxWorkers=2"
Make sure to retain these required placeholders:
$early_filenameβ The generated test file path--coverageDirectory=$early_coverage_dirβ Where coverage output should be stored--coverage--coverageProvider=v8--silent--passWithNoTests
π‘ Use Case: Custom Coverage Outputβ
Suppose you want the coverage output to be compatible with CI dashboards or reporting tools like Jest JUnit or Cobertura XML, and you'd like to include multiple coverage reporters in one run.
This would include:
- Generating JUnit-style test results (e.g., for GitHub Actions or Jenkins)
- Creating a Cobertura XML report
- Producing text and lcov reports for local and CI inspection
To do that, you can expand the default command as shown below.
π§ͺ Example: Extended Coverage Commandβ
Original command:
--coverage-command "npx jest --coverage --coverageProvider=v8 \
--coveragePathIgnorePatterns \"node_modules\" \"dist\" \".*\\.early\\.(spec|test)\\.[tj]sx?$\" \
--coverageDirectory=$early_coverage_dir \
--silent --passWithNoTests --maxWorkers=2"
Updated command with additional reporters:
--coverage-command "npx jest --coverage --coverageProvider=v8 \
--reporters=default --reporters=jest-junit \
--coverageReporters=text --coverageReporters=lcov --coverageReporters=cobertura \
--coveragePathIgnorePatterns \"node_modules\" \"dist\" \".*\\.early\\.(spec|test)\\.[tj]sx?$\" \
--coverageDirectory=$early_coverage_dir \
--silent --passWithNoTests --maxWorkers=2"
This command keeps the required $early_coverage_dir placeholder while enhancing the output for downstream processing.
β Placeholder Reminderβ
Both placeholders are required for correct operation. If omitted or renamed, the agent may fail.