{"id":"cc31530286d2a0e9","repo":"jestjs/jest","slug":"the-findrelatedtests-option-requires-file-paths","errorCode":null,"errorMessage":"The --findRelatedTests option requires file paths to be specified.\nExample usage: jest --findRelatedTests ./src/source.js ./src/index.js.","messagePattern":"The --findRelatedTests option requires file paths to be specified\\.\nExample usage: jest --findRelatedTests \\./src/source\\.js \\./src/index\\.js\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/jest-cli/src/args.ts","lineNumber":44,"sourceCode":"    'changedSince',\n  ]) {\n    if (argv[key] && argv.watchAll) {\n      throw new Error(\n        `Both --${key} and --watchAll were specified, but cannot be used ` +\n          'together. Try the --watch option which reruns only tests ' +\n          'related to changed files.',\n      );\n    }\n  }\n\n  if (argv.onlyFailures && argv.watchAll) {\n    throw new Error(\n      'Both --onlyFailures and --watchAll were specified, only one is allowed.',\n    );\n  }\n\n  if (argv.findRelatedTests && argv._.length === 0) {\n    throw new Error(\n      'The --findRelatedTests option requires file paths to be specified.\\n' +\n        'Example usage: jest --findRelatedTests ./src/source.js ' +\n        './src/index.js.',\n    );\n  }\n\n  if (\n    Object.prototype.hasOwnProperty.call(argv, 'maxWorkers') &&\n    argv.maxWorkers === undefined\n  ) {\n    throw new Error(\n      'The --maxWorkers (-w) option requires a number or string to be specified.\\n' +\n        'Example usage: jest --maxWorkers 2\\n' +\n        'Example usage: jest --maxWorkers 50%\\n' +\n        'Or did you mean --watch?',\n    );\n  }\n","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/jestjs/jest/blob/f49721c78e195558b40913977c9230f5b7f559d8/packages/jest-cli/src/args.ts#L26-L62","documentation":"`check` throws (packages/jest-cli/src/args.ts:43) when `--findRelatedTests` is set but no positional file paths were given (`argv._.length === 0`). findRelatedTests works by mapping source file paths to their dependent tests, so without input paths Jest has nothing to query.","triggerScenarios":"Thrown at packages/jest-cli/src/args.ts:44 when the library encounters an invalid state.","commonSituations":"Pre-commit hooks where the staged-file list is empty for non-JS commits; shell scripts that build the file list with a glob that expanded to nothing.","solutions":["Pass the source file paths explicitly: `jest --findRelatedTests ./src/a.js ./src/b.js`.","In a pre-commit hook, guard the call so jest is only invoked when the file list is non-empty (e.g. `if [ -n \"$FILES\" ]; then jest --findRelatedTests $FILES; fi`).","Use `--listTests --findRelatedTests` first to verify which paths resolve."],"exampleFix":"# before (husky pre-commit)\njest --findRelatedTests $(git diff --cached --name-only)\n\n# after\nFILES=$(git diff --cached --name-only --diff-filter=ACM | grep -E '\\.(js|ts|jsx|tsx)$')\n[ -n \"$FILES\" ] && jest --findRelatedTests $FILES || echo 'no JS files staged'","handlingStrategy":"validation","validationCode":"function ensureRelatedFiles(files: string[]): string[] {\n  if (files.length === 0) throw new Error('--findRelatedTests needs at least one file path');\n  return files;\n}","typeGuard":"const hasPositionalFiles = (argv: any) => Array.isArray(argv._) && argv._.length > 0;","tryCatchPattern":null,"preventionTips":["In git hooks, only invoke jest --findRelatedTests when staged JS/TS files exist.","Use lint-staged to pass files only when present.","Add `[ -n \"$FILES\" ] &&` guards in shell scripts."],"tags":["jest-cli","cli-args","findrelatedtests","precommit"],"analyzedSha":"f49721c78e195558b40913977c9230f5b7f559d8","analyzedAt":"2026-08-03T20:16:28.571Z","schemaVersion":2}