Calculating code coverage

With our integration test already written and running, we have one thing pending to do. It would be an awesome thing if we could see how our tests are doing with respect to our app in terms of test coverage.

Let’s add code coverage to the app!

Istanbul is a very famous JavaScript code coverage tool that computes different metrics such as statement quality, lines of code, function use, and branch coverage with module loader hooks to analyze all our code and add coverage when running tests, giving us real-time information about our application. It supports all kinds of JavaScript coverage use cases, from unit tests to functional and browser tests. The best part about this is that it is scalable.

Fortunately, we just need to install Istanbul and nyc (this last one in the command line client for istanbul). We just do this:

npm install istanbul --save-dev
npm install nyc --save-dev

Then, we modify our package.json file. This is to add test with coverage to our script object:

"test-coverage": "nyc mocha ./spec.js"

Then, run the following:

npm run test-coverage

You should be able to see the coverage summary of your application in the console.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.100.20