@wordpress/e2e-test-utils-playwright
Version:
End-To-End (E2E) test utils for WordPress.
8 lines (7 loc) • 3.06 kB
Source Map (JSON)
{
"version": 3,
"sources": ["../../src/lighthouse/index.ts"],
"sourcesContent": ["/**\n * External dependencies\n */\nimport type { Page } from '@playwright/test';\nimport lighthouse from 'lighthouse/core/index.cjs';\n\ntype LighthouseConstructorProps = {\n\tpage: Page;\n\tport: number;\n};\n\nexport class Lighthouse {\n\tpage: Page;\n\tport: number;\n\n\tconstructor( { page, port }: LighthouseConstructorProps ) {\n\t\tthis.page = page;\n\t\tthis.port = port;\n\t}\n\n\t/**\n\t * Returns the Lighthouse report for the current URL.\n\t *\n\t * Runs several Lighthouse audits in a separate browser window and returns\n\t * the summary.\n\t */\n\tasync getReport() {\n\t\t// From https://github.com/GoogleChrome/lighthouse/blob/36cac182a6c637b1671c57326d7c0241633d0076/core/config/default-config.js#L381-L446\n\t\tconst audits = {\n\t\t\t'largest-contentful-paint': 'LCP',\n\t\t\t'total-blocking-time': 'TBT',\n\t\t\tinteractive: 'TTI',\n\t\t\t'cumulative-layout-shift': 'CLS',\n\t\t\t'interaction-to-next-paint': 'INP',\n\t\t};\n\n\t\tconst report = await lighthouse(\n\t\t\tthis.page.url(),\n\t\t\t{ port: this.port },\n\t\t\t{\n\t\t\t\textends: 'lighthouse:default',\n\t\t\t\tsettings: {\n\t\t\t\t\t// \"provided\" means no throttling.\n\t\t\t\t\t// TODO: Make configurable.\n\t\t\t\t\tthrottlingMethod: 'provided',\n\t\t\t\t\t// Default is \"mobile\".\n\t\t\t\t\t// See https://github.com/GoogleChrome/lighthouse/blob/main/docs/emulation.md\n\t\t\t\t\t// TODO: Make configurable.\n\t\t\t\t\tformFactor: 'desktop',\n\t\t\t\t\tscreenEmulation: {\n\t\t\t\t\t\tdisabled: true,\n\t\t\t\t\t},\n\t\t\t\t\t// Speeds up the report.\n\t\t\t\t\tdisableFullPageScreenshot: true,\n\t\t\t\t\t// Only run certain audits to speed things up.\n\t\t\t\t\tonlyAudits: Object.keys( audits ),\n\t\t\t\t},\n\t\t\t}\n\t\t);\n\n\t\tconst result: Record< string, number > = {};\n\n\t\tif ( ! report ) {\n\t\t\treturn result;\n\t\t}\n\n\t\tconst { lhr } = report;\n\n\t\tfor ( const [ audit, acronym ] of Object.entries( audits ) ) {\n\t\t\tresult[ acronym ] = lhr.audits[ audit ]?.numericValue || 0;\n\t\t}\n\n\t\treturn result;\n\t}\n}\n"],
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,kBAAuB;AAOhB,IAAM,aAAN,MAAiB;AAAA,EACvB;AAAA,EACA;AAAA,EAEA,YAAa,EAAE,MAAM,KAAK,GAAgC;AACzD,SAAK,OAAO;AACZ,SAAK,OAAO;AAAA,EACb;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,YAAY;AAEjB,UAAM,SAAS;AAAA,MACd,4BAA4B;AAAA,MAC5B,uBAAuB;AAAA,MACvB,aAAa;AAAA,MACb,2BAA2B;AAAA,MAC3B,6BAA6B;AAAA,IAC9B;AAEA,UAAM,SAAS,UAAM,YAAAA;AAAA,MACpB,KAAK,KAAK,IAAI;AAAA,MACd,EAAE,MAAM,KAAK,KAAK;AAAA,MAClB;AAAA,QACC,SAAS;AAAA,QACT,UAAU;AAAA;AAAA;AAAA,UAGT,kBAAkB;AAAA;AAAA;AAAA;AAAA,UAIlB,YAAY;AAAA,UACZ,iBAAiB;AAAA,YAChB,UAAU;AAAA,UACX;AAAA;AAAA,UAEA,2BAA2B;AAAA;AAAA,UAE3B,YAAY,OAAO,KAAM,MAAO;AAAA,QACjC;AAAA,MACD;AAAA,IACD;AAEA,UAAM,SAAmC,CAAC;AAE1C,QAAK,CAAE,QAAS;AACf,aAAO;AAAA,IACR;AAEA,UAAM,EAAE,IAAI,IAAI;AAEhB,eAAY,CAAE,OAAO,OAAQ,KAAK,OAAO,QAAS,MAAO,GAAI;AAC5D,aAAQ,OAAQ,IAAI,IAAI,OAAQ,KAAM,GAAG,gBAAgB;AAAA,IAC1D;AAEA,WAAO;AAAA,EACR;AACD;",
"names": ["lighthouse"]
}