Skip to content

Commit

Permalink
Merge pull request #67 from jrjohnson/63-renamer
Browse files Browse the repository at this point in the history
Added an option for lcov to rename SF property
  • Loading branch information
jschilli committed May 31, 2015
2 parents 24928c2 + 7cead0a commit f14b8e9
Show file tree
Hide file tree
Showing 5 changed files with 194 additions and 7 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ var options = {
outputFile: 'test-output.json' // default is 'coverage.json'
},
lcovOptions: {
outputFile: 'lcov.dat'
outputFile: 'lcov.dat',
//provide a function to rename es6 modules to a file path
renamer: function(moduleName){
var expression = /^APP_NAME/;
return moduleName.replace(expression, 'app') + '.js';
}
},
reporters: ['json']
}
Expand Down
12 changes: 8 additions & 4 deletions lib/reporters/lcov-reporter.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
var Reporter = require('../reporter');

var lcovRecord = function(data) {

var str = "",
lineHandled = 0,
lineFound = 0;
lineFound = 0,
fileName = data.fileName;

if(this.options.lcovOptions && this.options.lcovOptions.renamer){
fileName = this.options.lcovOptions.renamer(fileName);
}

str += 'SF:' + data.fileName + '\n';
str += 'SF:' + fileName + '\n';
data.lines.forEach(function(value, num) {
if (value !== null) {
str += 'DA:' + num + ',' + value + '\n';
Expand All @@ -33,7 +37,7 @@ module.exports = Reporter.extend({
name: 'lcov',
defaultOutput: 'lcov.dat',
transform: function(coverageData) {
var data = coverageData.fileData.map(lcovRecord);
var data = coverageData.fileData.map(lcovRecord, this);
return data.join('\n');
}
});
File renamed without changes.
167 changes: 167 additions & 0 deletions tests/fixtures/lcov-output-with-renamer.dat
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
SF:something-else/app
DA:1,1
DA:5,1
DA:7,1
DA:9,1
DA:15,1
DA:17,1
LF:6
LH:6
end_of_record
SF:something-else/config/environment
DA:1,1
DA:4,0
DA:7,0
DA:8,0
DA:9,0
DA:10,0
DA:12,0
DA:15,0
LF:8
LH:1
end_of_record
SF:something-else/initializers/app-version
DA:1,1
DA:5,1
DA:7,1
DA:9,1
DA:12,8
DA:13,8
LF:6
LH:6
end_of_record
SF:something-else/initializers/export-application-global
DA:1,1
DA:5,1
DA:7,1
DA:9,1
DA:10,8
DA:12,8
DA:13,1
DA:19,1
LF:8
LH:8
end_of_record
SF:something-else/router
DA:1,1
DA:5,1
DA:7,1
DA:11,1
DA:12,1
DA:13,1
DA:14,1
DA:18,1
LF:8
LH:8
end_of_record
SF:something-else/models/todo
DA:1,1
DA:5,1
DA:7,1
DA:12,1
LF:4
LH:4
end_of_record
SF:something-else/controllers/todo
DA:1,1
DA:5,1
DA:7,1
DA:10,3
DA:13,2
DA:15,2
DA:16,1
DA:18,1
DA:22,3
DA:23,3
DA:24,3
DA:31,14
DA:32,14
DA:34,14
DA:36,14
DA:39,0
DA:40,0
DA:41,0
LF:18
LH:15
end_of_record
SF:something-else/utils/util
DA:1,1
DA:5,1
DA:7,1
DA:9,2
DA:11,14
DA:12,14
DA:16,1
LF:7
LH:7
end_of_record
SF:something-else/controllers/todos
DA:1,1
DA:5,1
DA:7,1
DA:11,1
DA:12,1
DA:13,0
DA:17,1
DA:23,1
DA:26,1
DA:30,0
DA:31,0
DA:32,0
DA:37,9
DA:41,7
DA:42,7
DA:46,7
DA:50,9
DA:54,9
DA:55,9
DA:57,0
DA:58,0
DA:59,0
LF:22
LH:15
end_of_record
SF:something-else/routes/todos
DA:1,1
DA:5,1
DA:7,1
DA:9,4
LF:4
LH:4
end_of_record
SF:something-else/routes/todos/active
DA:1,1
DA:5,1
DA:7,1
DA:9,0
DA:10,0
DA:14,0
LF:6
LH:3
end_of_record
SF:something-else/routes/todos/completed
DA:1,1
DA:5,1
DA:7,1
DA:9,0
DA:10,0
DA:14,0
LF:6
LH:3
end_of_record
SF:something-else/routes/todos/index
DA:1,1
DA:5,1
DA:7,1
DA:9,4
LF:4
LH:4
end_of_record
SF:something-else/adapters/application
DA:1,1
DA:5,1
DA:7,1
DA:11,1
LF:4
LH:4
end_of_record
15 changes: 13 additions & 2 deletions tests/unit/reporters/lcov-reporter-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,21 @@ var LCOVReporter = require('../../../lib/reporters/lcov-reporter');

describe('LCOV Reporter', function() {
it('should work without branches or modules', function () {
var expectedOutput = fs.readFileSync(path.join(__dirname, '../../fixtures/lcov.dat'), 'utf8');
var expectedOutput = fs.readFileSync(path.join(__dirname, '../../fixtures/lcov-output-no-renamer.dat'), 'utf8');
var reporter = new LCOVReporter({});
var output = reporter.transform(fixture);
expect(output).to.deep.equal(expectedOutput);
});
it('should replace modules names with file names when requested', function () {
var expectedOutput = fs.readFileSync(path.join(__dirname, '../../fixtures/lcov-output-with-renamer.dat'), 'utf8');
var reporter = new LCOVReporter({
lcovOptions: {
renamer: function(moduleName){
return moduleName.replace(/^todomvc-ember-cli/, 'something-else');
}
}
});
var output = reporter.transform(fixture);
expect(output).to.deep.equal(expectedOutput);
});
});

0 comments on commit f14b8e9

Please sign in to comment.