Jest filter filter returns 0 matches

Viewed 25

I'm using Jest v26.6.3 and I'm trying to create a filter to programmatically select what tests to run.

I'm following the docs on how to setup a filter file, which seems simple enough, but jest returns Pattern: - 0 matches regardless of the pattern I specify.

PS: If I remove the filter from the CLI argument, jest is able to find/run the tests normally.

filter.js

module.exports = function(testPaths) {
  return {
    filtered: testPaths
  };
};

CLI

jest --filter=absolute\path\to\filter.js

I know it is picking up the file because I console'd testPaths and it output the file paths as expected.

Any ideas? Thanks!

1 Answers

For reference, in case anyone needs it in the future, looks like it's a bug in Jest (a bug request has been raised).

Jest expects an array of object with the test property set (instead of an array of strings as suggested by the docs) to the test file path, like below:

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

The above will obviously not filter anything, but you can implement your own rules before the method returns.

Related