Skip to content
This repository has been archived by the owner on Sep 7, 2022. It is now read-only.

Severe test performance degradation when using karma-phantomjs-launcher #30

Open
NateRedding opened this issue Mar 25, 2014 · 26 comments
Open

Comments

@NateRedding
Copy link

I am converting a set of about 561 unit tests that were previously running on JSTD to run on Karma 0.12.0 and PhantomJS 1.9.7. I'll freely admit that these unit tests are probably doing all sorts of crazy stuff and not cleaning up properly after themselves and such (I didn't write them).

The tests run pretty quick when using karma-chrome-launcher - ~23 seconds. When I switch that to karma-phantom-launcher, it takes ~20 minutes!

I saw a similar issue (about a year old) on the Karma issues page talking about a 10x slowdown mentioning tweaks such as removing console.log output (ie. console.log = function() {}) and such. I can shave off a couple of minutes if I remove that and also turn off reporting of slow tests.

Thinking maybe this was an issue with PhantomJS, I found a shell script test runner to run my tests directly on PhantomJS. It is able to run them in a little under 2 minutes with no problem. So, this leads me to believe it must be a problem with karma-phantom-launcher.

Interestingly, when I was re-running the tests to get the numbers above, I somehow had one run where everything ran in about 2.5 minutes... not sure how that happened. I immediately re-ran it and it took 20+ minutes again.

My config:

    {
        basePath: '.',
        frameworks: ['jasmine'],
        singleRun: true,
        reporters: ['dots', 'beep'],
        colors: true,
        browsers: ['PhantomJS'],
        reportSlowerThan: 500,
        plugins: [
            'karma-jasmine',
            'karma-phantomjs-launcher',
            'karma-beep-reporter'
        ],
        files: files
    }
@NateRedding
Copy link
Author

This issue appears to be mostly environmental, but I don't know what the specific factors are. Initially, I thought it was lack of memory, but I have witnessed some test runs that ran poorly even when there should have been plenty of free physical memory. As best as I can tell, running Karma/PhantomJS when my IDE is running (IntelliJ) causes it to run extremely poorly.

@tavisrudd
Copy link

Also seeing this with phantom karma-jasmin on a very fast box with almost 30 gigs of free ram. Chrome runs the tests in 30 seconds, Phantom in over 3 minutes.

@dtabuenc
Copy link

Also seeing extreme slowdown in one of our projects. The slow down seems to happen when loading json fixtures or html templates from local file using ajax request. The ajax request is instant in chrome but a few seconds in phantom.

@chrylis
Copy link

chrylis commented Oct 29, 2014

I suspect PhantomJS. I'm seeing equivalent behavior running Java Selenium tests with PhantomJS, Chrome, and Firefox.

@dtabuenc
Copy link

My issue was solved. It was slow dns lookup when trying to lookup localhost. Make sure you have an entry for localhost pointing to 127.0.0.1 in your hosts file. This did not manifest itself while running the same tests under chrome, but did under phantom.

@chrylis
Copy link

chrylis commented Oct 29, 2014

Not the problem for me, unless also having an entry for ::1 will trigger it.

@adammiles10
Copy link

I am getting the same problem. It looks that phantomjs is taking about a second per file to serve up (from a xhr request).

+1 for fixing :)

@dignifiedquire
Copy link
Member

Could you try with phantomjs 2.0? I could imagine it being faster :)

@DavidKDeutsch
Copy link

@dtabuenc - thanks for posting; adding localhost to my hosts file solved the issue for me as well.

@eudisd
Copy link

eudisd commented Jan 10, 2016

+1

@meg2208
Copy link

meg2208 commented Mar 25, 2016

+1 (hi @eudisd)

anyone still having this problem? It is still slow for me with 2.0 and seems to get slower with each test case.

@rvignacio
Copy link

Same here, we have different set ups and tried both PhantomJS 1 and 2. Don't know if it's a launcher or PhantomJS problem.

@patrickmichalina
Copy link

I have the same issue, especially slow because of how many files I am loading using SystemJS (all XHR).

@mailmrmanoj
Copy link

+1

2 similar comments
@santhi23
Copy link

+1

@pedrotst
Copy link

+1

@eudisd
Copy link

eudisd commented Feb 24, 2017

The solution is not to use karma, switch over to jest + webpack + React.

@ChrisProlls
Copy link

+1

@vfeinman
Copy link

How can we all be having this issue and no solution yet?

Karma + Webpack + Jasmine + PhantomJS

147 tests
PhantomJS 4:31
Chrome: 0:13

@andregs
Copy link

andregs commented Mar 22, 2017

I replaced PhantomJS by Nightmare thanks to this guy and after that many of my problems are gone.
Also, take a loot at this recommendation:
https://github.com/angular/protractor/blob/master/docs/browser-setup.md#setting-up-phantomjs

@vfeinman
Copy link

@andregs Thank you so much for your suggestion! I'd really like to understand why PhantomJS was running so slowly,

147 tests:

  • PhantomJS 4:31
  • Chrome: 0:13
  • Nightmare: 0:17

@patrickmichalina
Copy link

Yea - Just move away from Phantom :) seems to be the right answer

@pedrotst
Copy link

pedrotst commented Mar 23, 2017

@patrickmichalina, there is no other options that runs in virtual memory. We are trying to avoid having to setup xvfb in our CI machine just for running our tests.

We are runnning out of options though since every now and then our tests will crash due to random phantomjs timeout 😢

@ckedwards
Copy link

@pedrotst I'm not sure why the better solution of headless chrome has not been mentioned yet. I don't know what this Nightmare nonsense is.

New launcher:
karma-runner/karma#2489

Example config:
karma-runner/karma#2603

I haven't tried headless chrome myself yet, but it looks promising.

@pselden
Copy link

pselden commented Apr 13, 2017

#30 (comment) -- nightmare just runs electron.

@ArcanisCz
Copy link

@andregs very thanks for that Nightmare suggestion - its a bit of workaround but a good one!

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