-
Notifications
You must be signed in to change notification settings - Fork 257
/
convertLcovToCoveralls.js
149 lines (127 loc) · 5.26 KB
/
convertLcovToCoveralls.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
var convertLcovToCoveralls = require('../index').convertLcovToCoveralls;
var getOptions = require('../index').getOptions;
var should = require('should');
var fs = require('fs');
var logger = require('../lib/logger');
var path = require('path');
logger = require('log-driver')({level : false});
describe("convertLcovToCoveralls", function(){
it ("should convert a simple lcov file", function(done){
delete process.env.TRAVIS;
var lcovpath = __dirname + "/../fixtures/onefile.lcov";
var input = fs.readFileSync(lcovpath, "utf8");
var libpath = __dirname + "/../fixtures/lib";
convertLcovToCoveralls(input, {filepath: libpath}, function(err, output){
should.not.exist(err);
output.source_files[0].name.should.equal("index.js");
output.source_files[0].source.split("\n").length.should.equal(173);
output.source_files[0].coverage[54].should.equal(0);
output.source_files[0].coverage[60].should.equal(0);
done();
});
});
it ("should pass on all appropriate parameters from the environment", function(done){
delete process.env.TRAVIS;
process.env.COVERALLS_GIT_COMMIT = "GIT_HASH";
process.env.COVERALLS_GIT_BRANCH = "master";
process.env.COVERALLS_SERVICE_NAME = "SERVICE_NAME";
process.env.COVERALLS_SERVICE_JOB_ID = "SERVICE_JOB_ID";
process.env.COVERALLS_REPO_TOKEN = "REPO_TOKEN";
process.env.CI_PULL_REQUEST = "https://github.com/fake/fake/pulls/123";
process.env.COVERALLS_PARALLEL = "true";
getOptions(function(err, options){
var lcovpath = __dirname + "/../fixtures/onefile.lcov";
var input = fs.readFileSync(lcovpath, "utf8");
var libpath = "fixtures/lib";
options.filepath = libpath;
convertLcovToCoveralls(input, options, function(err, output){
should.not.exist(err);
output.service_pull_request.should.equal("123");
output.parallel.should.equal(true);
//output.git.should.equal("GIT_HASH");
done();
});
});
});
it ("should work with a relative path as well", function(done){
delete process.env.TRAVIS;
var lcovpath = __dirname + "/../fixtures/onefile.lcov";
var input = fs.readFileSync(lcovpath, "utf8");
var libpath = "fixtures/lib";
convertLcovToCoveralls(input, {filepath: libpath}, function(err, output){
should.not.exist(err);
output.source_files[0].name.should.equal("index.js");
output.source_files[0].source.split("\n").length.should.equal(173);
done();
});
});
it ("should convert absolute input paths to relative", function(done){
delete process.env.TRAVIS;
var lcovpath = __dirname + "/../fixtures/istanbul.lcov";
var input = fs.readFileSync(lcovpath, "utf8");
var libpath = "/Users/deepsweet/Dropbox/projects/svgo/lib";
var sourcepath = path.resolve(libpath, "svgo/config.js");
var originalReadFileSync = fs.readFileSync;
fs.readFileSync = function(filepath) {
if (filepath === sourcepath) {
return '';
}
return originalReadFileSync.apply(fs, arguments);
};
var originalExistsSync = fs.existsSync;
fs.existsSync = function () { return true; };
convertLcovToCoveralls(input, {filepath: libpath}, function(err, output){
fs.readFileSync = originalReadFileSync;
fs.existsSync = originalExistsSync;
should.not.exist(err);
output.source_files[0].name.should.equal(path.join("svgo", "config.js"));
done();
});
});
it ("should ignore files that do not exists", function(done){
delete process.env.TRAVIS;
var lcovpath = __dirname + "/../fixtures/istanbul.lcov";
var input = fs.readFileSync(lcovpath, "utf8");
var libpath = "/Users/deepsweet/Dropbox/projects/svgo/lib";
var sourcepath = path.resolve(libpath, "svgo/config.js");
var originalReadFileSync = fs.readFileSync;
fs.readFileSync = function(filepath) {
if (filepath === sourcepath) {
return '';
}
return originalReadFileSync.apply(fs, arguments);
};
var originalExistsSync = fs.existsSync;
fs.existsSync = function () { return false; };
convertLcovToCoveralls(input, {filepath: libpath}, function(err, output){
fs.readFileSync = originalReadFileSync;
fs.existsSync = originalExistsSync;
should.not.exist(err);
output.source_files.should.be.empty();
done();
});
});
it ("should parse file paths concatenated by typescript and ng 2", function(done) {
process.env.TRAVIS_JOB_ID = -1;
var lcovpath = __dirname + "/../fixtures/istanbul.remap.lcov";
var input = fs.readFileSync(lcovpath, "utf8");
var libpath = "/Users/deepsweet/Dropbox/projects/svgo/lib";
var sourcepath = path.resolve(libpath, "svgo/config.js");
var originalReadFileSync = fs.readFileSync;
fs.readFileSync = function(filepath) {
if (filepath === sourcepath) {
return '';
}
return originalReadFileSync.apply(fs, arguments);
};
var originalExistsSync = fs.existsSync;
fs.existsSync = function () { return true; };
convertLcovToCoveralls(input, {filepath: libpath}, function(err, output){
fs.readFileSync = originalReadFileSync;
fs.existsSync = originalExistsSync;
should.not.exist(err);
output.source_files[0].name.should.equal(path.join("svgo", "config.js"));
done();
});
});
});