Search code examples
javascriptnpmjestjs

Run Jest tests only for current folder


I have Jest installed on my machine and typing jest from terminal results in tests from parent folers also getting executed. I want to run tests only from the current folder.

For e.g. if I go to c:/dev/app in terminal and type some-jest-command, it should only run files with .test.js present in the app folder. Currently, running jest command from app folder runs tests in parent folders too, which is not my desired behaviour.


Solution

  • By default, Jest will try to recursively test everything in whatever folder package.json is located.

    Let's say you're in c:/dev/app, and your package.json is in c:. If your basic command to invoke Jest is npm test, it'd recursively check for all tests in c:.For a specific folder like mentioned before, try running npm test dev/app.