UNPKG

5.35 kBJavaScriptView Raw
1(function (fs, parser, helper, path) {
2 'use strict';
3
4 var expect = helper.chai.expect;
5 var lcovData = fs.readFileSync(__dirname + '/mock/lcov.info').toString();
6 var noStatsLcovData = fs.readFileSync(__dirname + '/mock/no-lines.info').toString();
7 var nadaLcovData = fs.readFileSync(__dirname + '/mock/nada.info').toString();
8
9 describe('Lcov Parser', function () {
10 it('should be able to parse lcov data', function () {
11 return expect(parser.getParser('lcov').parse('', lcovData))
12 .to.eventually.satisfy(function (data) {
13 expect(data).to.deep.equal({
14 total: 92,
15 fileReports: [
16 {
17 filename: path.normalize('lib/reporter.js'),
18 coverage: {
19 1: 1,
20 25: 1,
21 39: 1,
22 40: 3,
23 44: 3,
24 48: 3,
25 50: 3,
26 52: 3,
27 54: 3,
28 55: 3,
29 61: 3,
30 63: 3,
31 67: 3,
32 73: 2,
33 74: 1,
34 75: 1,
35 76: 1,
36 77: 1,
37 79: 2,
38 81: 1,
39 82: 1,
40 83: 1,
41 84: 1,
42 87: 3
43 },
44 total: 92
45 }
46 ]
47 });
48 return true;
49 });
50 });
51 it('should be able to parse lcov data with path prefix', function () {
52 return expect(parser.getParser('lcov').parse(path.normalize('my-project' + path.sep), lcovData))
53 .to.eventually.satisfy(function (data) {
54 expect(data).to.deep.equal({
55 total: 92,
56 fileReports: [
57 {
58 filename: path.normalize('my-project/lib/reporter.js'),
59 coverage: {
60 1: 1,
61 25: 1,
62 39: 1,
63 40: 3,
64 44: 3,
65 48: 3,
66 50: 3,
67 52: 3,
68 54: 3,
69 55: 3,
70 61: 3,
71 63: 3,
72 67: 3,
73 73: 2,
74 74: 1,
75 75: 1,
76 76: 1,
77 77: 1,
78 79: 2,
79 81: 1,
80 82: 1,
81 83: 1,
82 84: 1,
83 87: 3
84 },
85 total: 92
86 }
87 ]
88 });
89 return true;
90 });
91 });
92 it('should be able to parse lcov data without lines', function () {
93 return expect(parser.getParser('lcov').parse('', noStatsLcovData))
94 .to.eventually.satisfy(function (data) {
95 expect(JSON.stringify(data)).to.equal(JSON.stringify({
96 total: 0,
97 fileReports: [
98 {
99 filename: path.normalize('lib/reporter.js'),
100 coverage: {},
101 total: 0
102 }
103 ]
104 }));
105 return true;
106 });
107 });
108 it('should be able to parse lcov data without anything', function () {
109 return expect(parser.getParser('lcov').parse('', nadaLcovData))
110 .to.eventually.satisfy(function (data) {
111 expect(JSON.stringify(data)).to.equal(JSON.stringify({
112 total: 0,
113 fileReports: [
114 {
115 filename: '',
116 coverage: {},
117 total: 0
118 }
119 ]
120 }));
121 return true;
122 });
123 });
124 });
125}(require('fs'), require('../lib/coverageParser'), require('./helper'), require('path')));