@wdio/lighthouse-service 9.0.0-alpha.321

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/LICENSE-MIT +20 -0
  2. package/README.md +258 -0
  3. package/build/auditor.d.ts +54 -0
  4. package/build/auditor.d.ts.map +1 -0
  5. package/build/auditor.js +147 -0
  6. package/build/commands.d.ts +86 -0
  7. package/build/commands.d.ts.map +1 -0
  8. package/build/commands.js +212 -0
  9. package/build/constants.d.ts +95 -0
  10. package/build/constants.d.ts.map +1 -0
  11. package/build/constants.js +150 -0
  12. package/build/gatherer/devtools.d.ts +19 -0
  13. package/build/gatherer/devtools.d.ts.map +1 -0
  14. package/build/gatherer/devtools.js +12 -0
  15. package/build/gatherer/pwa.d.ts +28 -0
  16. package/build/gatherer/pwa.d.ts.map +1 -0
  17. package/build/gatherer/pwa.js +66 -0
  18. package/build/gatherer/trace.d.ts +61 -0
  19. package/build/gatherer/trace.d.ts.map +1 -0
  20. package/build/gatherer/trace.js +233 -0
  21. package/build/handler/network.d.ts +45 -0
  22. package/build/handler/network.d.ts.map +1 -0
  23. package/build/handler/network.js +133 -0
  24. package/build/index.d.ts +50 -0
  25. package/build/index.d.ts.map +1 -0
  26. package/build/index.js +126 -0
  27. package/build/lighthouse/cri.d.ts +23 -0
  28. package/build/lighthouse/cri.d.ts.map +1 -0
  29. package/build/lighthouse/cri.js +29 -0
  30. package/build/scripts/collectMetaElements.d.ts +8 -0
  31. package/build/scripts/collectMetaElements.d.ts.map +1 -0
  32. package/build/scripts/collectMetaElements.js +37 -0
  33. package/build/scripts/registerPerformanceObserverInPage.d.ts +12 -0
  34. package/build/scripts/registerPerformanceObserverInPage.d.ts.map +1 -0
  35. package/build/scripts/registerPerformanceObserverInPage.js +23 -0
  36. package/build/types.d.ts +168 -0
  37. package/build/types.d.ts.map +1 -0
  38. package/build/types.js +1 -0
  39. package/build/utils.d.ts +23 -0
  40. package/build/utils.d.ts.map +1 -0
  41. package/build/utils.js +64 -0
  42. package/package.json +66 -0
