Front end third party dependencies and Code coverage
Date 28/10/2014
Front end dependencies
While Node.js is a back end JavaScript environment, the dependency management touched in the earlier lecture is equally important for front end dependencies. There dependency managers such as Bower and Component, which are very similar to npm. Many packages that are available in one of them, is also available in the two other.
Tasks for front end dependencies
In the project made in the web server lecture
Add a library for doing DOM selection and event handler binding by using a dependency manager
Use that library for putting the cursor in the first field when the user enter the feedback page
Write in
hello-node-js
repositoryREADME.md
file when would you use a front end package managerand when you would add the 3rd party library directly under the project version control
Code coverage of unit tests
Unit testing is usually providing stability to a project, but without knowing how much code the tests are covering, it is difficult to trust the given stability. Code coverage is a method used to describe how much of the code executed is truly tested.
One popular code coverage tool is istanbul, which can be installed with a command:
Coverage report can be generated with a command:
The above command runs nodeunit .
throught istanbul
which instruments the source and evaluates the unit tests, resulting a folder called coverage
that contains the report in several different formats.
The output should be something similar to:
A full working example with mocha
unit tests and istanbul
code coverage can be seen at the analyze-css
module.
Tasks for code coverage
Make sure that the unit tests and the task runner made in the
unit testing lecture are working
Add code coverage check via command line for the project
Configure the command so it can be excuted with
npm run-script coverage
Use coverage report to find out areas where tests are not touching
Add more unit tests to achieve at least 95% coverage
Push the code coverage report made in the 1st task to GitHub Pages ('gh-pages')
branch, so it becomes available at
username.github.io/project-name
Optional: Find a npm module that has unit tests and is running them via task runner
Add code coverage command to
package.json
, which can be executed withnpm run-script coverage
Create pull request
Link the pull request to the list below
Code coverage task runner pull requests
Links related to the lecture subject
Last updated
Was this helpful?