microsoft/typespec
Publicmirrored from https://github.com/microsoft/typespecAvailable
eng/scripts/merge-coverage.js
39lines · modecode
| 1 | // @ts-check |
| 2 | import { copyFileSync, existsSync, mkdirSync, readdirSync } from "fs"; |
| 3 | import { join } from "path"; |
| 4 | import { runOrExit } from "../../packages/internal-build-utils/dist/src/index.js"; |
| 5 | import { forEachProject, repoRoot } from "./helpers.js"; |
| 6 | |
| 7 | // Create folder to collect all coverage files |
| 8 | const rootCoverageTmp = join(repoRoot, "coverage", "tmp"); |
| 9 | mkdirSync(rootCoverageTmp, { recursive: true }); |
| 10 | |
| 11 | // Copy coverage files from each project to common folder |
| 12 | forEachProject((name, location, project) => { |
| 13 | const coverageTmp = join(location, "coverage", ".tmp"); |
| 14 | if (existsSync(coverageTmp)) { |
| 15 | const files = readdirSync(coverageTmp); |
| 16 | for (const file of files) { |
| 17 | copyFileSync(join(coverageTmp, file), join(rootCoverageTmp, file)); |
| 18 | } |
| 19 | } |
| 20 | }); |
| 21 | |
| 22 | // Generate merged report |
| 23 | await runOrExit( |
| 24 | "npm", |
| 25 | [ |
| 26 | "exec", |
| 27 | "--no", |
| 28 | "--prefix", |
| 29 | "packages/compiler", |
| 30 | "c8", |
| 31 | "--", |
| 32 | "report", |
| 33 | "--reporter=cobertura", |
| 34 | "--reporter=text", |
| 35 | ], |
| 36 | { |
| 37 | cwd: repoRoot, |
| 38 | } |
| 39 | ); |
| 40 | |