{"id":"57ae1318d876d18f","repo":"jestjs/jest","slug":"filter-filterpath-did-not-return-a-valid-test-l","errorCode":null,"errorMessage":"Filter ${filterPath} did not return a valid test list","messagePattern":"Filter (.+?) did not return a valid test list","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/jest-core/src/SearchSource.ts","lineNumber":345,"sourceCode":"    projectConfig: Config.ProjectConfig,\n    changedFiles?: ChangedFiles,\n    filter?: Filter,\n  ): Promise<SearchResult> {\n    const searchResult = await this._getTestPaths(\n      globalConfig,\n      projectConfig,\n      changedFiles,\n    );\n\n    const filterPath = globalConfig.filter;\n\n    if (filter) {\n      const tests = searchResult.tests;\n\n      const filterResult = await filter(tests.map(test => test.path));\n\n      if (!Array.isArray(filterResult.filtered)) {\n        throw new TypeError(\n          `Filter ${filterPath} did not return a valid test list`,\n        );\n      }\n\n      const filteredSet = new Set(filterResult.filtered);\n\n      return {\n        ...searchResult,\n        tests: tests.filter(test => filteredSet.has(test.path)),\n      };\n    }\n\n    return searchResult;\n  }\n\n  async findRelatedSourcesFromTestsInChangedFiles(\n    changedFilesInfo: ChangedFiles,\n  ): Promise<Array<string>> {","sourceCodeStart":327,"sourceCodeEnd":363,"githubUrl":"https://github.com/jestjs/jest/blob/f49721c78e195558b40913977c9230f5b7f559d8/packages/jest-core/src/SearchSource.ts#L327-L363","documentation":"When the --filter option points to a JS module, Jest calls it with the list of test paths and expects back an object with a `filtered` array property (the subset to run). If the returned value is not an array at `.filtered`, this TypeError is thrown. The filter contract is {filtered: string[]}.","triggerScenarios":"A filter module that returns {tests: [...]} instead of {filtered: [...]}, returns null/undefined, or returns a bare array.","commonSituations":"Writing a custom --filter script and guessing the return shape; an outdated filter from an older Jest version; a filter that throws and yields undefined.","solutions":["Return exactly {filtered: [...paths]} from the filter module","Ensure the filter does not throw and always returns the object","Consult the --filter docs for the expected contract"],"exampleFix":"// before\nmodule.exports = (tests) => ({tests});\n// after\nmodule.exports = (tests) => ({filtered: tests.filter(t => t.includes('unit'))});","handlingStrategy":"type-guard","validationCode":"function assertFilterResult(r: unknown): asserts r is {filtered: string[]} {\n  if (!r || !Array.isArray((r as any).filtered)) {\n    throw new TypeError('--filter module must return {filtered: string[]}');\n  }\n}","typeGuard":"function isFilterResult(r: unknown): r is {filtered: readonly string[]} {\n  return typeof r === 'object' && r !== null &&\n    Array.isArray((r as {filtered: unknown}).filtered);\n}","tryCatchPattern":null,"preventionTips":["Match the documented {filtered: string[]} contract exactly","Unit-test the filter module's return shape"],"tags":["cli","filter","config"],"analyzedSha":"f49721c78e195558b40913977c9230f5b7f559d8","analyzedAt":"2026-08-03T20:16:28.571Z","schemaVersion":2}