diff --git a/CHANGELOG.md b/CHANGELOG.md index eaa379867814..08bf7637fc90 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ ### Chore & Maintenance +- `[docs]` Updated documentation for the `--runTestsByPath` CLI command ([#14004](https://github.com/facebook/jest/pull/14004)) + ### Performance ## 29.5.0 diff --git a/docs/CLI.md b/docs/CLI.md index 006980433554..a6b918f74ffc 100644 --- a/docs/CLI.md +++ b/docs/CLI.md @@ -372,7 +372,39 @@ Alias: `-i`. Run all tests serially in the current process, rather than creating ### `--runTestsByPath` -Run only the tests that were specified with their exact paths. +Run only the tests that were specified with their exact paths. This avoids converting them into a regular expression and matching it against every single file. + +For example, given the following file structure: + +```bash +__tests__ +└── t1.test.js # test +└── t2.test.js # test +``` + +When ran with a pattern, no test is found: + +```bash +jest --runTestsByPath __tests__/t +``` + +Output: + +```bash +No tests found +``` + +However, passing an exact path will execute only the given test: + +```bash +jest --runTestsByPath __tests__/t1.test.js +``` + +Output: + +```bash +PASS __tests__/t1.test.js +``` :::tip diff --git a/e2e/__tests__/runTestsByPath.test.ts b/e2e/__tests__/runTestsByPath.test.ts index 5ebf617ffb87..463d1fbf9467 100644 --- a/e2e/__tests__/runTestsByPath.test.ts +++ b/e2e/__tests__/runTestsByPath.test.ts @@ -28,7 +28,7 @@ test('runs tests by exact path', () => { expect(run1.stderr).toMatch('PASS __tests__/t1.test.js'); expect(run1.stderr).not.toMatch('PASS __tests__/t2.test.js'); - // When running with thte flag and a pattern, no test is found. + // When running with the flag and a pattern, no test is found. const run2 = runJest(DIR, ['--runTestsByPath', '__tests__/t']); expect(run2.stdout).toMatch(/no tests found/i);