AngularJS Essentials
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
After this, you can use the Node Package Manager, also known as npm. It will<br />
manage the installation of everything that we need to set up our environment,<br />
as follows:<br />
npm install –g karma<br />
Chapter 7<br />
Configuration<br />
The configuration is quite simple. It just requires a file called karma.conf.js,<br />
located in the root application directory. The best way to create it is by following the<br />
configuration wizard through the following command:<br />
karma init<br />
Karma's configurator will be shown, and you just have to follow the instructions in<br />
order to generate your configuration file.<br />
The first question will be regarding the testing framework you would like to use.<br />
Karma supports Mocha and QUnit beyond Jasmine. After that, it will ask you about<br />
RequireJS, adding it depending on our answer. Then, you will be asked a question<br />
about which browser you want to use. There are many options such as Chrome,<br />
Firefox, Opera, Safari, IE, and even PhantomJS.<br />
Take care of the next question about the location of each source and test file. You<br />
should place it in the correct order, otherwise you can have some trouble. For our<br />
application, the best strategy to adopt is to follow the code organization that we<br />
studied in Chapter 1, Getting Started with <strong>AngularJS</strong>. After this, you could exclude the<br />
files that you don't want to test.<br />
Finally, Karma will ask you about watching the files and running the tests on every<br />
change. It is a very nice feature to enable, bringing with it a very fast feedback<br />
cycle while you are programming. You can also check out the configuration details<br />
generated through Karma's configurator:<br />
karma.conf.js<br />
module.exports = function(config) {<br />
config.set({<br />
basePath: '',<br />
frameworks: ['jasmine'],<br />
files: [<br />
'lib/angular/angular.js',<br />
'lib/angular/angular-mocks.js',<br />
'src/parkingApp.js',<br />
'src/parkingService.js',<br />
[ 141 ]<br />
www.it-ebooks.info