Create-react-app: Tests outside of src folder shouldn't be run

Created on 2 Sep 2016  ยท  12Comments  ยท  Source: facebook/create-react-app

The README.md says:
The .test.js / .spec.js files (or the __tests__ folders) can be located at any depth under the src top level folder.

However, if I create a .spec.js in a e2e folder at the root of the project, it is still executed by npm test

image

I guess that's a bug. Right now I can workaround by overriding the testPathPattern parameter in my package.json: react-scripts test --env=jsdom --testPathPattern ./src\/.*

claimed starter bug

Most helpful comment

I'd like to place all test files outside of src. Do I need to eject?

All 12 comments

Interesting, thanks for writing up. I probably forgot to limit this. Now that I think of it I think maybe we should allow them to be in top level src, test, tests and __tests__.

Yup, as long as we can have e2e and integration tests living in the same repository, that seems fair

Is this issue still open? Can I jump on it?

This is a very annoying issue for us, since the workaround is adding --testPathPattern ./src\/.* to the test command but that makes jest runs all the tests at every change, and we can't filter by pattern.

If anyone has a better workaround that would be great !

Is this issue still open? Can I jump on it?

Yes, please!

Hmm. Not running tests in other folders will probably be a breaking change for some people since they might rely on some of these tests. So I'm retagging as 0.10.

Happy to take a PR fixing it.

This bit me again today. :cry: Specifically using Cloud9 editor with files in the /.c9 directory.

My work around was to move everything down into a new directory web, so that the tree became:

.
โ”œโ”€โ”€ .c9
โ”‚ย ย  โ””โ”€โ”€ ...
โ”œโ”€โ”€ .git
โ”‚ย ย  โ””โ”€โ”€ ...
โ””โ”€โ”€ web
    โ”œโ”€โ”€ .gitignore
    โ”œโ”€โ”€ README.md
    โ”œโ”€โ”€ node_modules
    โ”œโ”€โ”€ package.json
    โ”œโ”€โ”€ public
    โ””โ”€โ”€ src

@motevets would you like to take a stab at fixing this and submit a pull request? ๐Ÿ˜„

Fixed via #1808.

Please help beta test the new version that includes this change!
https://github.com/facebookincubator/create-react-app/issues/2172

I'd like to place all test files outside of src. Do I need to eject?

Any updates?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

barcher picture barcher  ยท  3Comments

Evan-GK picture Evan-GK  ยท  3Comments

fson picture fson  ยท  3Comments

JimmyLv picture JimmyLv  ยท  3Comments

stopachka picture stopachka  ยท  3Comments