{"record":{"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/8e6d128e4a278059ecddecaa97400b04c8ae5fd9/packages/jest-core/src/SearchSource.ts#L327-L363","documentation":"Thrown as a TypeError by SearchSource.getTestPaths when a filter function (configured via globalConfig.filter, pointing to a module exporting a filter function) is invoked and its return value does not have an Array .filtered property. The filter contract requires returning { filtered: string[] }.","triggerScenarios":"Writing a --filter module that returns a bare array, an object without 'filtered', undefined, or a promise that resolves to a non-conforming shape.","commonSituations":"Misunderstanding the filter file contract (developers often return an array of paths directly); partial migrations of filter scripts; async filters that forget to return the wrapped object.","solutions":["Make the filter module return { filtered: [...paths] }","If the filter is async, await and then return the wrapped object","Validate the return shape before exporting"],"exampleFix":"// before: filter.js\nmodule.exports = (testPaths) => testPaths;\n\n// after\nmodule.exports = (testPaths) => ({\n  filtered: testPaths.filter(p => p.includes('unit')),\n});","handlingStrategy":"validation","validationCode":"function assertFilterResult(result: unknown): asserts result is { filtered: string[] } {\n  if (!result || typeof result !== 'object' || !Array.isArray((result as any).filtered)) {\n    throw new TypeError('Filter must return { filtered: string[] }');\n  }\n}","typeGuard":"function isValidFilterResult(value: unknown): value is { filtered: string[] } {\n  return (\n    typeof value === 'object' &&\n    value !== null &&\n    Array.isArray((value as any).filtered) &&\n    (value as any).filtered.every((p: unknown) => typeof p === 'string')\n  );\n}","tryCatchPattern":null,"preventionTips":["Document the { filtered: string[] } contract at the top of your filter module","Add a unit test asserting the filter returns the wrapped shape","For async filters, ensure the returned (not awaited) value is still wrapped"],"tags":["core","filter","argument-validation","contract"],"backgroundTag":null,"analyzedSha":"8e6d128e4a278059ecddecaa97400b04c8ae5fd9","analyzedAt":"2026-08-10T18:11:27.960Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}