forked from VeryGoodOpenSource/very_good_coverage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test.js
126 lines (114 loc) · 4.17 KB
/
index.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
120
121
122
123
124
125
126
const process = require('process');
const cp = require('child_process');
const path = require('path');
const { fail } = require('assert');
const getErrorOutput = (error) => {
const output = Array(...error.output)
.filter((line) => !!line)
.map((line) => line.toString().replace(/%0A/g, '\n'))
.filter((line) => line.trim().length > 0)
.join('\n');
return output;
};
test('empty LCOV throws an error', () => {
const lcovPath = './fixtures/lcov.empty.info';
process.env['INPUT_PATH'] = lcovPath;
const ip = path.join(__dirname, 'index.js');
try {
cp.execSync(`node ${ip}`, { env: process.env });
fail('this code should fail');
} catch (err) {
expect(err).toBeDefined();
const errorMessage = err.stdout.toString();
expect(errorMessage).toContain('lcov is empty!');
}
});
test('invalid LCOV format throws an error', () => {
const lcovPath = './fixtures/lcov.error.info';
process.env['INPUT_PATH'] = lcovPath;
const ip = path.join(__dirname, 'index.js');
try {
cp.execSync(`node ${ip}`, { env: process.env }).toString();
fail('this code should fail');
} catch (err) {
expect(err).toBeDefined();
const errorMessage = err.stdout.toString();
expect(errorMessage).toContain('parsing error!');
}
});
test('completes when the coverage is 100 and min_coverage is not provided', () => {
const lcovPath = './fixtures/lcov.100.info';
process.env['INPUT_PATH'] = lcovPath;
const ip = path.join(__dirname, 'index.js');
cp.execSync(`node ${ip}`, { env: process.env }).toString();
});
test('completes when the coverage is higher than the threshold after excluding files', () => {
const lcovPath = './fixtures/lcov.100.info';
const exclude = '**/*_observer.dart';
process.env['INPUT_PATH'] = lcovPath;
process.env['INPUT_EXCLUDE'] = exclude;
const ip = path.join(__dirname, 'index.js');
cp.execSync(`node ${ip}`, { env: process.env }).toString();
});
test('fails when the coverage is not 100 and min_coverage is not provided', () => {
const lcovPath = './fixtures/lcov.95.info';
process.env['INPUT_PATH'] = lcovPath;
const ip = path.join(__dirname, 'index.js');
try {
cp.execSync(`node ${ip}`, { env: process.env }).toString();
fail('this code should fail');
} catch (err) {
expect(err).toBeDefined();
}
});
test('fails when the coverage is below the min_coverage, even if we exclude files', () => {
const lcovPath = './fixtures/lcov.100.info';
const exclude = '**/does_not_exist.dart';
process.env['INPUT_PATH'] = lcovPath;
process.env['INPUT_EXCLUDE'] = exclude;
const ip = path.join(__dirname, 'index.js');
try {
cp.execSync(`node ${ip}`, { env: process.env }).toString();
fail('this code should fail');
} catch (err) {
expect(err).toBeDefined();
}
});
test('completes when the coverage is above the given min_threshold', () => {
const lcovPath = './fixtures/lcov.95.info';
const minCoverage = 80;
process.env['INPUT_PATH'] = lcovPath;
process.env['INPUT_MIN_COVERAGE'] = minCoverage;
const ip = path.join(__dirname, 'index.js');
cp.execSync(`node ${ip}`, { env: process.env }).toString();
});
test('fails when the coverage is below the given min_threshold', () => {
const lcovPath = './fixtures/lcov.95.info';
const minCoverage = 98;
process.env['INPUT_PATH'] = lcovPath;
process.env['INPUT_MIN_COVERAGE'] = minCoverage;
const ip = path.join(__dirname, 'index.js');
try {
cp.execSync(`node ${ip}`, { env: process.env }).toString();
fail('this code should fail');
} catch (err) {
expect(err).toBeDefined();
}
});
test('shows lines that are missing coverage when failure occurs', () => {
const lcovPath = './fixtures/lcov.95.info';
const minCoverage = 100;
process.env['INPUT_PATH'] = lcovPath;
process.env['INPUT_MIN_COVERAGE'] = minCoverage;
const ip = path.join(__dirname, 'index.js');
try {
cp.execSync(`node ${ip}`, { env: process.env }).toString();
fail('this code should fail');
} catch (err) {
const output = getErrorOutput(err);
expect(output).toContain('Lines not covered');
expect(output).toContain(
'/Users/felix/Development/github.com/felangel/bloc/packages/bloc/lib/src/bloc_observer.dart: 20, 27, 36, 43, 51'
);
}
});