To get started, clone the repo:
git clone https://github.com/saucelabs/karma-sauce-example.git && cd karma-sauce-example
Then run the following command to install the Karma command line interface globally and this repo's local node dependencies:
npm install -g karma-cli && npm install
Note: make sure you have node.js installed before running the above command.
Running Karma locally
You then can run Karma locally to see how it works with the
karma start command. Try saving a source file in the
src folder or a test file in the
test folder to see Karma automatically re-run the tests on the latest source code.
By default, this example runs jasmine tests in Chrome and Firefox on your local machine, and you can add more browsers that you have installed in the
karma-sauce-launcher pluginRunning Karma with the
To use Karma with Sauce, add your Sauce Labs username and access key to the
sauce.json file (if you don't have an account, you can sign up here).
You can now run the unit tests on Sauce with the
karma start karma.conf-ci.js command. Note that this will by default start Sauce Connect to establish a secure tunnel between your local machine and Sauce's cloud. To speed up the time it takes to connect to Sauce's cloud, you can start Sauce Connect in the background by using one of the binaries or the Mac app and then setting the
startConnect option to
false in the
karma.conf-ci.js file (make sure to change it back to
true before running on CI).
Using the karma-sauce-launcher in CI
It is cool to run your unit tests on Sauce locally while you develop, but even cooler to run them on a continuous integration system with every commit to your codebase. To integrate your CI with Sauce check out the instructions for Travis, Jenkins, or Bamboo.
karma.conf-ci.js file already is set up to read environment variables on CI so you shouldn't need to modify it as long as the
process.env.SAUCE_ACCESS_KEY are set properly during the build.
Example CI integration
Note: the build is failing on purpose as a demo of Sauce catching bugs in different browsers.