run-coverage-partitions.ts 1.0 KB

123456789101112131415161718192021222324252627282930
  1. /** CLI entry for partitioned Vitest coverage. */
  2. import { resolve } from 'node:path'
  3. import {
  4. COVERAGE_PARTITIONS_ENV,
  5. COVERAGE_TEST_TIMEOUT_ENV,
  6. CoveragePartitionCoordinator,
  7. coverageTestTimeoutArgs,
  8. forwardedCoverageArgs,
  9. parseCoveragePartitionCount,
  10. } from './coverage-partitions.ts'
  11. const partitions = parseCoveragePartitionCount(process.env[COVERAGE_PARTITIONS_ENV])
  12. if (partitions === undefined) {
  13. throw new Error(`${COVERAGE_PARTITIONS_ENV} is required by partitioned coverage.`)
  14. }
  15. const pnpmEntrypoint = process.env.npm_execpath
  16. if (pnpmEntrypoint === undefined || pnpmEntrypoint === '') {
  17. throw new Error('partitioned coverage must be invoked through a pnpm package script.')
  18. }
  19. const coordinator = new CoveragePartitionCoordinator({
  20. root: resolve(import.meta.dirname, '..'),
  21. partitions,
  22. pnpmEntrypoint,
  23. vitestArgs: [
  24. ...coverageTestTimeoutArgs(process.env[COVERAGE_TEST_TIMEOUT_ENV]),
  25. ...forwardedCoverageArgs(process.argv.slice(2)),
  26. ],
  27. })
  28. process.exitCode = await coordinator.run()