Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
brunocabral88 opened this issue Sep 7, 2022 · 5 comments · Fixed by #13329
Closed

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

brunocabral88 opened this issue Sep 7, 2022 · 5 comments · Fixed by #13329

Comments

@brunocabral88
Copy link
Contributor

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)
@jfw225
Copy link

jfw225 commented Sep 20, 2022

As mentioned in #12260, I believe the fix is fairly simple. Either update the documentation to specify that the return type is

type T = {
    filtered: { test: string }[];
};

or change this line SearchSource.js to

const filteredSet = new Set(filterResult.filtered);

I will say that the latter seems more clear as the current implementation seems redundant.

brunocabral88 added a commit to brunocabral88/jest that referenced this issue Sep 25, 2022
@brunocabral88
Copy link
Contributor Author

Thanks @jfw225, I think it makes more sense to just return an array of strings in the shape of { filtered: Array<string> }, considering the method accepts an array of strings too. I just created a PR for it.

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 30, 2022
@SimenB SimenB reopened this Sep 20, 2023
@jestjs jestjs unlocked this conversation Sep 20, 2023
@SimenB SimenB closed this as completed Sep 20, 2023
@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 21, 2023
@SimenB
Copy link
Member

SimenB commented Feb 20, 2024

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants