Installing and Running Karma

Installing Karma

  • Install Karma Globally and initialize it's configuration file:
$ npm install karma -g
-> Enter "Jasmine" for your testing framework
-> Enter "no" to the requireJS prompt
-> Enter "Chrome" for browser
-> At the watch all files prompt, type "yes"

Install Karma CLI

  • Use the command below to install Karma so that it can be accessed on the command line.
npm install -g karma-cli

Initializing Karma

$ karma init
  • with this installation, 2 additional dependencies are installed:
  • karma-chrome-launcher
  • karma-jasmine
  • You can ensure that these packages were installed by checking their version
$ karma-chrome-launcher --version
$ karma-jasmine --version

If they are not installed for some reason, you can install them with:

npm install karma-chrome-launcher -g

Get Karma Version

$ karma -–version

Customizing Karma Configuration

  • Edit the karma.conf file. This should be at the root of your application
  • To use Jasmine and Chrome, the configuration file should be set to:
frameworks: ['jasmine'],
browsers: ['Chrome'],
  • Configure a Test directory
  • This will configure the directory for our tests in /test/unit
files: [
'test/unit/**/*.js'
],

Runing Karma

  • Run Karma using the following command
karma start

Karma Launchers