-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug Fix: Added error message for missing lcov.info
Also did a lot of refactoring and failed attempts at testing
- Loading branch information
1 parent
1f74c22
commit 7decfef
Showing
6 changed files
with
123 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,53 @@ | ||
module.exports = function(grunt){ | ||
var fs = require('fs'); | ||
var glob = require('glob'); | ||
|
||
grunt.task.registerTask('coveralls', 'Coveralls coverage with Karma', function(){ | ||
var done = this.async(); | ||
var gruntOptions = grunt.config('coveralls.options'); | ||
process.env.NODE_COVERALLS_DEBUG = gruntOptions.debug ? 1 : 0; | ||
var lcov_path = glob.sync(gruntOptions.coverage_dir + "/**/lcov.info")[0]; | ||
var input = fs.readFileSync(lcov_path).toString(); | ||
var coveralls = require('coveralls/index'); | ||
|
||
coveralls.getBaseOptions(function(err, options){ | ||
options.filepath = "."; | ||
coveralls.convertLcovToCoveralls(input, options, function(err, postData){ | ||
if (err){ | ||
done(); | ||
throw err; | ||
} | ||
coveralls.sendToCoveralls(postData, function(err, response, body){ | ||
if (err){ | ||
done(); | ||
throw err; | ||
} | ||
if (response.statusCode >= 400){ | ||
done(); | ||
throw "Bad response: " + response.statusCode + " " + body; | ||
} | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
var fs = require('fs'); | ||
var glob = require('glob'); | ||
var logger = require('log-driver')({level: 'debug'}); | ||
|
||
function main(grunt){ | ||
|
||
grunt.task.registerTask('coveralls', 'Coveralls coverage with Karma', function(){ | ||
var done = this.async(); | ||
var gruntOptions = grunt.config('coveralls.options'); | ||
process.env.NODE_COVERALLS_DEBUG = gruntOptions.debug ? 1 : 0; | ||
var input = getInput(gruntOptions.coverage_dir); | ||
callCoveralls(done, input); | ||
}); | ||
|
||
}; | ||
|
||
function callCoveralls(done, input){ | ||
var coveralls = require('coveralls/index'); | ||
coveralls.getBaseOptions(function(err, options){ | ||
options.filepath = "."; | ||
coveralls.convertLcovToCoveralls(input, options, function(err, postData){ | ||
handleError(done, err); | ||
coveralls.sendToCoveralls(postData, function(err, response, body){ | ||
sendToCoverallsCallback(done, err, response, body); | ||
}); | ||
}); | ||
}); | ||
} | ||
|
||
function handleError(done, err) { | ||
if (err){ | ||
done(); | ||
throw err; | ||
} | ||
} | ||
|
||
function sendToCoverallsCallback(done, err, response, body){ | ||
handleError(done, err); | ||
if (response.statusCode >= 400){ | ||
handleError(done, "Bad response:" + response.statusCode + " " + body); | ||
} | ||
done(); | ||
} | ||
|
||
function getInput(basePath){ | ||
var lcov_path = glob.sync(basePath + "/**/lcov.info")[0]; | ||
if (!lcov_path){ | ||
logger.error("lcov.info not found in `" + basePath + "`"); | ||
} | ||
return fs.readFileSync(lcov_path).toString(); | ||
} | ||
|
||
module.exports = main; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
var App, something; | ||
|
||
App = Ember.Application.create(); | ||
|
||
something = function(x) { | ||
if (x < 10) { | ||
return console.log("Less"); | ||
} else if (x === 10) { | ||
return console.log("Equal"); | ||
} else { | ||
return console.log("Greater"); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
TN: | ||
SF:./test/data/app.js | ||
FN:5,(anonymous_1) | ||
FNF:1 | ||
FNH:0 | ||
FNDA:0,(anonymous_1) | ||
DA:1,1 | ||
DA:3,1 | ||
DA:5,1 | ||
DA:6,0 | ||
DA:7,0 | ||
DA:8,0 | ||
DA:9,0 | ||
DA:11,0 | ||
LF:8 | ||
LH:3 | ||
BRDA:6,1,0,0 | ||
BRDA:6,1,1,0 | ||
BRDA:8,2,0,0 | ||
BRDA:8,2,1,0 | ||
BRF:4 | ||
BRH:0 | ||
end_of_record |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
var should = require('should'); | ||
var sinon = require('sinon'); | ||
var request = require('request'); | ||
var grunt = require('grunt'); | ||
var sut = require('../tasks/main'); | ||
var assert = require('assert'); | ||
|
||
describe("grunt-karma-coveralls", function(){ | ||
|
||
beforeEach(function(){ | ||
sut(grunt); | ||
}); | ||
|
||
it("shows error message when lcov data does not exist", function(done){ | ||
grunt.config('coveralls', {options: {coverage_dir: './dummy/asdf'}}); | ||
grunt.task.run('coveralls'); | ||
grunt.task.start(); | ||
done(); | ||
}); | ||
|
||
}); |