jestjs/jest · error · Error
Both --onlyFailures and --watchAll were specified, only one
Error message
Both --onlyFailures and --watchAll were specified, only one is allowed.
What it means
A dedicated guard in `check` (packages/jest-cli/src/args.ts:37) forbids `--onlyFailures` together with `--watchAll`. `--onlyFailures` reads the previous run's results to select failed tests, while `--watchAll` triggers a full re-run on any change; the two selection strategies conflict and the failure cache is not maintained across watch reruns.
Source
Thrown at packages/jest-cli/src/args.ts:38
}
for (const key of [
'onlyChanged',
'lastCommit',
'changedFilesWithAncestor',
'changedSince',
]) {
if (argv[key] && argv.watchAll) {
throw new Error(
`Both --${key} and --watchAll were specified, but cannot be used ` +
'together. Try the --watch option which reruns only tests ' +
'related to changed files.',
);
}
}
if (argv.onlyFailures && argv.watchAll) {
throw new Error(
'Both --onlyFailures and --watchAll were specified, only one is allowed.',
);
}
if (argv.findRelatedTests && argv._.length === 0) {
throw new Error(
'The --findRelatedTests option requires file paths to be specified.\n' +
'Example usage: jest --findRelatedTests ./src/source.js ' +
'./src/index.js.',
);
}
if (
Object.prototype.hasOwnProperty.call(argv, 'maxWorkers') &&
argv.maxWorkers === undefined
) {
throw new Error(
'The --maxWorkers (-w) option requires a number or string to be specified.\n' +View on GitHub (pinned to f49721c78e)
Solutions
- Use `--watch` with `--onlyFailures` if available in your workflow, or run `--onlyFailures` once without watch.
- If you need continuous full re-runs, drop `--onlyFailures` and keep `--watchAll`.
Example fix
# before jest --onlyFailures --watchAll # after jest --onlyFailures # one-shot rerun of failures
Defensive patterns
Strategy: validation
Validate before calling
function validate(argv: { onlyFailures?: boolean; watchAll?: boolean }): void {
if (argv.onlyFailures && argv.watchAll) {
throw new Error('--onlyFailures cannot be combined with --watchAll');
}
} Type guard
const onlyFailuresWithWatchAll = (a: any) => Boolean(a.onlyFailures && a.watchAll);
Prevention
- Run --onlyFailures as a one-shot, not inside watchAll.
- Keep failure-rerun scripts separate from watch scripts.
When it happens
Trigger: `jest --onlyFailures --watchAll` or `jest -f --watchAll`.
Common situations: Wanting a watch loop that only re-runs failing tests; combining flags from different scripts.
Related errors
- Both --${key} and --watchAll were specified, but cannot be u
- The --maxWorkers (-w) option requires a number or string to
- Both --runInBand and --maxWorkers were specified, only one i
- The --findRelatedTests option requires file paths to be spec
- The --selectProjects option requires the name of at least on
AI-assisted analysis of jestjs/jest@f49721c78e (2026-08-03).
Data as JSON: /data/errors/48155784e9d35da1.json.
Report an issue: GitHub.