-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Incredibly slow (near unusable) on Docker container #1395
Comments
Hmm, that is very weird. Is the file system access slow, that's really the only thing that should be different here between Jest and mocha? Jest crawls the file system from the root (package.json) and looks at all the files for static analysis. How many cores does the system report that it has? Can you try invoking Jest with |
Another thing is that if you are using babel-jest, babel actually loads a ton of modules so if the fs is slow, this might contribute to that. |
i remember having similar kind of issues inside docker container. The problem was the slowness of fs access. I think it was related to mounting a directory through a virtual container |
found the issue docker/compose#631 |
This is a known docker for mac issue: https://forums.docker.com/t/file-access-in-mounted-volumes-extremely-slow-cpu-bound/8076/158 |
Yeah I'm gonna close this out because unfortunately it isn't actionable from our side :( |
Hi @cpojer, sorry I didn't mean to drop off like that, I did get a chance to run |
@mbrio I decided to switch over to mocha, and the tests run immediately within my docker container without an issue. No changes were made to my Dockerfile or docker-compose configuration. This seems like a Jest issue and not a Docker issue. I had no issues with running my Jests tests locally, only within the container. |
@amkoehler yeah, I think there's a significant difference in the libraries that Jest and Mocha use for watching filesystem changes. I assume that Mocha is less thorough, (and/or) less active, and/or less compatible with all filesystems. The speed issue is definitely an issue with Docker for Mac as I have friends who have slightly different configurations for running Docker on a Mac that do not see as big of an issue. With that said, since Docker for Mac is the official way to run Docker instances, it would be great for the developers of Jest to consider looking into how to be a bit more compatible with it. |
I came to this issue lots of times when trying to figure it out why jest was slow. Scenario: Building my application inside a docker container. In my case, the container was based on Linux Alpine. My Solution: I changed the container base image to use Ubuntu instead of Alpine. Hope this helps someone! :) |
This page pretty much says that As of Dec'17, running jest can be considered unusable in my opinion. I'm seeing 28s time for 3 basic test files inside a container. Exact same thing on the host takes 0.4s. This can work for CI purposes, but not for developer env. There are a few clunky workarounds for this, all of which in my opinion mostly defeat the point of running development env inside containers. docker-sync and d4m-nfs are considered to be currently best solutions for this. Personally I'm not interested in trying either because if I can't use |
@rogeliog is this something you could potentially find someone in Docker team to fix? |
enabling the |
I've investigated a bit, and it seems the source of slowness is this._crawl |
That's great! |
Is the fix already on the latest jest version? I am using the latest and running 3 tests on docker took 2+ mins. |
Using the new PnP feature of Yarn enabled Jest to run fast in Docker for me. It removes the |
"roots": ["./src"] not supported for create-react-app (boo!) |
I feel like this is still an issue. Running a single test file was taking me 17-20 seconds in a Docker container. After some Googling, I landed on this issue. I already have a jest |
I agree with @elliotlarson. Even if most of the blame is on Docker for Mac, I believe jest could optimize its scan for tests in ways that would help regardless of Docker. |
Ideas and PRs are most welcome. It's, as far as I know, not an issue for anyone on the core team - so if anything is gonna happen here it'll have to come from the community |
@SimenB Fair enough. I only wished there was some incentive for the core team to try to reach more people. However cool jest might be, there are alternatives out there. And being super slow to run is a deal breaker. |
Linking to docker/for-mac#1358 |
I had a similar problem, in a kubernete's pod the unit-test takes until 200 segs to done, then I found thins issue on Jest's GitHub. So, I add this |
I use create-react-app and I can use the
Note: I am using "react-scripts": "^2.1.5" and
However if I pass it as string it will work. I don't know if I am doing a mistake or something |
would be useful to have a debug method for whats going on. For example I tried to figure out why my glob patterns were not improving speed until I found this issue #7031 which made me realize all the files are crawled before the filter. so I added a "roots" folder and it sped up the crawling significantly. |
there's a new issue to work on a docker-for-mac improvement to solve this: docker/roadmap#7 |
(I don't use watch mode, I run test manually after I made some changes) My issue is mounting the Before
After
|
@jpbochi 's mention solved for my case. using |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
I've begun using Docker containers for many of my projects and have noticed how incredibly slow Jest runs in a Docker container when executing on a shared folder on OS X. Within Docker you can mount a local path and map it to a path within the container (e.g. ~/Source/projecta:/usr/src/app). When using this configuration my tests which consists of a single file with a single unit test takes over 30 seconds; but when run locally outside of Docker it takes 1 second. I'm using the command
jest specs/unit
; which I got from another Jest issue suggesting that supplying the test folder could speed up tests, and it did, locally, from 3 seconds to 1 second; but made no change to how it runs in Docker. I would have left it at that and said that it's a Docker for Mac issue (especially because there is a speed issue with mounted volumes that is known) but I ran the same exact single test using mocha and it executed in milliseconds. The unit test is a simpleexpect(true).toBe(true)
(or for mocha+chaiexpect(true).to.equal(true)
and for some reason Jest, under Docker, executed in ~30 seconds vs mocha's less than 1 second.Are there any configuration settings or optimizations that I could use to help speed up Jest? I would much rather use Jest over Mocha, but will obviously use the test platform that executes in a reasonable amount of time. This is my Jest configuration:
The text was updated successfully, but these errors were encountered: