UNPKG

playwright-performance-reporter

Version:

Measure and publish performance metrics from browser dev-tools when running playwright

90 lines (89 loc) 2.81 kB
import { type MeasurePlugin, type OnSamplingMeasure, type OnStartMeasure, type OnStopMeasure } from './index.js'; /** * Supported hooks to run measurements on */ export declare const hooks: readonly ["onTest", "onTestStep"]; export type Hooks = typeof hooks[number]; export declare const hookOrder: readonly ["onStart", "onSampling", "onStop"]; export type HookOrder = typeof hookOrder[number]; /** * All metrics implemented in the reporter */ export declare const metrics: readonly ["usedJsHeapSize", "totalJsHeapSize", "jsHeapSizeLimit", "powerInWatts", "allPerformanceMetrics", "heapDump"]; export type Metrics = typeof metrics[number]; /** * Common interface to define procedures to observe metrics */ export type MetricObserver = { name: string; plugins: MeasurePlugin[]; onStart: OnStartMeasure; onSampling: OnSamplingMeasure; onStop: OnStopMeasure; }; /** * Define which metric should regularly be requested */ export type MetricSampling = { samplingTimeoutInMilliseconds: number; }; /** * Browsers that have been tested to work with performance metric extraction */ export declare const supportedBrowsers: readonly ["chromium", "webkit", "firefox"]; export type SupportedBrowsers = typeof supportedBrowsers[number]; /** * Restrict metrics to browsers as some don't expose APIs or * don't support extraction at all */ export declare const browsersSupportingMetrics: { readonly chromium: readonly ["usedJsHeapSize", "totalJsHeapSize", "allPerformanceMetrics", "heapDump"]; readonly firefox: readonly []; readonly webkit: readonly []; }; export type ChromiumSupportedMetrics = typeof browsersSupportingMetrics.chromium[number] & Metrics; export type OptionsFileWrite = { outputDir: string; outputFile: string; }; export type JsonWriter = { /** * Initialize writer * * @param options defines target output */ initialize(options: OptionsFileWrite): void; /** * Create new entry of an object * * @param content */ write(content: Record<any, any>): boolean; /** * Finish json stream */ close(): void; /** * Delete created target */ delete(): boolean; }; /** * Customize the reporter with desired browser and (custom) metrics */ export type Options = { outputDir: string; outputFile: string; deleteOnFailure: boolean; customJsonWriter?: JsonWriter; browsers: { [browser in SupportedBrowsers]?: { [hook in Hooks]?: { metrics: Array<typeof browsersSupportingMetrics[browser][number] & Metrics>; customMetrics?: Record<string, MetricObserver>; sampleMetrics?: Record<string, MetricSampling>; }; }; }; }; export declare const defaultOptions: Options;