For all of you old fogies working on angular 1 apps and are running browser tests with karma you can run your tests in firefox with headless mode with a customer launcher. Add the snippet below to your karma conf
It's becoming more and more popular not to use a browser for unit tests.
You do "pure" unit tests, which test most of the logic, computations and intention in nodejs, then rely on (usually just a few) E2E tests in selenium or whatever to make sure stuff actually work in the browser.
For example, in a standard React/Redux app with low amounts of legacy code, you can test almost all of the app's constructs in node and be very confident that everything works.
There's still a few places where Karma + Browser shine. Namely when something requires a unit test-style environment but is integration heavy. Think libraries abstracting browser details such as a rich text editor or a library like jQuery.
We were using Xvfb with PhantomJS. Moving to a headless browser gave us the advantage of making sure everything is rendering just as we see in the GUI mode of that browser. This had a lot to do with moving away from PhantomJS. But it also removed the unkowns, Xvfb and other dependencies that came with it, from our stack. The lesser the unkowns the better I guess.
We have found PhantomJS to be very buggy and hard to debug. We generate millions of PDFs a month. Whenever we upgrade PhantomJS, something breaks with no way to debug easily. We end up reverting to the older version. After trying 3 times, we gave up and had settled for the older version.
In the middle of moving a massive codebase off PhantomJS, it is indeed a nightmare. Old versions leaked memory, debugging/logging is really weird because you get trapped in the context of the browser, and pooling...one of the old phantom pooling packages on GH is part of someone's grad thesis.
Does not play well with React Fiber either, in my experience. Aaaand isn't the brain behind PhantomJS stepping down or something? To any potential users: just go with Chrome
Chrome's headless mode uses significantly less memory than using xvfb. I assume FF would have the same benefit. Plus one less moving part, dependency, etc.
Well why do you want to do that, if you are finding the tests are too slow it maybe worth writing some tests with jasmine that can be run in node without a browser.
That's what we currently do, karma and browser testing are useful but sometimes you can get away with not using them.
One thing we are trying is using JSDom to run browser based tests in node
``` browsers: ['FirefoxHeadless'], customLaunchers: { FirefoxHeadless: { base: 'Firefox', flags: [ '-headless', ], }, }, ```
Note you need to be running the beta version of firefox, I needed to download it from here https://www.mozilla.org/en-US/firefox/channel/desktop/