Jest: --findRelatedTests overrides --testPathPattern

Created on 19 Dec 2017  路  11Comments  路  Source: facebook/jest

Do you want to request a _feature_ or report a _bug_?
Report what I believe is a bug (It doesn't seem to be expected behaviour from my research)

What is the current behavior?
I'm running jest --testPathPattern=PATTERN --findRelatedTests on a precommit hook with lint-staged and it runs tests that don't match with pattern

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.

Clone https://github.com/emilgoldsmith/jest-bug and you can try running yarn run correct-behaviour and yarn run buggy-behaviour to see the difference.

What is the expected behavior?
It should check for all related tests that they fit the testPathPattern, and in the case of yarn run buggy-behaviour it should return the exactly same as yarn run correct-behaviour, and therefore not find any tests.

Please provide your exact Jest configuration and mention your Jest, node,
yarn/npm version and operating system.

I'll just provide what I used in the example repo I created above:

node v9.3.0
yarn v1.3.2
default yarn configuration
OS: Ubuntu 16.04

Help Wanted

Most helpful comment

@jeysal Awesome I think I'm on the right track, might have a PR soon :)

All 11 comments

I agree it makes sense that testPathPattern is just a filter applied on top of files returned by findRelatedTests. PR welcome!

Might find time for a PR at some point, but for now if anyone else wants this functionality I just changed to using the --config option and using the testPathIgnorePatterns config option for the directory I wanted to exclude.

For those looking to help out on this one, this PR solves a similar problem and might be useful to check out: https://github.com/facebook/jest/pull/6736 馃檪

@emilgoldsmith

using the testPathIgnorePatterns config option for the directory I wanted to exclude.

doesn't work either. findRelatedTests overrides this key too

Hi @SimenB is this still something that needs attention?

@mackness I just double-checked, this bug still occurs, so yes a fix would be appreciated :)

Hi, I would appreciate it as well. 馃憤

@jeysal @natterstefan I am having a little bit of trouble figuring out where to get started with this issue but I am still looking into it!

@jeysal Do you think all of the changes will be isolated to this file: https://github.com/facebook/jest/blob/master/packages/jest-config/src/normalize.ts or do you think there are other parts of the codebase I should be considering?

Thanks for help!

@mackness Off the top of my head I think SearchSource would be where most (if not all) changes would be needed to implement this :)

@jeysal Awesome I think I'm on the right track, might have a PR soon :)

Hi @jeysal just want to make sure my change is headed in the right direction. If you think it make sense I can write a couple tests for _getTestPaths. Thanks for your help.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

StephanBijzitter picture StephanBijzitter  路  3Comments

Secretmapper picture Secretmapper  路  3Comments

hramos picture hramos  路  3Comments

stephenlautier picture stephenlautier  路  3Comments

rosiakr picture rosiakr  路  3Comments