top | item 15132007

(no title)

royka118 | 8 years 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/

discuss

order

Vinnl|8 years 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 :)

gardnr|8 years ago

> headless mode with a customer launcher

Where does one find a customer launcher?

rk06|8 years ago

OP means custom launcher.

paulddraper|8 years ago

I use karma. Do only Angular 1 folks use it?

What does everyone else use for browser tests?

shados|8 years ago

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.

MuffinFlavored|8 years ago

Does this offer any real benefit over Xvfb?

pcx|8 years ago

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.

tyingq|8 years ago

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.

royka118|8 years ago

Well currently we run the karma tests on CI with chrome headless so this allows us to do the same with firefox

hackcasual|8 years ago

Works on Windows.

MuffinFlavored|8 years ago

Do you have any advice on how to get off of Karma with Angular 1 apps?

royka118|8 years ago

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