5 ms·
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 custome
by royka118 9y ago
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
```
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/ https://www.mozilla.org/en-US/firefox/channel/desktop/
- MuffinFlavored 9y agoDoes this offer any real benefit over Xvfb?
- royka118 9y agoWell currently we run the karma tests on CI with chrome headless so this allows us to do the same with firefox
- pcx 9y agoWe 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.
- knicholes 9y agoWait, why did you need to use XVFB with PhantomJS? Isn't Phantom headless as is?
- jrgifford 9y agoStill requires a X server, which docker containers won't necessarily have.
- first_amendment 9y agoOnly versions 1.4 and below. Versions 1.5 and above do not require an X server. Version 1.5 has been available for 5+ years: https://ariya.io/2012/03/pure-headless-phantomjs-no-x11-or-xvfb https://ariya.io/2012/03/pure-headless-phantomjs-no-x11-or-x...
- pcx 9y agoWe 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.
- huehehue 9y agoIn 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
- tyingq 9y agoChrome'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.
- hackcasual 9y agoWorks on Windows.
- jhasse 9y agoThat's a disadvantage IMHO.
- MuffinFlavored 9y agoDo you have any advice on how to get off of Karma with Angular 1 apps?
- royka118 9y agoWell 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
- moogly 9y agoWe ported all our karma/Jasmine tests to (ts-)jest. Works great. Comes with JsDOM out of the box.
- Vinnl 9y ago> Note you need to be running the beta version of firefox Also note that that's only the case on Windows and OS X (it's already released for Linux), and only as long as Firefox 56 hasn't been released yet :)
- royka118 9y ago:D
- paulddraper 9y agoI use karma. Do only Angular 1 folks use it? What does everyone else use for browser tests?
- oatmealsnap 9y agoWe use Karma as well.
- shados 9y agoIt'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.
- gardnr 9y ago> headless mode with a customer launcher Where does one find a customer launcher?