UNPKG

playwright-results-parser

Version:

Core building block for Playwright test analysis tools - provides foundational parsing, normalization, and transformation APIs that other packages can build upon.

128 lines 3.62 kB
/** * Statistics calculation for test runs */ import type { NormalizedTestRun, NormalizedTest } from "../types/index.js"; /** * Project-level statistics */ export interface ProjectStatistics { total: number; passed: number; failed: number; skipped: number; flaky: number; duration: number; } /** * File-level statistics */ export interface FileStatistics { total: number; passed: number; failed: number; skipped: number; flaky: number; duration: number; } /** * Test duration statistics */ export interface DurationStatistics { total: number; average: number; median: number; p95: number; min: number; max: number; } /** * Complete test statistics */ export interface TestStatistics { total: number; passed: number; failed: number; skipped: number; flaky: number; duration: DurationStatistics; byProject: Record<string, ProjectStatistics>; byFile: Record<string, FileStatistics>; } /** * Calculates comprehensive statistics for a test run. * Provides aggregate metrics including totals, duration statistics, and grouping by project/file. * * @param run - Normalized test run data from parsePlaywrightJson * @returns Complete statistics including counts, percentiles, and grouped metrics * * @example * ```typescript * const stats = calculateStatistics(testRun); * console.log(`Pass rate: ${(stats.passed / stats.total * 100).toFixed(2)}%`); * console.log(`P95 duration: ${stats.duration.p95}ms`); * console.log(`Flaky tests: ${stats.flaky}`); * ``` */ export declare function calculateStatistics(run: NormalizedTestRun): TestStatistics; /** * Retrieves all failed tests from a test run. * * @param run - Normalized test run data * @returns Array of tests with 'failed' status * * @example * ```typescript * const failedTests = getFailedTests(testRun); * failedTests.forEach(test => { * console.log(`Failed: ${test.fullTitle}`); * console.log(`Error: ${test.error?.message}`); * }); * ``` */ export declare function getFailedTests(run: NormalizedTestRun): NormalizedTest[]; /** * Retrieves all flaky tests from a test run. * Tests are considered flaky if they have status 'flaky' or retries > 0. * * @param run - Normalized test run data * @returns Array of flaky tests * * @example * ```typescript * const flakyTests = getFlakyTests(testRun); * console.log(`Found ${flakyTests.length} flaky tests`); * flakyTests.forEach(test => { * console.log(`Flaky: ${test.title} (${test.retries} retries)`); * }); * ``` */ export declare function getFlakyTests(run: NormalizedTestRun): NormalizedTest[]; /** * Filters tests by project name. * * @param run - Normalized test run data * @param project - Project name to filter by (e.g., 'chromium', 'firefox') * @returns Array of tests belonging to the specified project * * @example * ```typescript * const chromiumTests = getTestsByProject(testRun, 'chromium'); * console.log(`Chromium tests: ${chromiumTests.length}`); * ``` */ export declare function getTestsByProject(run: NormalizedTestRun, project: string): NormalizedTest[]; /** * Filters tests by file path. * * @param run - Normalized test run data * @param filePath - File path to filter by * @returns Array of tests from the specified file * * @example * ```typescript * const authTests = getTestsByFile(testRun, 'tests/auth.spec.ts'); * console.log(`Auth tests: ${authTests.length}`); * ``` */ export declare function getTestsByFile(run: NormalizedTestRun, filePath: string): NormalizedTest[]; //# sourceMappingURL=statistics.d.ts.map