Tuesday, January 5, 2016

Installation and Configuration of Karma [Jasmine Unit test runner]

Karma Installation

There are few steps to install Karma ( Jasmine Unit Test Runner )

1.       Download and Install Node.js


2.       Download and Install Python 2.7

3.       Set Python Environment Variable
[npm Config set python python 2.7]

4.       Run command to install Karma
 [npm install –g Karma]  

5.       Configure Karma js file [ Karma excute unit tests according to a karma.config.js configuration file ] you can generate automatically  karma.config.js  file by running following command
[karma init]

6.       Start Karma
Karma start karma.config.js 


Sample js file of karma.config.js

module.exports = function(config) {
    config.set({

        // base path that will be used to resolve all patterns (eg. files, exclude)
        basePath: '',


        // frameworks to use
        // available frameworks: https://npmjs.org/browse/keyword/karma-adapter
        frameworks: ['jasmine'],


        // list of files / patterns to load in the browser
        files: [
           'Scripts/jasmine/jasmine.js',
           'Scripts/angular.js',
           'Scripts/angular-mocks.js',
           'Scripts/angular-route.min.js',
           'Scripts/angular-ui-router.min.js',
           'Scripts/angular-*.js',
           'Scripts/ui*.js',
           'app/app.js', // do not change app.js position
           'app/Area/controllers/summaryController.js',
           'Scripts/Test/*Spec.js' // Jasmine Test
           ],


        // list of files to exclude
        exclude: [],


        // preprocess matching files before serving them to the browser
        // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
        preprocessors: {
   
        },


        // test results reporter to use
        // possible values: 'dots', 'progress'
        // available reporters: https://npmjs.org/browse/keyword/karma-reporter
        reporters: ['progress'],
        //reporters: ['spec'],
        //specReporter: {
        //    maxLogLines: 5,         // limit number of lines logged per test
        //    suppressErrorSummary: false,  // do not print error summary
        //    suppressFailed: false,  // do not print information about failed tests
        //    suppressPassed: false,  // do not print information about passed tests
        //    suppressSkipped: true  // do not print information about skipped tests
        //},
        plugins: ['karma-ie-launcher', 'karma-chrome-launcher', 'karma-jasmine'],

        // web server port
        port: 9876,


        // enable / disable colors in the output (reporters and logs)
        colors: true,


        // level of logging
        // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
        logLevel: config.LOG_INFO,


        // enable / disable watching file and executing tests whenever any file changes
        autoWatch: true,


        // start these browsers
        // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
        browsers: ['IE','Chrome'],


        // Continuous Integration mode
        // if true, Karma captures browsers, runs the tests and exits
        singleRun: false,

        // Concurrency level
        // how many browser should be started simultanous
        concurrency: Infinity
    });
}

Additional Source Links :
https://www.jetbrains.com/pycharm/help/running-unit-tests-on-karma.html
http://www.methodsandtools.com/tools/karma.php



No comments:

SQL Server - Identify unused indexes

 In this blog, we learn about the index usage information (SYS.DM_DB_INDEX_USAGE_STATS) and analyze the index usage data (USER_SEEKS, USER_S...