Skip to content

[Bug]: --filter argument inconsistent with documentation #13222

Closed
@brunocabral88

Description

Version

v29.0.2

Steps to reproduce

  1. Install the latest version of Jest in a repository with existing test files
  2. Confirm Jest runs all your test files properly by running jest without arguments
  3. Create a file called filter.js in the current folder and paste the below contents
module.exports = testPaths => {
  return {
    filtered: testPaths,
  };
};
  1. Run jest --filter=<absolute-path>/filter.js

Expected behavior

I would expect Jest to run all the tests, considering I am not filtering any tests from the given input

Actual behavior

Jest outputs Pattern: - 0 matches

Additional context

This is not consistent with what the documentation (that can be found here) suggests.

From the docs:
Path to a module exporting a filtering function. This asynchronous function receives a list of test paths which can be manipulated to exclude tests from running by returning an object with the "filtered" property. Especially useful when used in conjunction with a testing infrastructure to filter known broken, e.g.

However, in the SearchSource.getTestPaths, we can see that it looks for a property called test in every item returned from the filter.

A workaround I did in my environment was to have it return the expected property, like below:

module.exports = (testPaths) => {
  ... code omitted ...
  return {
    filtered: testsToExecute.map((test) => ({ test })),
  };
}

We should probably either update the code so it only expects an array of string as the documentation suggests, or update the documentation to specify it requires the filtered property to have an array of shape { test: string}

Environment

System:
	OS: Windows 11 Home
	CPU: (8) x86-64
Binaries:
	Node: 16.14.0
	Yarn: 1.22.15
	npm: 8.3.1
npmPackages:
	jest: 29.0.2 (also tested on 26.6.3)

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions