Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

grunt-istanbul

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

grunt-istanbul

JavaScript codecoverage tool for Grunt

  • 0.4.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6.4K
increased by29.3%
Maintainers
1
Weekly downloads
 
Created
Source

grunt-istanbul Build Status

JavaScript codecoverage tool for Grunt

Getting Started

This plugin requires Grunt ~0.4.1

Install this grunt plugin next to your project's Gruntfile.js with: npm install grunt-istanbul

Then add this line to your project's Gruntfile.js gruntfile:

grunt.loadNpmTasks('grunt-istanbul');

Documentation

To use this grunt-istanbul plugin, register a grunt task to run the following:

  1. Instrument your source code
  2. Run your test suite against your instrumented source code
  3. Store your coverage results
  4. Make the report

For step 2, an environment variable can be used to determine which path to use for loading the source code to run the tests against. For example, when you normally run your tests you want them to point directly at your source code. But when you run your instanbul code coverage task you want your tests to point at your instrumented source code. The grunt-env plugin can be used for setting an environment variable in a grunt task. Here's an example solution that solves this problem using grunt-env and grunt-mocha-test:

// in Gruntfile.js
module.exports = function (grunt) {

  grunt.initConfig({
    env: {
      coverage: {
        APP_DIR_FOR_CODE_COVERAGE: '../test/coverage/instrument/app/'
      }
    },
    instrument: {
      files: 'app/*.js',
      options: {
        lazy: true,
        basePath: 'test/coverage/instrument/'
      }
    },
    mochaTest: {
      options: {
        reporter: 'spec'
      },
      src: ['test/*.js']
    },
    storeCoverage: {
      options: {
        dir: 'test/coverage/reports'
      }
    },
    makeReport: {
      src: 'test/coverage/reports/**/*.json',
      options: {
        type: 'lcov',
        dir: 'test/coverage/reports',
        print: 'detail'
      }
    }
  });

  grunt.registerTask('coverage', ['env:coverage', 'instrument', 'mochaTest',
    'storeCoverage', 'makeReport']);
};


// require_helper.js
module.exports = function (path) {
  return require((process.env.APP_DIR_FOR_CODE_COVERAGE || '../app/') + path);
};

// using requireHelper in a test
var requireHelper = require('../require_helper');
var formValidator = requireHelper('form_validator');

Also, checkout the example Gruntfile.js in this repo (note that you do not need to implement the reloadTasks task in this example): Gruntfile.js

more examples

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using grunt.

Release History

(Nothing yet)

License

Copyright (c) 2014 taichi Licensed under the MIT license.

Keywords

FAQs

Package last updated on 01 Dec 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc