Node.js
Jest CLI
Jest commands for JavaScript testing.
29 commands
Windows
MacOS
Linux
#testing
#javascript
Basic Execution
Run all tests in the project
jest
Run tests in a specific file
jest src/utils.test.js
Run tests serially in one process
jest --runInBand
Stop after the first test failure
jest --bail
Show individual test results
jest --verbose
Suppress console.log output
jest --silent
Watch Mode
Re-run tests on file changes
jest --watch
Watch all files for changes
jest --watchAll
Watch and run only changed tests
jest --watch --onlyChanged
Coverage
Run tests and collect coverage
jest --coverage
Show coverage in terminal only
jest --coverage --coverageReporters=text
Specify files to collect coverage from
jest --collectCoverageFrom="src/**/*.js"
Set minimum coverage thresholds
jest --coverageThreshold='{"global":{"branches":80}}'
Filtering
Run tests matching a file path pattern
jest --testPathPattern="api"
Run tests matching a name pattern
jest -t "should return 200"
Run tests for files changed since main
jest --changedSince=main
Run tests related to specific files
jest --findRelatedTests src/utils.js
Run tests for changes in last commit
jest --lastCommit
Configuration
Display the resolved Jest configuration
jest --showConfig
Create a Jest configuration file
jest --init
Use a custom configuration file
jest --config=jest.e2e.config.js
Run tests across multiple projects
jest --projects ./frontend ./backend
Debugging
Detect open handles preventing exit
jest --detectOpenHandles
Log heap usage after each test
jest --logHeapUsage
List all tests without running them
jest --listTests
Clear the Jest transform cache
jest --clearCache
Quick Commands
Run Jest in watch mode to re-run tests on file changes
jest --watch
Run all tests and generate a code coverage report
jest --coverage
Run only tests whose names match the given pattern
jest -t "should return 200"