UNPKG

playwright-performance-reporter

Version:

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

47 lines (46 loc) 1.44 kB
import { performanceDomainPlugin } from '../plugins/index.js'; export class TotalJsHeapSize { name = 'totalJsHeapSize'; chromiumCompatibleName = 'JSHeapTotalSize'; plugins = [ performanceDomainPlugin, ]; /** * @inheritdoc */ async onStart(accumulator, developmentTools) { await this.common(accumulator, developmentTools); } /** * @inheritdoc */ async onSampling(accumulator, developmentTools) { await this.common(accumulator, developmentTools); } /** * @inheritdoc */ async onStop(accumulator, developmentTools) { await this.common(accumulator, developmentTools); } /** * Common function for onStart and onStop hook */ async common(accumulator, client) { return new Promise(resolve => { client.send('Performance.getMetrics', (error, cdpResponse) => { if (!cdpResponse || Boolean(error)) { resolve(false); return; } const foundMetric = cdpResponse.metrics.find(metricResponse => metricResponse.name === this.chromiumCompatibleName); if (!foundMetric) { resolve(false); return; } Object.assign(accumulator, { [this.name]: foundMetric.value }); resolve(true); }); }); } }