Unexpected test file matching due to parent directory name interfere with `testRegex`
See original GitHub issueDo you want to request a feature or report a bug? bug
What is the current behavior?
Using config option testRegex
that does not include test/...
something, having tests in test/xxx.test.js
will still be run.
The example in my case is: { "testRegex": "src/.*\.test\.js$" }
If the current behavior is a bug, please provide the steps to reproduce and
either a repl.it demo through https://repl.it/languages/jest or a minimal
repository on GitHub that we can yarn install
and yarn test
.
See https://github.com/mraxus/jest-always-test-test and use commands yarn test
and yarn fail
to see expected/unexpected behaviour
What is the expected behaviour?
yarn fail
does not pass where it should.
Please provide your exact Jest configuration
module.exports = {
testEnvironment: 'node',
testRegex: 'test/unit/.*\\.test\\.js$',
};
vs
module.exports = {
testEnvironment: 'node',
testRegex: 'src/.*\\.test\\.js$',
};
Run npx envinfo --preset jest
in your project directory and paste the
results here
System:
OS: macOS High Sierra 10.13.4
CPU: x64 Intel(R) Core(TM) i5-7267U CPU @ 3.10GHz
Binaries:
Node: 8.11.1
Yarn: 1.5.1
npm: 5.8.0
npmPackages:
jest:
wanted: ^22.4.3
installed: 22.4.3
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (3 by maintainers)
Top GitHub Comments
@rickhanlonii I will check it out and see what I can provide!
So after some more troubleshooting with a colleague, I now understand what was going on. So I have the absolute path as
Users/me/src/js/project/
. And as he pointed out, the testRegex uses the absolute path, not relative, which is not stated in the docs.Personally I think the regex should only match the relative path as this is only what is relevant. Otherwise you get unexpected behaviour. Just like this case >p
But using the config:
testMatch: ['<rootDir>/src/**/*.test.js'],
then I can get the tests running as expected.So my suggestion would be to either:
testRegex
path relativeI will update the issue title