Skip to content

Commit

Permalink
Merge pull request #26 from fracmak/custom_collector_port
Browse files Browse the repository at this point in the history
Added ability to customize the collector port through options
  • Loading branch information
r3b committed Nov 22, 2014
2 parents ecaeaaa + e77a129 commit e84c4cd
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ Next to that your test should be run.
options: {
keepAlive: true,
noColor: false,
collectorPort: 3001,
coverageDir: 'path/to/coverage/dir',
args: {
baseUrl: 'http://localhost:9000'
Expand Down
2 changes: 1 addition & 1 deletion resources/saveCoverage.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ var fs=fs||require("fs");
var http=http||require("http");
var options = {
hostname: 'localhost',
port: 3001,
port: <%=collectorPort%>,
path: '/data',
method: 'POST',
headers:{
Expand Down
8 changes: 5 additions & 3 deletions tasks/protractor_coverage.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ module.exports = function(grunt) {
keepAlive: true,
noColor: false,
debug: false,
collectorPort: 3001,
args: {}
});
var saveCoverageTemplate = grunt.file.expand(["resources/saveCoverage.tmpl", "node_modules/grunt-protractor-coverage/resources/saveCoverage.tmpl", process.cwd()+'/**/resources/saveCoverage.tmpl']).shift();
Expand All @@ -114,6 +115,7 @@ module.exports = function(grunt) {
var saveCoverageContent=grunt.template.process( saveCoverageSource, {
data: {
dirname: coverageDir,
collectorPort: opts.collectorPort,
coverage: '__coverage__'
}
});
Expand Down Expand Up @@ -179,19 +181,19 @@ module.exports = function(grunt) {
grunt.verbose.writeln("Spawn node with arguments: " + args);
// start the collector
var collector=require('coverage-collector');
collector(3001);
collector({port: opts.collectorPort});
function cleanup(callback){
suppliedArgs.specs.forEach(function(f){grunt.file.delete(f, {force:true});});
}
function getCoverageData(callback){
http.get("http://localhost:3001/data", function(res) {
http.get("http://localhost:" + opts.collectorPort + "/data", function(res) {
var payload="";
res.on('data', function (chunk) {
payload+=chunk;
// grunt.log.warn('BODY: ' + chunk);
});
res.on('end', function(){
http.get("http://localhost:3001/done", function(res) {
http.get("http://localhost:" + opts.collectorPort + "/done", function(res) {
cleanup();
if(callback){callback(payload);}
})
Expand Down

0 comments on commit e84c4cd

Please sign in to comment.