Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(cli): updated documentation for --runTestsByPath command #14004

Merged
merged 5 commits into from Mar 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -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
Expand Down
34 changes: 33 additions & 1 deletion docs/CLI.md
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps to is worth mentioning that glob patterns can be used, if users shell is able to expand them?

For example, on Linux or macOS it is possible to run all tests in a folder like this:

jest --runTestsByPath __tests__/*

EDIT In the other hand, jest __tests__/* does the similar thing (just similar thing, because paths will be treated as patterns). Less typing. So probably there is no need to add anything. Sorry about the noise (;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem 👍
I used the test case introduced by the original commit as a guideline.

```

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

Expand Down
2 changes: 1 addition & 1 deletion e2e/__tests__/runTestsByPath.test.ts
Expand Up @@ -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);

Expand Down