@@ -0,0 +1,37 @@
1
+ export default function collectMetaElements() {
2
+ const selector = 'head meta';
3
+ const realMatchesFn = window.Element.prototype.matches;
4
+ const metas = [];
5
+ const _findAllElements = (nodes) => {
6
+ // eslint-disable-next-line no-cond-assign
7
+ for (let i = 0, el; el = nodes[i]; ++i) {
8
+ if (!selector || realMatchesFn.call(el, selector)) {
9
+ metas.push(el);
10
+ }
11
+ // If the element has a shadow root, dig deeper.
12
+ if (el.shadowRoot) {
13
+ _findAllElements(el.shadowRoot.querySelectorAll('*'));
14
+ }
15
+ }
16
+ };
17
+ _findAllElements(document.querySelectorAll('*'));
18
+ return metas.map(meta => {
19
+ const getAttribute = (name) => {
20
+ const attr = meta.attributes.getNamedItem(name);
21
+ if (!attr) {
22
+ return;
23
+ }
24
+ return attr.value;
25
+ };
26
+ return {
27
+ // @ts-ignore
28
+ name: meta.name.toLowerCase(),
29
+ // @ts-ignore
30
+ content: meta.content,
31
+ property: getAttribute('property'),
32
+ // @ts-ignore
33
+ httpEquiv: meta.httpEquiv ? meta.httpEquiv.toLowerCase() : undefined,
34
+ charset: getAttribute('charset'),
35
+ };
36
+ });
37
+ }
@@ -0,0 +1,12 @@
1
+ declare global {
2
+ interface Window {
3
+ ____lastLongTask: number;
4
+ ____lhPerformanceObserver: PerformanceObserver;
5
+ }
6
+ }
7
+ /**
8
+ * Used by _waitForCPUIdle and executed in the context of the page, updates the ____lastLongTask
9
+ * property on window to the end time of the last long task.
10
+ */
11
+ export default function registerPerformanceObserverInPage(): void;
12
+ //# sourceMappingURL=registerPerformanceObserverInPage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registerPerformanceObserverInPage.d.ts","sourceRoot":"","sources":["../../src/scripts/registerPerformanceObserverInPage.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,CAAC;IACX,UAAU,MAAM;QACZ,gBAAgB,EAAE,MAAM,CAAA;QACxB,yBAAyB,EAAE,mBAAmB,CAAA;KACjD;CACJ;AAED;;;GAGG;AAEH,MAAM,CAAC,OAAO,UAAU,iCAAiC,SAmBxD"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Used by _waitForCPUIdle and executed in the context of the page, updates the ____lastLongTask
3
+ * property on window to the end time of the last long task.
4
+ */
5
+ export default function registerPerformanceObserverInPage() {
6
+ window.____lastLongTask = window.performance.now();
7
+ const observer = new window.PerformanceObserver(entryList => {
8
+ const entries = entryList.getEntries();
9
+ for (const entry of entries) {
10
+ if (entry.entryType === 'longtask') {
11
+ const taskEnd = entry.startTime + entry.duration;
12
+ window.____lastLongTask = Math.max(window.____lastLongTask, taskEnd);
13
+ }
14
+ }
15
+ });
16
+ observer.observe({ entryTypes: ['longtask'] });
17
+ // HACK: A PerformanceObserver will be GC'd if there are no more references to it, so attach it to
18
+ // window to ensure we still receive longtask notifications. See https://crbug.com/742530.
19
+ // For an example test of this behavior see https://gist.github.com/patrickhulce/69d8bed1807e762218994b121d06fea6.
20
+ // FIXME COMPAT: This hack isn't neccessary as of Chrome 62.0.3176.0
21
+ // https://bugs.chromium.org/p/chromium/issues/detail?id=742530#c7
22
+ window.____lhPerformanceObserver = observer;
23
+ }
@@ -0,0 +1,168 @@
1
+ import type { TraceStreamJson } from '@tracerbench/trace-event';
2
+ import type { ReportOptions } from 'istanbul-reports';
3
+ import type { Totals, CoverageSummaryData } from 'istanbul-lib-coverage';
4
+ import type { Viewport } from 'puppeteer-core/lib/esm/puppeteer/common/Viewport.js';
5
+ import type { NETWORK_STATES, PWA_AUDITS } from './constants.js';
6
+ export interface DevtoolsConfig {
7
+ coverageReporter?: CoverageReporterOptions;
8
+ }
9
+ export interface CoverageReporterOptions {
10
+ /**
11
+ * whether or not to enable code coverage reporting
12
+ * @default false
13
+ */
14
+ enable?: boolean;
15
+ /**
16
+ * Directory where JS coverage reports are stored
17
+ */
18
+ logDir?: string;
19
+ /**
20
+ * format of report
21
+ * @default json
22
+ */
23
+ type?: keyof ReportOptions;
24
+ /**
25
+ * Options for coverage report
26
+ */
27
+ options?: any;
28
+ /**
29
+ * Exclude code coverage files
30
+ * @default []
31
+ */
32
+ exclude?: (RegExp | string)[];
33
+ }
34
+ export type FormFactor = 'mobile' | 'desktop' | 'none';
35
+ export interface EnablePerformanceAuditsOptions {
36
+ cacheEnabled: boolean;
37
+ cpuThrottling: number;
38
+ networkThrottling: keyof typeof NETWORK_STATES;
39
+ formFactor: FormFactor;
40
+ }
41
+ export interface DeviceDescription {
42
+ viewport: Viewport;
43
+ userAgent: string;
44
+ }
45
+ export interface Device {
46
+ name: string;
47
+ userAgent: string;
48
+ viewport: {
49
+ width: number;
50
+ height: number;
51
+ deviceScaleFactor: number;
52
+ isMobile: boolean;
53
+ hasTouch: boolean;
54
+ isLandscape: boolean;
55
+ };
56
+ }
57
+ export interface DeviceOptions {
58
+ osVersion: string;
59
+ inLandscape: boolean;
60
+ }
61
+ export interface Audit {
62
+ audit: (opts: any, context: any) => Promise<any>;
63
+ defaultOptions: Record<string, any>;
64
+ }
65
+ export interface AuditResults {
66
+ 'speed-index': MetricsResult;
67
+ 'first-contentful-paint': MetricsResult;
68
+ 'largest-contentful-paint': MetricsResult;
69
+ 'cumulative-layout-shift': MetricsResult;
70
+ 'total-blocking-time': MetricsResult;
71
+ interactive: MetricsResult;
72
+ }
73
+ export interface AuditRef {
74
+ id: keyof AuditResults;
75
+ weight: number;
76
+ }
77
+ export interface MainThreadWorkBreakdownResult {
78
+ details: {
79
+ items: {
80
+ group: string;
81
+ duration: number;
82
+ }[];
83
+ };
84
+ }
85
+ export interface DiagnosticsResults {
86
+ details: {
87
+ items: any[];
88
+ };
89
+ }
90
+ export interface ResponseTimeResult {
91
+ numericValue: number;
92
+ }
93
+ export interface MetricsResult {
94
+ score: number;
95
+ }
96
+ export interface MetricsResults {
97
+ details: {
98
+ items: {
99
+ observedDomContentLoaded: number;
100
+ observedFirstVisualChange: number;
101
+ observedFirstPaint: number;
102
+ firstContentfulPaint: number;
103
+ firstMeaningfulPaint: number;
104
+ largestContentfulPaint: number;
105
+ observedLastVisualChange: number;
106
+ interactive: number;
107
+ observedLoad: number;
108
+ speedIndex: number;
109
+ totalBlockingTime: number;
110
+ maxPotentialFID: number;
111
+ }[];
112
+ };
113
+ }
114
+ export interface LHAuditResult {
115
+ score: number;
116
+ warnings?: any[];
117
+ notApplicable?: boolean;
118
+ numericValue?: number;
119
+ numericUnit?: string;
120
+ displayValue?: {
121
+ i18nId: string;
122
+ values: any;
123
+ formattedDefault: string;
124
+ };
125
+ details?: any;
126
+ }
127
+ export interface AuditResult {
128
+ passed: boolean;
129
+ details: Record<string, LHAuditResult | ErrorAudit>;
130
+ }
131
+ export interface ErrorAudit {
132
+ score: 0;
133
+ error: Error;
134
+ }
135
+ export type PWAAudits = keyof typeof PWA_AUDITS;
136
+ export type NetworkStates = 'offline' | 'GPRS' | 'Regular 2G' | 'Good 2G' | 'Regular 3G' | 'Good 3G' | 'Regular 4G' | 'DSL' | 'Wifi' | 'online';
137
+ export interface Coverage {
138
+ lines: Totals;
139
+ statements: Totals;
140
+ functions: Totals;
141
+ branches: Totals;
142
+ files: Record<string, CoverageSummaryData>;
143
+ }
144
+ export interface CustomDevice {
145
+ viewport: Viewport;
146
+ userAgent: string;
147
+ }
148
+ export type DeviceProfiles = 'Blackberry PlayBook' | 'BlackBerry Z30' | 'Galaxy Note 3' | 'Galaxy Note II' | 'Galaxy S III' | 'Galaxy S5' | 'iPad' | 'iPad Mini' | 'iPad Pro' | 'iPhone 4' | 'iPhone 5' | 'iPhone 6' | 'iPhone 6 Plus' | 'iPhone 7' | 'iPhone 7 Plus' | 'iPhone 8' | 'iPhone 8 Plus' | 'iPhone SE' | 'iPhone X' | 'JioPhone 2' | 'Kindle Fire HDX' | 'LG Optimus L70' | 'Microsoft Lumia 550' | 'Microsoft Lumia 950' | 'Nexus 10' | 'Nexus 4' | 'Nexus 5' | 'Nexus 5X' | 'Nexus 6' | 'Nexus 6P' | 'Nexus 7' | 'Nokia Lumia 520' | 'Nokia N9' | 'Pixel 2' | 'Pixel 2 XL' | CustomDevice;
149
+ export interface PerformanceAuditOptions {
150
+ /**
151
+ * Network throttling artificially limits the maximum download throughput (rate of data transfer). (e.g. Fast 3G).
152
+ */
153
+ networkThrottling?: NetworkStates;
154
+ /**
155
+ * Define CPU throttling to understand how your page performs under that constraint (e.g. 1.5).
156
+ */
157
+ cpuThrottling?: number;
158
+ /**
159
+ * Enable or disable cache of resources. Defaults to true.
160
+ */
161
+ cacheEnabled?: boolean;
162
+ }
163
+ export interface GathererDriver {
164
+ beginTrace(): Promise<void>;
165
+ endTrace(): Promise<TraceStreamJson>;
166
+ evaluate(script: Function, args: Object): Promise<any>;
167
+ }
168
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAC/D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AACrD,OAAO,KAAK,EAAE,MAAM,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;AACxE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qDAAqD,CAAA;AACnF,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAEhE,MAAM,WAAW,cAAc;IAC3B,gBAAgB,CAAC,EAAE,uBAAuB,CAAA;CAC7C;AAED,MAAM,WAAW,uBAAuB;IACpC;;;OAGG;IACH,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;IACf;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,aAAa,CAAA;IAC1B;;OAEG;IACH,OAAO,CAAC,EAAE,GAAG,CAAA;IACb;;;OAGG;IACH,OAAO,CAAC,EAAE,CAAC,MAAM,GAA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CAAA;AAEvkB,MAAM,WAAW,uBAAuB;IACpC;;OAEG;IACH,iBAAiB,CAAC,EAAE,aAAa,CAAC;IAClC;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;OAEG;IACH,YAAY,CAAC,EAAE,OAAO,CAAA;CACzB;AAED,MAAM,WAAW,cAAc;IAC3B,UAAU,IAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IAC5B,QAAQ,IAAK,OAAO,CAAC,eAAe,CAAC,CAAA;IACrC,QAAQ,CAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,CAAA;CAC1D"}
package/build/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,23 @@
1
+ import type { CDPSession } from 'puppeteer-core/lib/esm/puppeteer/api/CDPSession.js';
2
+ import type { Target } from 'puppeteer-core/lib/esm/puppeteer/api/Target.js';
3
+ import type { RequestPayload } from './handler/network.js';
4
+ import type { GathererDriver } from './types.js';
5
+ export declare function setUnsupportedCommand(browser: WebdriverIO.Browser | WebdriverIO.MultiRemoteBrowser): void;
6
+ /**
7
+ * Create a sum of a specific key from a list of objects
8
+ * @param list list of key/value objects
9
+ * @param key key of value to be summed up
10
+ */
11
+ export declare function sumByKey(list: RequestPayload[], key: keyof RequestPayload): number;
12
+ /**
13
+ * check if url is supported for tracing
14
+ * @param {string} url to check for
15
+ * @return {Boolean} true if url was opened by user
16
+ */
17
+ export declare function isSupportedUrl(url: string): boolean;
18
+ /**
19
+ * Either request the page list directly from the browser or if Selenium
20
+ * or Selenoid is used connect to a target manually
21
+ */
22
+ export declare function getLighthouseDriver(session: CDPSession, target: Target): Promise<GathererDriver>;
23
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oDAAoD,CAAA;AACpF,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gDAAgD,CAAA;AAK5E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAC1D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAahD,wBAAgB,qBAAqB,CAAE,OAAO,EAAE,WAAW,CAAC,OAAO,GAAG,WAAW,CAAC,kBAAkB,QAMnG;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,CAAE,IAAI,EAAE,cAAc,EAAE,EAAE,GAAG,EAAE,MAAM,cAAc,UAE1E;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAE,GAAG,EAAE,MAAM,WAE1C;AAED;;;GAGG;AACH,wBAAsB,mBAAmB,CAAE,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,CA+BvG"}
package/build/utils.js ADDED
@@ -0,0 +1,64 @@
1
+ import Driver from 'lighthouse/lighthouse-core/gather/driver.js';
2
+ import ChromeProtocol from './lighthouse/cri.js';
3
+ import { IGNORED_URLS, UNSUPPORTED_ERROR_MESSAGE } from './constants.js';
4
+ const CUSTOM_COMMANDS = [
5
+ 'getMetrics',
6
+ 'startTracing',
7
+ 'getDiagnostics',
8
+ 'getCoverageReport',
9
+ 'enablePerformanceAudits',
10
+ 'disablePerformanceAudits',
11
+ 'getMainThreadWorkBreakdown',
12
+ 'checkPWA'
13
+ ];
14
+ export function setUnsupportedCommand(browser) {
15
+ for (const command of CUSTOM_COMMANDS) {
16
+ browser.addCommand(command, /* istanbul ignore next */ () => {
17
+ throw new Error(UNSUPPORTED_ERROR_MESSAGE);
18
+ });
19
+ }
20
+ }
21
+ /**
22
+ * Create a sum of a specific key from a list of objects
23
+ * @param list list of key/value objects
24
+ * @param key key of value to be summed up
25
+ */
26
+ export function sumByKey(list, key) {
27
+ return list.map((data) => data[key]).reduce((acc, val) => acc + val, 0);
28
+ }
29
+ /**
30
+ * check if url is supported for tracing
31
+ * @param {string} url to check for
32
+ * @return {Boolean} true if url was opened by user
33
+ */
34
+ export function isSupportedUrl(url) {
35
+ return IGNORED_URLS.filter((ignoredUrl) => url.startsWith(ignoredUrl)).length === 0;
36
+ }
37
+ /**
38
+ * Either request the page list directly from the browser or if Selenium
39
+ * or Selenoid is used connect to a target manually
40
+ */
41
+ export async function getLighthouseDriver(session, target) {
42
+ const connection = session.connection();
43
+ if (!connection) {
44
+ throw new Error('Couldn\'t find a CDP connection');
45
+ }
46
+ const cUrl = new URL(connection.url());
47
+ const cdpConnection = new ChromeProtocol(cUrl.port, cUrl.hostname);
48
+ /**
49
+ * only create a new DevTools session if our WebSocket url doesn't already indicate
50
+ * that we are using one
51
+ */
52
+ if (!cUrl.pathname.startsWith('/devtools/browser')) {
53
+ await cdpConnection._connectToSocket({
54
+ webSocketDebuggerUrl: connection.url(),
55
+ id: (await target.asPage()).mainFrame()._id
56
+ });
57
+ const { sessionId } = await cdpConnection.sendCommand('Target.attachToTarget', undefined, { targetId: (await target.asPage()).mainFrame()._id, flatten: true });
58
+ cdpConnection.setSessionId(sessionId);
59
+ return new Driver(cdpConnection);
60
+ }
61
+ const list = await cdpConnection._runJsonCommand('list');
62
+ await cdpConnection._connectToSocket(list[0]);
63
+ return new Driver(cdpConnection);
64
+ }
package/package.json ADDED
@@ -0,0 +1,66 @@
1
+ {
2
+ "name": "@wdio/lighthouse-service",
3
+ "version": "9.0.0-alpha.321+63953a607",
4
+ "description": "A WebdriverIO service that allows you to run Chrome DevTools commands in your tests",
5
+ "author": "Christian Bromann <mail@bromann.dev>",
6
+ "homepage": "https://github.com/webdriverio/webdriverio/tree/main/packages/wdio-lighthouse-service",
7
+ "license": "MIT",
8
+ "engines": {
9
+ "node": ">=18"
10
+ },
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git://github.com/webdriverio/webdriverio.git",
14
+ "directory": "packages/wdio-lighthouse-service"
15
+ },
16
+ "keywords": [
17
+ "webdriver",
18
+ "wdio",
19
+ "wdio-service",
20
+ "lighthouse",
21
+ "chrome",
22
+ "selenium",
23
+ "performance",
24
+ "audit",
25
+ "testing",
26
+ "pwa",
27
+ "progressive web app",
28
+ "test"
29
+ ],
30
+ "bugs": {
31
+ "url": "https://github.com/webdriverio/webdriverio/issues"
32
+ },
33
+ "type": "module",
34
+ "types": "./build/index.d.ts",
35
+ "exports": {
36
+ ".": "./build/index.js",
37
+ "./package.json": "./package.json"
38
+ },
39
+ "typeScriptVersion": "3.8.3",
40
+ "dependencies": {
41
+ "@babel/core": "^7.18.0",
42
+ "@tracerbench/trace-event": "^8.0.0",
43
+ "@types/node": "^20.1.0",
44
+ "@wdio/logger": "9.0.0-alpha.321+63953a607",
45
+ "@wdio/types": "9.0.0-alpha.321+63953a607",
46
+ "babel-plugin-istanbul": "^6.1.1",
47
+ "devtools-protocol": "^0.0.1312386",
48
+ "istanbul-lib-coverage": "^3.2.0",
49
+ "istanbul-lib-report": "^3.0.0",
50
+ "istanbul-reports": "^3.1.4",
51
+ "lighthouse": "8.6.0",
52
+ "puppeteer-core": "22.11.1",
53
+ "webdriverio": "9.0.0-alpha.321+63953a607"
54
+ },
55
+ "publishConfig": {
56
+ "access": "public"
57
+ },
58
+ "devDependencies": {
59
+ "@types/babel__core": "^7.1.19",
60
+ "@types/istanbul-lib-coverage": "^2.0.6",
61
+ "@types/istanbul-lib-report": "^3.0.0",
62
+ "@types/istanbul-reports": "^3.0.4",
63
+ "@wdio/globals": "9.0.0-alpha.321+63953a607"
64
+ },
65
+ "gitHead": "63953a6079023cb390a113fe5ce1c1b01b8e4bb6"
66
+ }