Skip to content

Commit

Permalink
Updated --filter documentation and fixed spacing issue as noticed by …
Browse files Browse the repository at this point in the history
…linter
  • Loading branch information
brunocabral88 committed Sep 21, 2023
1 parent f8a70c7 commit a75ba48
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -8,6 +8,7 @@
- `[@jest/fake-timers]` [**BREAKING**] Upgrade `@sinonjs/fake-timers` to v11 ([#14544](https://github.com/jestjs/jest/pull/14544))
- `[@jest/schemas]` Upgrade `@sinclair/typebox` to v0.31 ([#14072](https://github.com/jestjs/jest/pull/14072))
- `[pretty-format]` [**BREAKING**] Do not render empty string children (`''`) in React plugin ([#14470](https://github.com/facebook/jest/pull/14470))
- `[@jest/core]` [**BREAKING**] Changed `--filter` to accept an object with shape `{ filtered: Array<string> }` to match [documentation](https://jestjs.io/docs/cli#--filterfile) ([#13319](https://github.com/jestjs/jest/pull/13319))

### Fixes

Expand Down
9 changes: 5 additions & 4 deletions docs/CLI.md
Expand Up @@ -194,13 +194,14 @@ Alias: `-e`. Use this flag to show full diffs and errors instead of a patch.

### `--filter=<file>`

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 shape `{ filtered: Array<{ test: string }> }`. Especially useful when used in conjunction with a testing infrastructure to filter known broken tests, e.g.
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 and must return an object with shape `{ filtered: Array<string> }` containing the tests that should be run by Jest. Especially useful when used in conjunction with a testing infrastructure to filter known broken tests.

```js title="my-filter.js"
// This filter when applied will only run tests ending in .spec.js (not the best way to do it, but it's just an example):
const filteringFunction = (testPath) => testPath.endsWith('.spec.js');

module.exports = testPaths => {
const allowedPaths = testPaths
.filter(filteringFunction)
.map(test => ({test})); // [{ test: "path1.spec.js" }, { test: "path2.spec.js" }, etc]
const allowedPaths = testPaths.filter(filteringFunction); // ["path1.spec.js", "path2.spec.js", etc]

return {
filtered: allowedPaths,
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-core/src/__tests__/SearchSource.test.ts
Expand Up @@ -113,7 +113,7 @@ describe('SearchSource', () => {
const {searchSource, config} = await initSearchSource(initialOptions);
const {tests: paths} = await searchSource.getTestPaths(
{
...config,
...config,
testPathPattern: '',
},
null,
Expand Down

0 comments on commit a75ba48

Please sign in to comment.