feat(docs): add tips for running Jest CLI (#6308)

Include running tests from a specific file and running a particular test in a file

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
Trang Le 2022-03-23 17:15:42 +07:00 committed by GitHub
parent df63380a82
commit 385614d20d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -190,6 +190,36 @@ When debugging the CMS with Git Gateway you must:
4. Refresh the page 4. Refresh the page
5. You should be able to log in via your Netlify Identity email/password 5. You should be able to log in via your Netlify Identity email/password
### Fine tune the way you run unit tests
There are situations where you would want to run a specific test file, or tests that match a certain pattern.
To run all the tests for a specific file, use this command:
```
yarn jest <filename or file path>
```
The first part of the command, `yarn jest` means running the locally installed version of `jest`. It is equivalent to running `node_modules/.bin/jest`.
Example for running all the tests for the file `gitlab.spec.js`: `yarn jest gitlab.spec.js`
Some test files like `API.spec.js` is available in several packages. You can pass a regexp pattern instead of file path to narrow down files.
Example for running all the tests for the file `API.spec.js` in the `netlify-cms-backend-gitlab` package:
`yarn jest ".+backend-gitlab/.+/API.spec.js`
To run a specific test in a file, add the flag `--testNamePattern`, or `-t` for short followed by a regexp to match your test name.
Example for running the test "should return true on project access_level >= 30" in the API.spec.js in `netlify-cms-backend-gitlab` package:
```
yarn jest -t "true on p" ".+backend-gitlab/.+/API.spec.js"
```
For more information about running tests exactly the way you want, check out the official documentation for [Jest CLI](https://jestjs.io/docs/cli).
## License ## License
By contributing to Netlify CMS, you agree that your contributions will be licensed By contributing to Netlify CMS, you agree that your contributions will be licensed