Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to add folders to have jest ignore #1299

Closed
chrisdrackett opened this issue Dec 20, 2016 · 14 comments
Closed

Ability to add folders to have jest ignore #1299

chrisdrackett opened this issue Dec 20, 2016 · 14 comments
Milestone

Comments

@chrisdrackett
Copy link
Contributor

We currently have a couple of submodules that are outside of the src directory that we would like jest to ignore. The only way we've found to do this currently is to replace the test script with one of our own. While this isn't a big deal, it would be nice to be able to ignore these directories within our package.json

@robcaldecott
Copy link

We're facing this with a Cordova app where Jest is trying to run tests in the plugins folder so a solution to this would be welcome: even if it means using a custom script (but not if it means ejecting!) Can you share your custom script please chrisdrackett?

@chrisdrackett
Copy link
Contributor Author

@jonahfang
Copy link

I have a .vim dir inside the project root, when I run npm test and select a(all), jest scan the .vim dir:

 PASS  src/App.test.js
 FAIL  .vim/.vimundo/%src%src%App.test.js
  ● Test suite failed to run

    SyntaxError: /Users/fzx/adev/ra/demo/.vim/.vimundo/%src%src%App.test.js: Unexpected character '�' (1:3)
    > 1 | Vim�UnDo��'�Jx�Z2��@o'��0��~��_hhh�H
        |    ^
      2 | """"Xh�b_�����Xh��5�_�����Xh���	�	5�_�����==V=Xh�3�
      3 | �	5�_����==V=Xh�:�
      4 | 	import ''5�_�	����==V=Xh�<�

      at Parser.pp$5.raise (node_modules/.6.14.1@babylon/lib/index.js:4246:13)
      at Parser.getTokenFromCode (node_modules/.6.14.1@babylon/lib/index.js:1065:10)
      at Parser.readToken (node_modules/.6.14.1@babylon/lib/index.js:694:19)
      at Parser.<anonymous> (node_modules/.6.14.1@babylon/lib/index.js:6435:20)
      at Parser.readToken (node_modules/.6.14.1@babylon/lib/index.js:5370:22)
      at Parser.nextToken (node_modules/.6.14.1@babylon/lib/index.js:684:19)
      at Parser.next (node_modules/.6.14.1@babylon/lib/index.js:609:10)
      at Parser.pp$3.parseIdentifier (node_modules/.6.14.1@babylon/lib/index.js:4131:8)
      at Parser.pp$3.parseExprAtom (node_modules/.6.14.1@babylon/lib/index.js:3484:21)
      at Parser.parseExprAtom (node_modules/.6.14.1@babylon/lib/index.js:6402:22)

@cdaringe
Copy link

cdaringe commented Jan 8, 2017

Are there not CLI flags your can pass to npm test to handle this? ARGS after npm test -- ... are passed to jest. There's also a custom config file you can use, https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/utils/createJestConfig.js#L18

@gaearon
Copy link
Contributor

gaearon commented Feb 11, 2017

Closing as a duplicate of #544.
We should just fix that instead.

@gaearon gaearon closed this as completed Feb 11, 2017
@gaearon gaearon added this to the 0.9.1 milestone Feb 11, 2017
@gaearon gaearon modified the milestones: 0.9.2, 0.9.1 Feb 24, 2017
@ryansully
Copy link
Contributor

ryansully commented Feb 26, 2017

While this issue was based upon ignoring a folder outside src, I have a very similar use case regarding a file/folder inside src. My solution has been exactly the same as @chrisdrackett: to copy test.js and modify it to allow exclusions, which is not very DRY or ideal.

Because of that use case, I think it is relevant to the original request of this issue, to have the ability to add folders (and files) to have Jest ignore, and subsequently I don't think that this is necessarily a duplicate of #544. I would still like to see some sort of ignore/exclude functionality that applies not only to files/folders outside src, but inside as well.

@gaearon
Copy link
Contributor

gaearon commented Feb 26, 2017

Can you explain more about your use case? The comment about submodules mentioned they're outside src.

@ryansully
Copy link
Contributor

Actually, my use case is better exemplified by #1455, so I'll defer to that issue instead of continuing discussion in this one.

@z-vr
Copy link

z-vr commented May 17, 2017

@gaearon It'd be great to be able to exclude files from jest. E.g., if I have some test lib with functions commonly used by differennt tests, I can't put it in the __tests__ directory, because jest will complain that a test suite must export at least one test.

@gaearon
Copy link
Contributor

gaearon commented May 17, 2017

We are only running tests inside src in next release if it helps. You can try the next release with canary version of react-scripts.

I'm not sure what you mean by your question though. A specific example would help.

@z-vr
Copy link

z-vr commented May 17, 2017

@gaearon

> src/__tests__
testA.test.js
testB.test.js
data.json
normalised-test-data.js

testA: import data from './normalised-test-data.js; ...,
testB: import data from './normalised-test-data.js; ...,
normalised-test-data:

import data from './data.json'; 
export default const normalisedData = data.filter((el, i, arr) => err.indexOf(el) === i);

FAIL src/__tests__/normalised-test-data.js

  • Test suite failed to run

    Your test suite must contain at least one test.

@gaearon
Copy link
Contributor

gaearon commented May 17, 2017

Right, but why do you need to put normalised-test-data.js into __tests__? You can put it outside of the folder.

@devonjs
Copy link

devonjs commented Feb 26, 2018

Can you explain more about your use case? The comment about submodules mentioned they're outside src.

@gaearon how would you go about handling submodules within the src file? Our use case is that the submodule runs tests in a different testEnvironment than the main React app (node instead of jsdom because we've encountered some issues with request headers in the jsdom environment).

We're using old react-scripts 0.9.5 right now, which uses an older version of Jest that does not support specifying different testEnvironments seen here

I'm completely open to moving the submodule outside of the src and then excluding it from the coverage report as mentioned in #1455, if thats the case, what would be the CRA recommended folder for that?

@woile
Copy link

woile commented Mar 25, 2018

Hi i'm having a similar issue, I have fakers inside the __tests__ folder, I believe they belong there. It would be awesome to have a way to ignore a folder or files.

Right now I'm planning on solving this by moving them outside the __tests__ folder.

An easy approach could be ignoring files with a particular key. Like file.test.js but the opposite.
Maybe something like myFile.ignore.test.js, or someone with more creativity can think of a better one.

Thanks a lot!

@lock lock bot locked and limited conversation to collaborators Jan 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

9 participants