{"record":{"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":"exception","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/8e6d128e4a278059ecddecaa97400b04c8ae5fd9/packages/jest-cli/src/args.ts#L26-L62","documentation":"check() requires that --findRelatedTests be accompanied by at least one positional file path (args.ts:43-49). The flag tells Jest to compute the inverse dependency graph from those source files to their tests; with no files named (argv._.length === 0) there is nothing to relate, so Jest aborts rather than running the whole suite.","triggerScenarios":"Running jest --findRelatedTests with no trailing paths; a pre-commit hook invoking jest --findRelatedTests before any staged files were passed; a tool that strips positional args before forwarding to jest.","commonSituations":"husky/lint-staged misconfiguration that calls jest --findRelatedTests without interpolating the staged file list; running the flag manually to try it out; a glob-expansion step that produced zero files.","solutions":["Pass the source file paths after the flag: jest --findRelatedTests ./src/a.js ./src/b.js.","If automating via lint-staged, use the $eslint etc. variable substitution (e.g. 'jest --findRelatedTests').","Guard the hook so it only invokes jest when at least one file is staged."],"exampleFix":"// before\njest --findRelatedTests\n// after\njest --findRelatedTests ./src/source.js ./src/index.js","handlingStrategy":"validation","validationCode":"function runFindRelated(files: string[]): void {\n  if (files.length === 0) {\n    throw new Error('--findRelatedTests needs at least one file path');\n  }\n  // execa('jest', ['--findRelatedTests', ...files])\n}","typeGuard":"function hasPaths(files: unknown[]): files is string[] {\n  return files.length > 0 && files.every(f => typeof f === 'string');\n}","tryCatchPattern":null,"preventionTips":["In lint-staged, pass staged files via the substitution variable so the list is never empty.","Guard pre-commit hooks to skip jest when nothing is staged.","Document the expected invocation in your contributing guide."],"tags":["jest-cli","cli-args","findrelatedtests","precommit","missing-argument"],"backgroundTag":null,"analyzedSha":"8e6d128e4a278059ecddecaa97400b04c8ae5fd9","analyzedAt":"2026-08-10T18:11:27.960Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}