Giter Site home page Giter Site logo

paulcurley / grunt-template-jasmine-istanbul Goto Github PK

View Code? Open in Web Editor NEW

This project forked from maenu/grunt-template-jasmine-istanbul

0.0 2.0 0.0 98 KB

Code coverage template mix-in for grunt-contrib-jasmine, using istanbul

License: MIT License

grunt-template-jasmine-istanbul's Introduction

Code coverage template mix-in for grunt-contrib-jasmine, using istanbul

Installation

npm install grunt-template-jasmine-istanbul --save-dev

Template Options

templateOptions.coverage

Type: String Mandatory.

The file path where to store the coverage.json.

templateOptions.report

Type: String | Object | Array Mandatory.

If a String is given, it will be used as the path where a HTML report is generated. If an Object is given, it must have the properties type and options, where type is a String and options an Object. type and options are used to create the report by passing it to istanbuls Report.create(type, options). For example, if you want to generate a Cobertura report at bin/coverage/cobertura, use this:

report: {
	type: 'cobertura',
	options: {
		dir: 'bin/coverage/cobertura'
	}
}

If an Array is given, it must consist of Objects of the form just described.

The supported types are:

templateOptions.replace

Type: Boolean Default: true

Whether or not the src scripts are replaced by the paths to their instrumented versions. This is useful when you want the mixed-in template to work with the original sources, and you want to serve the instrumented sources by redirecting request on the server side.

templateOptions.thresholds

Type: Object Default: undefined

Thresholds for any of the metrics that Istanbul measures. If a threshold is not met, a warning is emitted. See example below for available metrics.

templateOptions.template

Type: String | Object Default: jasmine's default template

The template to mix-in coverage.

templateOptions.templateOptions

Type: Object Default: undefined

The options to pass to the mixed-in template.

Examples

There are multiple examples at a example repository.

Simple

Have a look at this example.

// Example configuration
grunt.initConfig({
	jasmine: {
		coverage: {
			src: ['src/main/js/*.js'],
			options: {
				specs: ['src/test/js/*.js'],
				template: require('grunt-template-jasmine-istanbul'),
				templateOptions: {
					coverage: 'bin/coverage/coverage.json',
					report: 'bin/coverage',
                    thresholds: {
                        lines: 75,
                        statements: 75,
                        branches: 75,
                        functions: 90
                    }
				}
			}
		}
	}
}

RequireJS

Have a look at this example. Note that you need to configure the baseUrl to point to the instrumented sources, as described in the section below.

grunt.initConfig({
    jasmine: {
        coverage: {
            src: ['src/main/js/*.js'],
            options: {
                specs: ['src/test/js/*.js'],
                template: require('grunt-template-jasmine-istanbul'),
                templateOptions: {
                    coverage: 'bin/coverage/coverage.json',
                    report: 'bin/coverage',
                    template: require('grunt-template-jasmine-requirejs'),
                    templateOptions: {
                        requireConfig: {
                            baseUrl: '.grunt/grunt-contrib-jasmine/src/main/js/'
                        }
                    }
                }
            }
        }
    }
}

Is it really that easy?

No.

Setting baseUrl to that location may screw up your whole configuration, because paths relative to the original sources are broken. Therefore, if this happens to you, instead of directly loading the instrumented sources, set replace: false, intercept request to the original sources and redirect them to the instrumented versions. You can do this on both the client side, or the server side. Look at the corresponding Grunfile.js files and be filled with horror: Yes, this is nasty, but it (seems to) works.

Mixed-in Templates

The Idea

Do you have another template you want to use, but you also want to collect code coverage at the same time? Then you can use a mixed-in template, that's what they are for. The idea behind a mixed-in template is simple: Istanbul generates code coverage information by instrumenting the sources before they are run and by generating reports after they have run. Therefore this templates acts as a test pre- and post-processor, but it doesn't interfere with the actual running of the tests. This makes it possible to use another template as a mix-in template to run the tests, defined by templateOptions.template and can be configured with templateOptions.templateOptions.

A Single Requirement

A mixed-in template needs to load the instrumented sources in order for the coverage reports to be correctly generated. This template copies instrumented versions of the sources to a temporary location at .grunt/grunt-contrib-jasmine/. If your mixed-in template simply includes the sources, as the default template does, you don't need to account for that, since this template replaces the src option with the paths to the instrumented versions. If your mixed-in template loads the sources differently, e.g. directly from the file system, you may need to reconfigure the mixed-in template.

Change log

  • v0.2.4, 26.05.13, merged #12 from @kayhadrin, instrumented versions of files loaded via absolute paths on windows are now created at a valid path
  • v0.2.3, 12.05.13, merged thresholds from @larsthorup #9 which can abort a build with too low coverage
  • v0.2.2, 11.05.13, added replace option, so it can be prevented that the original src option is replaced with their instrumented versions

grunt-template-jasmine-istanbul's People

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.