mirror of
https://github.com/bretzel-app/crumbs.git
synced 2026-10-12 12:06:57 +02:00
Add V8 coverage for unit tests via @vitest/coverage-v8 and Istanbul instrumentation for E2E tests via vite-plugin-istanbul. Coverage data is collected from browser pages after each Playwright test and merged with nyc. CI uploads both coverage reports as GitHub Actions artifacts. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
25 lines
833 B
TypeScript
25 lines
833 B
TypeScript
import { writeFileSync, mkdirSync } from 'fs';
|
|
import { join } from 'path';
|
|
import type { Page } from '@playwright/test';
|
|
|
|
const COVERAGE_DIR = join(process.cwd(), 'coverage', 'e2e', 'raw');
|
|
|
|
let counter = 0;
|
|
|
|
/**
|
|
* Collect Istanbul coverage data from the browser page.
|
|
* The vite-plugin-istanbul injects `window.__coverage__` when COVERAGE=true.
|
|
*/
|
|
export async function collectCoverage(page: Page, testTitle: string) {
|
|
if (process.env.VITE_COVERAGE !== 'true') return;
|
|
|
|
const coverage = await page.evaluate(() => (window as any).__coverage__);
|
|
if (!coverage) return;
|
|
|
|
mkdirSync(COVERAGE_DIR, { recursive: true });
|
|
|
|
const safeName = testTitle.replace(/[^a-zA-Z0-9-_]/g, '_');
|
|
const filename = `coverage-${safeName}-${counter++}-${Date.now()}.json`;
|
|
writeFileSync(join(COVERAGE_DIR, filename), JSON.stringify(coverage));
|
|
}
|