2. WHY KARMA?
A simple tool that allows you to execute JavaScript code in multiple real browsers
Karma is to make your test-driven development easy, fast, and fun
Test code in multiple browsers (desktop, mobile, tablets, etc.)
Execute your tests locally during development
Execute your tests on a continuous integration server
Execute your tests on every save
Uses Istanbul to automagically generate coverage reports
3. WHY TESTING FRAMEWORK NEEDED?
Karma is not a testing framework, nor an assertion library
Karma just launches an HTTP server, and generates the test runner HTML file
Available Javascript Testing framework plugin
Jasmine
Mocha
Qunit
4. PRE-REQUISITE - INSTALL NODE.JS AND NPM
Open - https://nodejs.org/en/download/ and select appropriate operating system (Windows for demo)
It starts downloading the exe file, open it once it finishes downloading
Complete the installation wizard and verify the installation
5. CREATE NEW NODE PROJECT
Command –
npm init
It creates new node project
along with package.json file
6. INSTALL KARMA
Command –
npm install karma –save-dev
npm install requirejs --save-dev
npm install karma-requirejs --save-dev
It adds new karma and require dev dependency in package.json
7. INSTALL JASMINE AND KARMA CHROME LAUNCHER
Command –
npm install jasmine-core karma karma-chrome-launcher --save-dev
npm install karma-jasmine karma-jasmine-html-reporter karma-spec-reporter --save-dev
It adds new dependencies in package.json
8. CONFIGURE KARMA
Command –
npm install -g karma-cli
karma init karma.conf.js
It will install karma cli globally, new
dependencies in package.json
Run Karma simply by “karma” from
anywhere and it will always run the local
version
The configuration file can be generated
using karma init
11. RUN KARMA
Command –
karma start karma.conf.js
Run Karma simply by “karma” from
anywhere and it will always run the local
version
12. FILE STRUCTURE
Spec Folder –
It contains all the test file
Src Folder –
It contains all the source
files
package.json file –
file in the app root defines
what libraries will be
installed into
node_modules when you
run npm install
Node Modules –
Directory is only for build tools
Karma.conf –
It contains Karma related
configuration
package-lock.json–
automatically generated for
any operations where npm
modifies either the
node_modules tree