forked from ziishaned/jest-reporter-action
-
Notifications
You must be signed in to change notification settings - Fork 101
/
Copy pathlcov_test.js
119 lines (115 loc) · 1.64 KB
/
lcov_test.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
import { parse, percentage } from "./lcov"
test("parse should parse lcov strings correctly", async function() {
const data = `
TN:
SF:/files/project/foo.js
FN:19,foo
FN:33,bar
FN:54,baz
FNF:3
FNH:2
DA:20,3
DA:21,3
DA:22,3
LF:23
LH:21
BRDA:21,0,0,1
BRDA:21,0,1,2
BRDA:22,1,0,1
BRDA:22,1,1,2
BRDA:37,2,0,0
BRF:5
BRH:4
end_of_record
`
const lcov = await parse(data)
expect(lcov).toEqual([
{
title: "",
file: "/files/project/foo.js",
lines: {
found: 23,
hit: 21,
details: [
{
line: 20,
hit: 3,
},
{
line: 21,
hit: 3,
},
{
line: 22,
hit: 3,
},
],
},
functions: {
hit: 2,
found: 3,
details: [
{
name: "foo",
line: 19,
},
{
name: "bar",
line: 33,
},
{
name: "baz",
line: 54,
},
],
},
branches: {
hit: 4,
found: 5,
details: [
{
line: 21,
block: 0,
branch: 0,
taken: 1,
},
{
line: 21,
block: 0,
branch: 1,
taken: 2,
},
{
line: 22,
block: 1,
branch: 0,
taken: 1,
},
{
line: 22,
block: 1,
branch: 1,
taken: 2,
},
{
line: 37,
block: 2,
branch: 0,
taken: 0,
},
],
},
},
])
})
test("parse should fail on invalid lcov", async function() {
await expect(parse("invalid")).rejects.toBe("Failed to parse string")
})
test("percentage should calculate the correct percentage", function() {
expect(
percentage([
{ lines: { hit: 20, found: 25 } },
{ lines: { hit: 10, found: 15 } },
]),
).toBe(75)
})