UNPKG

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