Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to run Karma with no browsers at all?

I started an Angular.js app with Yeoman's yo angular that includes Karma testing. Then, the grunt test reasonably failed because Karma can't find any browsers. (The browsers has not been set in the app's node_modules/karma config file.)

I'm doing my development via SSH into a remote machine, which I think (let me know if I'm wrong) is pointless to have Chrome, /usr/bin/chromium-browser, installed.

So is it possible to run Karma without any browsers?

like image 466
randwa1k Avatar asked Feb 20 '14 01:02

randwa1k


People also ask

Does karma need Chrome?

Karma works only with browsers, so use PhantomJS if you want it to be headless. We don't use it as Chrome or Safari are faster than PhantomJS.

How do I run karma in my browser?

With the default settings in place, just point your browser to http://localhost:9876/ . This allows you to capture a browser on any device, such as a tablet or a phone, that is on the same network as the machine running Karma (or using a local tunnel).

How do you Autocapture in karma?

Just simply add into the configuration file: browsers = ['Chrome']; Then, Karma will take care of autocapturing these browsers, as well as killing them.


2 Answers

I am going to add my two cents to this.

Correct - Karma requires a browser to run. BUT - you can run Chrome in Headless mode, which means although you do need the browser installed, it will not open it's UI, and you can therefore run the tests purely through an SSH session for example.

We used this configuration for our CI/CD deployments. Our Docker image for running the tests had Chrome installed and we ran them with Chrome headless mode. Worked like a charm.

To use this, simply modify your browsers property in your karma.conf.js

browsers: ['ChromeHeadless'] 

Hope this might help someone out there who may be looking for something similar...

like image 95
Clay Avatar answered Oct 01 '22 04:10

Clay


Karma needs a browser to be set.

You can make use of PhantomJS instead of Chrome.
Indeed, it's more discreet than a traditional browser launch.

like image 40
Mik378 Avatar answered Oct 01 '22 05:10

Mik378