{"id":13610338,"url":"https://github.com/r3b/grunt-protractor-coverage","last_synced_at":"2025-04-12T22:33:30.479Z","repository":{"id":15454049,"uuid":"18187057","full_name":"r3b/grunt-protractor-coverage","owner":"r3b","description":"Coverage analysis for Protractor tests","archived":false,"fork":false,"pushed_at":"2017-05-23T23:02:31.000Z","size":312,"stargazers_count":38,"open_issues_count":21,"forks_count":29,"subscribers_count":9,"default_branch":"master","last_synced_at":"2024-10-07T07:42:37.993Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/r3b.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-03-27T18:40:18.000Z","updated_at":"2022-01-17T13:41:00.000Z","dependencies_parsed_at":"2022-08-27T11:50:54.641Z","dependency_job_id":null,"html_url":"https://github.com/r3b/grunt-protractor-coverage","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/r3b%2Fgrunt-protractor-coverage","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/r3b%2Fgrunt-protractor-coverage/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/r3b%2Fgrunt-protractor-coverage/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/r3b%2Fgrunt-protractor-coverage/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/r3b","download_url":"https://codeload.github.com/r3b/grunt-protractor-coverage/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223502426,"owners_count":17155938,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T19:01:43.778Z","updated_at":"2024-11-07T16:31:04.841Z","avatar_url":"https://github.com/r3b.png","language":"JavaScript","readme":"# grunt-protractor-coverage\n[![Build Status](https://travis-ci.org/r3b/grunt-protractor-coverage.svg?branch=master)](https://travis-ci.org/r3b/grunt-protractor-coverage)\n[![Coverage Status](https://coveralls.io/repos/r3b/grunt-protractor-coverage/badge.png)](https://coveralls.io/r/r3b/grunt-protractor-coverage)\n\n\u003e Instrument your code and gather coverage data from Protractor E2E tests\n\n## Getting Started\nThis plugin requires Grunt `~0.4.4`\n\nIf you haven't used [Grunt](http://gruntjs.com/) before, be sure to check out the [Getting Started](http://gruntjs.com/getting-started) guide, as it explains how to create a [Gruntfile](http://gruntjs.com/sample-gruntfile) as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:\n\nThe underlying code is borrowed heavily from [grunt-protractor-runner](https://github.com/teerapap/grunt-protractor-runner) and most options are still intact.\n\n```shell\nnpm install grunt-protractor-coverage --save-dev\n```\n\nOnce the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:\n\n```js\ngrunt.loadNpmTasks('grunt-protractor-coverage');\n```\n\n## The \"protractor_coverage\" task\n\n### Overview\nIn your project's Gruntfile, add a section named `protractor_coverage` to the data object passed into `grunt.initConfig()`.\n\n```js\ngrunt.initConfig({\n  protractor_coverage: {\n    options: {\n      // Task-specific options go here.\n    },\n    your_target: {\n      // Target-specific file lists and/or options go here.\n    },\n  },\n})\n```\n\n#### Default Options\nIn this example, the default options are used to do capture coverage of your protractor tests.\n\nMeasuring coverage from protractor tests does not work out of the box. To measure coverage Protractor coverage, all\nsources need to be instrumented using istanbul.\n\n```js\n    instrument: {\n        files: 'src/**/*.js',\n        options: {\n            lazy: true,\n            basePath: \"instrumented\"\n        }\n    }\n```\n\nAnd the server running the code / app should use that instrumented code.\n\n```js\n    connect: {\n        options: {\n            port: 9000,\n            hostname: 'localhost'\n        },\n        runtime: {\n            options: {\n                middleware: function (connect) {\n                    return [\n                        lrSnippet,\n                        mountFolder(connect, 'instrumented'),\n                        mountFolder(connect, '.......')\n                    ];\n                }\n            }\n        }\n    }\n```\n\nNext to that your test should be run.\n\n```js\n    protractor_coverage: {\n        options: {\n            keepAlive: true,\n            noColor: false,\n            collectorPort: 3001,\n            coverageDir: 'path/to/coverage/dir',\n            args: {\n                baseUrl: 'http://localhost:9000'\n            }\n        },\n        local: {\n            options: {\n                configFile: 'path/to/protractor-local.conf.js'\n            }\n        },\n        travis: {\n            options: {\n                configFile: 'path/to/protractor-travis.conf.js'\n            }\n        }\n    }\n```\n\nAfter the tests have been run and the coverage has been measured and captured you want to create a report.\n\n```js\n    makeReport: {\n        src: 'path/to/coverage/dir/*.json',\n        options: {\n            type: 'lcov',\n            dir: 'path/to/coverage/dir',\n            print: 'detail'\n        }\n    }\n```\n\n### Cucumber tests\ngrunt-protractor-coverage normally injects code used for obtaining coverage information by generating altered versions of spec files, but Cucumber features are written in Gherkin rather than JavaScript so this will fail. You can prevent this from happening using the noInject option:\n\n```js\n    protractor_coverage: {\n        options: {\n            keepAlive: true,\n            noInject: true,\n            coverageDir: 'path/to/coverage/dir',\n            args: {\n                baseUrl: 'http://localhost:9000'\n            }\n        },\n        local: {\n            options: {\n                configFile: 'path/to/protractor-local.conf.js'\n            }\n        }\n    }\n```\n\nOnce enabled you'll also need to update your step definitions to store coverage data after each scenario runs: \n\n```js\nvar coverage = require('grunt-protractor-coverage/cucumber');\n\nmodule.exports = function () {\n    // Step definitions go here\n    \n    this.After(coverage.getCoverage);\n};\n```\n\n### Glue it all together!!\n\n```js\ngrunt.initConfig({\n    connect: {\n        options: {\n            port: 9000,\n            hostname: 'localhost'\n        },\n        runtime: {\n            options: {\n                middleware: function (connect) {\n                    return [\n                        lrSnippet,\n                        mountFolder(connect, 'instrumented'),\n                        mountFolder(connect, '.......')\n                    ];\n                }\n            }\n        }\n    },\n    instrument: {\n        files: 'src/**/*.js',\n        options: {\n        lazy: true,\n            basePath: \"instrumented\"\n        }\n    },\n    protractor_coverage: {\n        options: {\n            keepAlive: true,\n            noColor: false,\n            coverageDir: 'path/to/coverage/dir',\n            args: {\n                baseUrl: 'http://localhost:9000'\n            }\n        },\n        local: {\n            options: {\n                configFile: 'path/to/protractor-local.conf.js'\n            }\n        },\n        travis: {\n            options: {\n                configFile: 'path/to/protractor-travis.conf.js'\n            }\n        }\n    },\n    makeReport: {\n        src: 'path/to/coverage/dir/*.json',\n        options: {\n            type: 'lcov',\n            dir: 'path/to/coverage/dir',\n            print: 'detail'\n        }\n    }\n});\n```\n\n## Contributing\nIn 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](http://gruntjs.com/).\n\n## Release History\n_(Nothing yet)_\n","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fr3b%2Fgrunt-protractor-coverage","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fr3b%2Fgrunt-protractor-coverage","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fr3b%2Fgrunt-protractor-coverage/lists"}