// The page's coverage report, once every test has added its page's (coverage.ts, #390), and its // lines file by file in summary.json, which scripts/coverage-metrics.ts reads for Grafana (#394). import fs from 'node:fs'; import path from 'node:path'; import { CoverageReport } from 'monocart-coverage-reports'; import { coverageOptions } from './coverage.ts'; /// Where a coverage run's page unit and native-bridge tests write V8's record of what they ran. export const NODE_COVERAGE = 'target/coverage/node-v8'; export default async function teardown() { if (!process.env.IPX_COVERAGE) return; const report = new CoverageReport(coverageOptions); // What the page's Node tests ran of it, when the run measured them first (NODE_V8_COVERAGE, #407). if (fs.existsSync(NODE_COVERAGE)) await report.addFromDir(NODE_COVERAGE); const results = await report.generate(); if (!results) return; const lines = results.files.map((f) => ({ file: f.sourcePath, covered: f.summary.lines.covered, total: f.summary.lines.total })); fs.writeFileSync(path.join(coverageOptions.outputDir!, 'summary.json'), JSON.stringify({ lines }, null, 2)); }