Jest: Ability to pass a path to a specific test file you want to run

Created on 6 Mar 2018  路  9Comments  路  Source: facebook/jest

I'd be willing to do the PR for this one and make it work. I'm mind blown that the entire library is based on regular expressions when it comes to resolving paths. I'm not really sure who made those decisions and why but not being able to pass a relative path to the file you want to run is mind-blowing.

Feature Request

Most helpful comment

I never said that that running a test by a filePath should exclude a config file. You can still pass a config file via --config flag. What I said is, it would be nice to provide a full path to a file that I want to run, without recursively running through every single folder looking for the string to match.

All 9 comments

@agjs sorry to hear about your mind exploding

You can pass the path to the file you want to test as long as your configured matchers allow for it. We tried allowing it to skip the matchers and it didn't work out. See here and the related links for more info

So your solution is to close the thread with "We failed to make it work so no one will"?

Amazing.

I think this is just a lack of feature. @rickhanlonii could close this issue just because it doesn't conform to provided issue template, so don't blame him ;)

I'll tag it as a feature request. Please provide how would you like this to work, e.g.:

jest --testPath ../my/path

Hi and thanks for reopening this.

CLI should work more or less just like any other test runner, mocha or similar. Your little example demonstrates how it should work.

One should simply be able to provide a path to a file and run that specific test. This shouldn't involve any pattern-matching but simply read the file path and execute that specific file.

My bad, @agjs! I assumed you were asking to do this without an extra CLI arg

For more context, we added support for this without an arg in https://github.com/facebook/jest/pull/3882, and decided to roll back in https://github.com/facebook/jest/pull/5544 and https://github.com/facebook/jest/pull/5582, since we decided that Jest should never run tests that are excluded through the config

I never said that that running a test by a filePath should exclude a config file. You can still pass a config file via --config flag. What I said is, it would be nice to provide a full path to a file that I want to run, without recursively running through every single folder looking for the string to match.

Are there any updates on this?

If you want to pass file paths in instead of pattern matching (for programmatic runs or similar), there is:
https://jestjs.io/docs/en/cli#runtestsbypath

Not sure I'm seeing the point of this feature request, but maybe I'm missing something?

--runTestsByPath covers the feature request I think. It was undocumented at the time this issue was opened, which might be why OP didn't know about it?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ianp picture ianp  路  3Comments

kentor picture kentor  路  3Comments

jardakotesovec picture jardakotesovec  路  3Comments

kgowru picture kgowru  路  3Comments

withinboredom picture withinboredom  路  3Comments