We will see a bit of configuration from karma and an example of a working enviroment for testing and coverage.
This project is the same I am using for browser testing , but with integration to saucelabs. So we can make our tests run in different devices and browsers.
For impatients you can find the repo here
The karma configuration we will be analyzing will be this one
Saucelabs will be working with our code in order to test in different devices and browsers. Please create an account on saucelabs.
In this case we need to have installed nodejs, npm, and karma, mocha, phantomjs and expect for assertion.
It would be nice that you already saw this post that explains about karma configuration of this project.
Defining browsers and platforms
We need to define with karma which are going to be those devices and browsers that saucelabs will take care for.
So we can see that reporters defined are saucelabs and spec, all this values will override the ones from karma.local.conf.js.
We are adding our browsers to the configuration. We will record logs in the file sauce-connect.log in order to see if there where any error during this execution.
So after defining our configurations for sauce labs on top of our locals. We can run saucelabs through our command line.
To do so we will define our credentials for saucelabs in enviroment variables. Those creadentials you will get after logging to saucelabs in your account settings.
$ export SAUCE_USERNAME=[YOUR USER NAME] $ export SAUCE_ACCESS_KEY=[YOUR ACCESS KEY]
Remember export running from terminal will actually work in that terminal, in order to get it working all the time from the command line you need to define it locally.
I will not go further on this two environment variables, the reasons is we will define them lately in another place, and actually some one else will run our configurations to saucelabs. (cough cough travis)
So running saucelabs from command line now will be. The same as running locally but with the configuration for saucelabs.
$ karma start karma.saucelabs.conf.js
At this moment we just created a nice environment to test what we need with mocha, karma, phantomjs, and then we just added some cross browsing tests with saucelabs. Whats next? We can tell someone else to run all this for us hang tight to your chair and read the next post for Continuous Integration and Github.