|
| 1 | +/** |
| 2 | + * @fileoverview Filter coverage data to exclude dist/ files |
| 3 | + * |
| 4 | + * This script post-processes V8 coverage data to remove dist/ files, |
| 5 | + * ensuring coverage reports only show src/ TypeScript files. |
| 6 | + */ |
| 7 | + |
| 8 | +import fs from 'node:fs' |
| 9 | +import path from 'node:path' |
| 10 | +import { fileURLToPath } from 'node:url' |
| 11 | + |
| 12 | +const __dirname = path.dirname(fileURLToPath(import.meta.url)) |
| 13 | +const projectRoot = path.resolve(__dirname, '..') |
| 14 | +const coveragePath = path.join(projectRoot, 'coverage/coverage-final.json') |
| 15 | + |
| 16 | +if (!fs.existsSync(coveragePath)) { |
| 17 | + console.error('Coverage file not found:', coveragePath) |
| 18 | + process.exit(1) |
| 19 | +} |
| 20 | + |
| 21 | +const coverage = JSON.parse(fs.readFileSync(coveragePath, 'utf-8')) |
| 22 | + |
| 23 | +// Filter out dist/ files |
| 24 | +const filtered = {} |
| 25 | +let distCount = 0 |
| 26 | +let srcCount = 0 |
| 27 | + |
| 28 | +for (const [file, data] of Object.entries(coverage)) { |
| 29 | + // Keep only src/ files, exclude dist/ |
| 30 | + if (file.includes('/src/') && !file.includes('/dist/')) { |
| 31 | + filtered[file] = data |
| 32 | + srcCount++ |
| 33 | + } else if (file.includes('/dist/')) { |
| 34 | + distCount++ |
| 35 | + } |
| 36 | +} |
| 37 | + |
| 38 | +console.log(`Filtered ${distCount} dist/ files`) |
| 39 | +console.log(`Kept ${srcCount} src/ files`) |
| 40 | +console.log(`Total files: ${Object.keys(coverage).length}`) |
| 41 | + |
| 42 | +fs.writeFileSync(coveragePath, JSON.stringify(filtered, null, 2)) |
| 43 | +console.log('Coverage data filtered successfully') |
0 commit comments