Skip to content

Commit a75ba48

Browse files
committed
Updated --filter documentation and fixed spacing issue as noticed by linter
1 parent f8a70c7 commit a75ba48

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- `[@jest/fake-timers]` [**BREAKING**] Upgrade `@sinonjs/fake-timers` to v11 ([#14544](https://github.com/jestjs/jest/pull/14544))
99
- `[@jest/schemas]` Upgrade `@sinclair/typebox` to v0.31 ([#14072](https://github.com/jestjs/jest/pull/14072))
1010
- `[pretty-format]` [**BREAKING**] Do not render empty string children (`''`) in React plugin ([#14470](https://github.com/facebook/jest/pull/14470))
11+
- `[@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))
1112

1213
### Fixes
1314

docs/CLI.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,13 +194,14 @@ Alias: `-e`. Use this flag to show full diffs and errors instead of a patch.
194194

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

197-
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.
197+
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.
198198

199199
```js title="my-filter.js"
200+
// 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):
201+
const filteringFunction = (testPath) => testPath.endsWith('.spec.js');
202+
200203
module.exports = testPaths => {
201-
const allowedPaths = testPaths
202-
.filter(filteringFunction)
203-
.map(test => ({test})); // [{ test: "path1.spec.js" }, { test: "path2.spec.js" }, etc]
204+
const allowedPaths = testPaths.filter(filteringFunction); // ["path1.spec.js", "path2.spec.js", etc]
204205

205206
return {
206207
filtered: allowedPaths,

packages/jest-core/src/__tests__/SearchSource.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ describe('SearchSource', () => {
113113
const {searchSource, config} = await initSearchSource(initialOptions);
114114
const {tests: paths} = await searchSource.getTestPaths(
115115
{
116-
...config,
116+
...config,
117117
testPathPattern: '',
118118
},
119119
null,

0 commit comments

Comments
 (0)