Building and Testing
Karma runner
Karma runner (http://karma-runner.github.io) is enabled to easily execute
JavaScript tests. Karma runner was born to replace another popular test runner JS
TestDriver with a stable, pure JavaScript, node.js based solution.
The Karma runner is able to dispatch source and test code to a running instance of a
browser (or start a new one if needed!), trigger execution of tests, collect individual
tests outcomes and report the final result. It uses real browsers to execute tests. This
is a big deal in the JavaScript world, since we can simultaneously execute tests in
several browsers making sure that our code will operate correctly in the wild.
The Karma runner is a remarkable tool when it comes to stability and
speed. It is used in the AngularJS project to execute tests as part of the
continuous integration build. On each build Karma runner executes
around 2000 unit tests on multiple browsers. In total around 14,000 tests
are being executed in about 20 seconds. Those numbers should raise our
confidence in Karma runner as a tool, and AngularJS as a framework.
Testing is such a central theme in AngularJS that we are going to have deeper look
into Jasmine tests and Karma runner later in this chapter.
Organizing files and folders
So far we've made some pretty important decisions regarding the technical stack and
tools to be used, while constructing the sample SCRUM application. Now, we need
to answer one more crucial question; how to organize different files in meaningful
folders structure.
There are multiple ways of organizing files in any given project. Sometimes choices
are made for us, since some of the existing tools and frameworks force a prescribed
layout. But neither grunt.js nor AngularJS impose any particular directory
structure so we are free to make our choices. In the following paragraphs you can
find one proposal for organizing files and rationales behind this proposal. You might
choose to use the described structure as is in your future projects or tweak it to suit
your particular needs.
Root folders
While designing folders layout we would like to end up with a directory structure
that makes it easy to navigate in the code base. At the same time we need to keep
build complexity at a reasonable level.