1.0.0 • Published 8 years ago

grunt-qunit-blanket-lcov v1.0.0

Weekly downloads
5
License
MIT
Repository
github
Last release
8 years ago

grunt-qunit-blanket-lcov npm version

Save LCOV reports generated by Blanket for Grunt QUnit.

This is used to save Blanket.js tests coverage results done with grunt-contrib-qunit in order to send them to Coveralls.io with grunt-coveralls.

Getting Started

Setup the task

If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

npm install grunt-qunit-blanket-lcov --save-dev

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

grunt.loadNpmTasks('grunt-qunit-blanket-lcov');

Setup Blanket.js

Simply follow Blanket.js guide to setup the test coverage with QUnit. No special configuration of the test suite is needed.

Your test HTML should look like :

<!DOCTYPE html>
<html>
<head>
  <title>My test suite</title>
  <meta charset="utf-8">
  
  <link rel="stylesheet" href="../bower_components/qunit/qunit/qunit.css">
  
  <script src="../bower_components/jquery/dist/jquery.min.js"></script>
  <script src="../bower_components/qunit/qunit/qunit.js"></script>
  <script src="../bower_components/blanket/dist/qunit/blanket.min.js"></script>
  
  <script src="../src/library.js" data-cover></script>

  <script src="core.js"></script>
</head>

<body>
  <!-- -->
</body>
</html>

Don't forget to change the urls of the qunit task to add ?coverage=true for each test suite.

The "qunit_blanket_lcov" task

Overview

In your project's Gruntfile, add a section named qunit_blanket_lcov to the data object passed into grunt.initConfig().

grunt.initConfig({
  qunit_blanket_lcov: {
    lib: {
      src: 'src/library.js',
      options: {
        prefix: 'http://localhost:<%= connect.test.options.port %>/',
        dest: '.coverage-results/library.lcov'
      }
    }
  }
});

Then add or edit your test Grunt task to execute qunit_blanket_lcov before qunit.

grunt.registerTask('test', [
    'qunit_blanket_lcov',
    'qunit'
]);

Options

dest

Type: string Required

Output file for LCOV data.

prefix

Type: string Required

The prefix to remove from file paths, this is generally the host + port of the grunt-contrib-connect task you use.

force

Type: boolean Default value: false

By default the task will fail if there is no coverage results to write.

inject_reporter

Type: boolean Default value: true

Automatically insert the custom Blanket reporter in the PhantomJS instance. If you redefined the inject option of grunt-contrib-qunit you must set this option to false and manually add node_modules/grunt-qunit-blanket-lcov/reporter.js to the inject list.

Usage Examples

One file

In this example the test coverage results of library.js will be saved to library.lcov.

grunt.initConfig({
  qunit_blanket_lcov: {
    lib: {
      src: 'src/library.js',
      options: {
        prefix: 'http://localhost:9001/',
        dest: '.coverage-results/library.lcov'
      }
    }
  }
});

Multiple files

If you have many source files used by QUnit analyzed by Blanket it might be a good idea to use the Grunt files globbing option.

grunt.initConfig({
  qunit_blanket_lcov: {
    all: {
      files: [{
        expand: true,
        src: ['src/*.js', 'src/plugins/**/plugin.js']
      }],
      options: {
        prefix: 'http://localhost:9001/',
        dest: '.coverage-results/all.lcov'
      }
    }
  }
});
1.0.0

8 years ago

0.3.3

9 years ago

0.3.2

10 years ago

0.3.1

10 years ago

0.3.0

10 years ago

0.2.3

10 years ago

0.2.2

10 years ago

0.2.1

10 years ago

0.2.0

10 years ago

0.1.0

10 years ago