jest: Can't run a single test file specified by name via the CLI
The docs claim that I should be able to run jest path/to/my-test.js. When I do that, I get this error:
$ ./node_modules/.bin/jest /home/dandv/jest/my-test.js
No tests found
In /home/dandv/jest
2 files checked.
testMatch: **/__tests__/**/*.js?(x),**/?(*.)(spec|test).js?(x) - 1 match
testPathIgnorePatterns: /node_modules/ - 2 matches
Pattern: "/home/dandv/jest/my-test.js" - 0 matches
$ ls my-test.js
my-test.js
I’m using jest v20.0.4 and zsh. Running ./node_modules/.bin/jest ./my-test.js under bash produces the same No tests found result.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 1
- Comments: 24 (12 by maintainers)
The docs claim it works, and every single command-line build tool I’ve ever used that takes a file parameter, actually uses that particular file. Jest doesn’t, which is super counter-intuitive.
That will only hide the problem above.
I understand. Not sure I really have the time to dive into yet another new project right now though.
@thymikee: If I rename the file to
*.test.jsthat does match the default wildcard and the test runs, but that’s the point of the bug - Jest should run a specific test file that’s passed to it, regardless of the extension.@dandv I think it would be nice to make it work, but It’s not a priority. Feel free to work on this 😃
This still doesn’t seem fully fixed in 23.4.1 - files with other extensions (notably .mjs) aren’t found.
I think that regardless of the value of
testMatch, if I pass an explicit filename, jest should execute that test.Passing a matching wildcard to
--testMatchstill doesn’t work:Got a similar problem running in windows.
Running similar command on Mac the test is found.
Made a repo to reproduce it. https://github.com/lindgr3n/jest-single-test
Note: that running following works on windows so you can work around it in this case.
this version works as expected! Thanks. I see now that got jest as a transitive dependency and I am not in explicit control of it’s version… sorry for the confusion.
#3882
Alright @Hetachi, the thread bump worked. I’ll submit a PR after figuring out how to test this.
I assume the problem is that Jest is always using regex to match file names. When you are on Windows, and the path separator is
\, then passing full path to the test never works. The real use case is when you are using VS Code and there is a launch.json file to debug test:The macro
${file}will populate path using windows file separator\and as a result the whole thing will be incorrect regex expression. I would consider this issue as annoying bug rather than just an enhancement.Does it work when you pass only
my-test.js?