From 613f25b643988e59e5266223ce2279ab5a63d696 Mon Sep 17 00:00:00 2001 From: Gramsco <45275394+gramsco@users.noreply.github.com> Date: Tue, 3 May 2022 15:30:51 +0200 Subject: [PATCH 1/4] Update documentation (see #12260) This PR specifies how to use the filtering function CLI option. --- website/versioned_docs/version-28.0/CLI.md | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/website/versioned_docs/version-28.0/CLI.md b/website/versioned_docs/version-28.0/CLI.md index 694de03a17cb..4ea73b5a6562 100644 --- a/website/versioned_docs/version-28.0/CLI.md +++ b/website/versioned_docs/version-28.0/CLI.md @@ -204,7 +204,18 @@ Alias: `-e`. Use this flag to show full diffs and errors instead of a patch. ### `--filter=` -Path to a module exporting a filtering function. This method receives a list of tests which can be manipulated to exclude tests from running. Especially useful when used in conjunction with a testing infrastructure to filter known broken. +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. + +```javascript +// my-filter.js +module.exports = (testPaths) => { + const allowedPaths = testPaths.filter(filteringFunction) // ["path1.spec.js", "path2.spec.js", etc] + return { + filtered : allowedPaths, + } +} +``` + ### `--findRelatedTests ` From e02f6b36e6f5671f9cbdfd87221e87974eeac899 Mon Sep 17 00:00:00 2001 From: Gramsco <45275394+gramsco@users.noreply.github.com> Date: Tue, 3 May 2022 15:37:28 +0200 Subject: [PATCH 2/4] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c4895d250a34..bc615f9909de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ ### Chore & Maintenance +- `[docs]` Specified documentation about `--filter` CLI docs ([#12799](https://github.com/facebook/jest/pull/12799)) - `[@jest-reporters]` Move helper functions from `utils.ts` into separate files ([#12782](https://github.com/facebook/jest/pull/12782)) - `[jest-resolve]` Replace `process.versions.pnp` type declaration with `@types/pnpapi` devDependency ([#12783](https://github.com/facebook/jest/pull/12783)) From 978629d6afcbeeffb15c62893c4baac0c104b759 Mon Sep 17 00:00:00 2001 From: Gramsco <45275394+gramsco@users.noreply.github.com> Date: Tue, 3 May 2022 15:43:28 +0200 Subject: [PATCH 3/4] Update website/versioned_docs/version-28.0/CLI.md Co-authored-by: Tom Mrazauskas --- website/versioned_docs/version-28.0/CLI.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/website/versioned_docs/version-28.0/CLI.md b/website/versioned_docs/version-28.0/CLI.md index 4ea73b5a6562..ab25c63c2658 100644 --- a/website/versioned_docs/version-28.0/CLI.md +++ b/website/versioned_docs/version-28.0/CLI.md @@ -206,8 +206,7 @@ Alias: `-e`. Use this flag to show full diffs and errors instead of a patch. 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. -```javascript -// my-filter.js +```js title="my-filter.js" module.exports = (testPaths) => { const allowedPaths = testPaths.filter(filteringFunction) // ["path1.spec.js", "path2.spec.js", etc] return { From 59119769b645f825f3965ec902e47118eb6209e9 Mon Sep 17 00:00:00 2001 From: Antonin Gauthier Date: Thu, 5 May 2022 19:26:55 +0200 Subject: [PATCH 4/4] update docs/CLI.mod ran prettier --- docs/CLI.md | 11 ++++++++++- website/versioned_docs/version-28.0/CLI.md | 11 +++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/docs/CLI.md b/docs/CLI.md index 694de03a17cb..b070f975a2dd 100644 --- a/docs/CLI.md +++ b/docs/CLI.md @@ -204,7 +204,16 @@ Alias: `-e`. Use this flag to show full diffs and errors instead of a patch. ### `--filter=` -Path to a module exporting a filtering function. This method receives a list of tests which can be manipulated to exclude tests from running. Especially useful when used in conjunction with a testing infrastructure to filter known broken. +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. + +```js title="my-filter.js" +module.exports = testPaths => { + const allowedPaths = testPaths.filter(filteringFunction); // ["path1.spec.js", "path2.spec.js", etc] + return { + filtered: allowedPaths, + }; +}; +``` ### `--findRelatedTests ` diff --git a/website/versioned_docs/version-28.0/CLI.md b/website/versioned_docs/version-28.0/CLI.md index ab25c63c2658..b070f975a2dd 100644 --- a/website/versioned_docs/version-28.0/CLI.md +++ b/website/versioned_docs/version-28.0/CLI.md @@ -207,15 +207,14 @@ Alias: `-e`. Use this flag to show full diffs and errors instead of a patch. 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. ```js title="my-filter.js" -module.exports = (testPaths) => { - const allowedPaths = testPaths.filter(filteringFunction) // ["path1.spec.js", "path2.spec.js", etc] +module.exports = testPaths => { + const allowedPaths = testPaths.filter(filteringFunction); // ["path1.spec.js", "path2.spec.js", etc] return { - filtered : allowedPaths, - } -} + filtered: allowedPaths, + }; +}; ``` - ### `--findRelatedTests ` Find and run the tests that cover a space separated list of source files that were passed in as arguments. Useful for pre-commit hook integration to run the minimal amount of tests necessary. Can be used together with `--coverage` to include a test coverage for the source files, no duplicate `--collectCoverageFrom` arguments needed.