forked from FastLane-Labs/atlas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
filter_lcov.js
41 lines (34 loc) · 1.3 KB
/
filter_lcov.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
// This script is used to filter the lcov.info file generated when running `forge coverage`
// because, by default, it includes test coverage of all script (.s.sol) and test (.t.sol) files
// which are not relevant in estimating test coverage of the repo.
const fs = require('fs');
const path = require('path');
// File paths
const lcovFile = 'lcov.info'; // Original lcov file
const filteredLcovFile = 'lcov_filtered.info'; // New filtered lcov file
// Directories to exclude from the coverage report
const excludeDirs = ['test/', 'script/'];
// Read the original lcov file
fs.readFile(lcovFile, 'utf8', (err, data) => {
if (err) {
console.error(`Error reading ${lcovFile}:`, err);
return;
}
// Split the content into records
const records = data.split('end_of_record\n');
let filteredRecords = [];
records.forEach(record => {
const isExcluded = excludeDirs.some(dir => record.includes(`SF:${dir}`));
if (!isExcluded) {
filteredRecords.push(record + 'end_of_record');
}
});
// Write the filtered content to a new lcov file
fs.writeFile(filteredLcovFile, filteredRecords.join('\n'), 'utf8', err => {
if (err) {
console.error(`Error writing ${filteredLcovFile}:`, err);
return;
}
console.log(`Filtered lcov file created at ${filteredLcovFile}`);
});
});