Book Image

PhantomJS Cookbook

By : Rob Friesel
Book Image

PhantomJS Cookbook

By: Rob Friesel

Overview of this book

Table of Contents (15 chapters)
PhantomJS Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Generating code coverage reports with Istanbul and the Karma test runner


This recipe expands on our use of the Karma test runner and introduces the Istanbul library for static analysis of test coverage. Istanbul is a code coverage tool for JavaScript that instruments the code under test and provides reports about statement, branch, function, and line test coverage.

Getting ready

To run this recipe, we will need the following items:

  • JavaScript code to test, and the tests for that code

  • Node.js and npm installed and on our PATH

  • The Karma test runner installed

  • The following plugins (npm modules) for Karma:

    • karma-jasmine

    • karma-phantomjs-launcher

    • karma-coverage

    Note

    The karma-coverage plugin uses Istanbul to provide reports on code coverage. We can learn more about Istanbul at http://gotwarlost.github.io/istanbul/; we can install it on the command line as:

    npm install karma-coverage --save-dev
    

The library code that we will use for our tests is available in the downloadable code repository as string...