Last active
May 17, 2017 06:04
-
-
Save satyaki1/d02fed30d8d0370928239212c17c2170 to your computer and use it in GitHub Desktop.
Karma Jasmine Setup Steps For A Simple Javascript Application
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Karma configuration | |
| // Generated on Fri Apr 14 2017 11:29:28 GMT+0530 (India Standard Time) | |
| 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: [ | |
| 'test/*.spec.js', | |
| 'source/js/*.js' | |
| ], | |
| // 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: ['reporter'], | |
| // 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: ['Firefox', 'Chrome'], | |
| // Continuous Integration mode | |
| // if true, Karma captures browsers, runs the tests and exits | |
| singleRun: false, | |
| // Concurrency level | |
| // how many browser should be started simultaneous | |
| concurrency: Infinity | |
| }) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Steps to follow to set up Karma and Jasmine unit test case framworks in your project - | |
| #Pre-requisites | |
| 1. NPM | |
| 2. NodeJS | |
| #Steps | |
| Following commands to run/ steps to follow from your project root directory - | |
| * Create a package.json file in your project directory by running `npm init` command from your root direcotory | |
| * After setting up the initial package.json file , run this command to install Karma runner - `npm install karma --save -dev` | |
| -- The `--save -dev` option will add dependency in your `package.json` file which will helps future user to install it easily by just running `npm install` command | |
| * Run `npm install karma-chrome-launcher --save-dev` to add Chrome extension to run your spec | |
| * Run `npm install karma-firefox-launcher --save-dev` to add Firfox extension to run your spec | |
| * Run `npm install karma-jasmine --save-dev` to install karma-jasmine package | |
| * Run `npm install jasmine-core --save-dev` to install jasmine-core package | |
| * Setup karma.conf.js to by running `karma init karma.conf.js` command and follow steps. check the file created at my end for reference | |
| * Run `npm install karma-spec-reporter --save-dev` command to show the spec results in a more concise manner | |
| * After writing your specs in test/abc.spec.js to run the spec use command `karma start` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment