@wordpress/e2e-test-utils-playwright 1.47.0 → 1.48.0

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 (172) hide show
  1. package/package.json +3 -3
  2. package/src/admin/create-new-post.ts +47 -0
  3. package/src/admin/edit-post.ts +24 -0
  4. package/{build/admin/get-page-error.js → src/admin/get-page-error.ts} +12 -9
  5. package/src/admin/index.ts +52 -0
  6. package/src/admin/visit-admin-page.ts +43 -0
  7. package/src/admin/visit-site-editor.ts +62 -0
  8. package/src/admin/wait-for-site-editor.ts +52 -0
  9. package/src/config.ts +12 -0
  10. package/src/editor/click-block-options-menu-item.ts +18 -0
  11. package/src/editor/click-block-toolbar-button.ts +21 -0
  12. package/src/editor/get-blocks.ts +75 -0
  13. package/src/editor/get-edited-post-content.ts +19 -0
  14. package/src/editor/index.ts +95 -0
  15. package/src/editor/insert-block.ts +54 -0
  16. package/src/editor/open-document-settings-sidebar.ts +31 -0
  17. package/src/editor/preview.ts +32 -0
  18. package/src/editor/publish-post.ts +51 -0
  19. package/src/editor/save-draft.ts +20 -0
  20. package/src/editor/select-blocks.ts +48 -0
  21. package/src/editor/set-content.ts +24 -0
  22. package/src/editor/set-is-fixed-toolbar.ts +20 -0
  23. package/src/editor/set-preferences.ts +37 -0
  24. package/src/editor/show-block-toolbar.ts +20 -0
  25. package/src/editor/site-editor.ts +55 -0
  26. package/src/editor/switch-editor-tool.ts +34 -0
  27. package/src/editor/switch-to-legacy-canvas.ts +20 -0
  28. package/src/editor/transform-block-to.ts +34 -0
  29. package/src/index.ts +8 -0
  30. package/src/lighthouse/index.ts +75 -0
  31. package/src/metrics/index.ts +441 -0
  32. package/src/page-utils/drag-files.ts +173 -0
  33. package/src/page-utils/emulate-network-conditions.ts +101 -0
  34. package/src/page-utils/index.ts +54 -0
  35. package/src/page-utils/is-current-url.ts +20 -0
  36. package/src/page-utils/keycodes.ts +48 -0
  37. package/src/page-utils/press-keys.ts +195 -0
  38. package/{build → src}/page-utils/set-browser-viewport.js +14 -12
  39. package/src/request-utils/blocks.ts +58 -0
  40. package/src/request-utils/comments.ts +80 -0
  41. package/src/request-utils/gutenberg-experiments.ts +62 -0
  42. package/src/request-utils/index.ts +222 -0
  43. package/src/request-utils/login.ts +34 -0
  44. package/src/request-utils/media.ts +102 -0
  45. package/src/request-utils/menus.ts +145 -0
  46. package/src/request-utils/pages.ts +75 -0
  47. package/src/request-utils/patterns.ts +31 -0
  48. package/src/request-utils/plugins.ts +103 -0
  49. package/src/request-utils/posts.ts +69 -0
  50. package/src/request-utils/preferences.ts +63 -0
  51. package/{build/request-utils/records.js → src/request-utils/records.ts} +15 -10
  52. package/src/request-utils/rest.ts +222 -0
  53. package/src/request-utils/site-settings.ts +58 -0
  54. package/src/request-utils/templates.ts +83 -0
  55. package/src/request-utils/themes.ts +110 -0
  56. package/src/request-utils/users.ts +125 -0
  57. package/src/request-utils/widgets.js +68 -0
  58. package/src/test.ts +204 -0
  59. package/src/types.ts +13 -0
  60. package/build/admin/create-new-post.js +0 -31
  61. package/build/admin/create-new-post.js.map +0 -1
  62. package/build/admin/edit-post.js +0 -20
  63. package/build/admin/edit-post.js.map +0 -1
  64. package/build/admin/get-page-error.js.map +0 -1
  65. package/build/admin/index.js +0 -40
  66. package/build/admin/index.js.map +0 -1
  67. package/build/admin/visit-admin-page.js +0 -32
  68. package/build/admin/visit-admin-page.js.map +0 -1
  69. package/build/admin/visit-site-editor.js +0 -45
  70. package/build/admin/visit-site-editor.js.map +0 -1
  71. package/build/admin/wait-for-site-editor.js +0 -41
  72. package/build/admin/wait-for-site-editor.js.map +0 -1
  73. package/build/config.js +0 -13
  74. package/build/config.js.map +0 -1
  75. package/build/editor/click-block-options-menu-item.js +0 -17
  76. package/build/editor/click-block-options-menu-item.js.map +0 -1
  77. package/build/editor/click-block-toolbar-button.js +0 -16
  78. package/build/editor/click-block-toolbar-button.js.map +0 -1
  79. package/build/editor/get-blocks.js +0 -45
  80. package/build/editor/get-blocks.js.map +0 -1
  81. package/build/editor/get-edited-post-content.js +0 -15
  82. package/build/editor/get-edited-post-content.js.map +0 -1
  83. package/build/editor/index.js +0 -75
  84. package/build/editor/index.js.map +0 -1
  85. package/build/editor/insert-block.js +0 -23
  86. package/build/editor/insert-block.js.map +0 -1
  87. package/build/editor/open-document-settings-sidebar.js +0 -27
  88. package/build/editor/open-document-settings-sidebar.js.map +0 -1
  89. package/build/editor/preview.js +0 -21
  90. package/build/editor/preview.js.map +0 -1
  91. package/build/editor/publish-post.js +0 -45
  92. package/build/editor/publish-post.js.map +0 -1
  93. package/build/editor/save-draft.js +0 -18
  94. package/build/editor/save-draft.js.map +0 -1
  95. package/build/editor/select-blocks.js +0 -28
  96. package/build/editor/select-blocks.js.map +0 -1
  97. package/build/editor/set-content.js +0 -17
  98. package/build/editor/set-content.js.map +0 -1
  99. package/build/editor/set-is-fixed-toolbar.js +0 -18
  100. package/build/editor/set-is-fixed-toolbar.js.map +0 -1
  101. package/build/editor/set-preferences.js +0 -21
  102. package/build/editor/set-preferences.js.map +0 -1
  103. package/build/editor/show-block-toolbar.js +0 -19
  104. package/build/editor/show-block-toolbar.js.map +0 -1
  105. package/build/editor/site-editor.js +0 -44
  106. package/build/editor/site-editor.js.map +0 -1
  107. package/build/editor/switch-editor-tool.js +0 -33
  108. package/build/editor/switch-editor-tool.js.map +0 -1
  109. package/build/editor/switch-to-legacy-canvas.js +0 -18
  110. package/build/editor/switch-to-legacy-canvas.js.map +0 -1
  111. package/build/editor/transform-block-to.js +0 -24
  112. package/build/editor/transform-block-to.js.map +0 -1
  113. package/build/index.js +0 -19
  114. package/build/index.js.map +0 -1
  115. package/build/lighthouse/index.js +0 -61
  116. package/build/lighthouse/index.js.map +0 -1
  117. package/build/metrics/index.js +0 -314
  118. package/build/metrics/index.js.map +0 -1
  119. package/build/page-utils/drag-files.js +0 -119
  120. package/build/page-utils/drag-files.js.map +0 -1
  121. package/build/page-utils/emulate-network-conditions.js +0 -71
  122. package/build/page-utils/emulate-network-conditions.js.map +0 -1
  123. package/build/page-utils/index.js +0 -37
  124. package/build/page-utils/index.js.map +0 -1
  125. package/build/page-utils/is-current-url.js +0 -21
  126. package/build/page-utils/is-current-url.js.map +0 -1
  127. package/build/page-utils/keycodes.js +0 -41
  128. package/build/page-utils/keycodes.js.map +0 -1
  129. package/build/page-utils/press-keys.js +0 -141
  130. package/build/page-utils/press-keys.js.map +0 -1
  131. package/build/page-utils/set-browser-viewport.js.map +0 -1
  132. package/build/request-utils/blocks.js +0 -40
  133. package/build/request-utils/blocks.js.map +0 -1
  134. package/build/request-utils/comments.js +0 -52
  135. package/build/request-utils/comments.js.map +0 -1
  136. package/build/request-utils/gutenberg-experiments.js +0 -47
  137. package/build/request-utils/gutenberg-experiments.js.map +0 -1
  138. package/build/request-utils/index.js +0 -196
  139. package/build/request-utils/index.js.map +0 -1
  140. package/build/request-utils/login.js +0 -21
  141. package/build/request-utils/login.js.map +0 -1
  142. package/build/request-utils/media.js +0 -106
  143. package/build/request-utils/media.js.map +0 -1
  144. package/build/request-utils/menus.js +0 -116
  145. package/build/request-utils/menus.js.map +0 -1
  146. package/build/request-utils/pages.js +0 -53
  147. package/build/request-utils/pages.js.map +0 -1
  148. package/build/request-utils/patterns.js +0 -27
  149. package/build/request-utils/patterns.js.map +0 -1
  150. package/build/request-utils/plugins.js +0 -85
  151. package/build/request-utils/plugins.js.map +0 -1
  152. package/build/request-utils/posts.js +0 -42
  153. package/build/request-utils/posts.js.map +0 -1
  154. package/build/request-utils/preferences.js +0 -54
  155. package/build/request-utils/preferences.js.map +0 -1
  156. package/build/request-utils/records.js.map +0 -1
  157. package/build/request-utils/rest.js +0 -181
  158. package/build/request-utils/rest.js.map +0 -1
  159. package/build/request-utils/site-settings.js +0 -33
  160. package/build/request-utils/site-settings.js.map +0 -1
  161. package/build/request-utils/templates.js +0 -54
  162. package/build/request-utils/templates.js.map +0 -1
  163. package/build/request-utils/themes.js +0 -69
  164. package/build/request-utils/themes.js.map +0 -1
  165. package/build/request-utils/users.js +0 -81
  166. package/build/request-utils/users.js.map +0 -1
  167. package/build/request-utils/widgets.js +0 -61
  168. package/build/request-utils/widgets.js.map +0 -1
  169. package/build/test.js +0 -189
  170. package/build/test.js.map +0 -1
  171. package/build/types.js +0 -3
  172. package/build/types.js.map +0 -1
package/build/index.js DELETED
@@ -1,19 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.expect = exports.test = exports.Lighthouse = exports.Metrics = exports.RequestUtils = exports.PageUtils = exports.Editor = exports.Admin = void 0;
4
- var admin_1 = require("./admin");
5
- Object.defineProperty(exports, "Admin", { enumerable: true, get: function () { return admin_1.Admin; } });
6
- var editor_1 = require("./editor");
7
- Object.defineProperty(exports, "Editor", { enumerable: true, get: function () { return editor_1.Editor; } });
8
- var page_utils_1 = require("./page-utils");
9
- Object.defineProperty(exports, "PageUtils", { enumerable: true, get: function () { return page_utils_1.PageUtils; } });
10
- var request_utils_1 = require("./request-utils");
11
- Object.defineProperty(exports, "RequestUtils", { enumerable: true, get: function () { return request_utils_1.RequestUtils; } });
12
- var metrics_1 = require("./metrics");
13
- Object.defineProperty(exports, "Metrics", { enumerable: true, get: function () { return metrics_1.Metrics; } });
14
- var lighthouse_1 = require("./lighthouse");
15
- Object.defineProperty(exports, "Lighthouse", { enumerable: true, get: function () { return lighthouse_1.Lighthouse; } });
16
- var test_1 = require("./test");
17
- Object.defineProperty(exports, "test", { enumerable: true, get: function () { return test_1.test; } });
18
- Object.defineProperty(exports, "expect", { enumerable: true, get: function () { return test_1.expect; } });
19
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AACA,iCAAgC;AAAvB,8FAAA,KAAK,OAAA;AACd,mCAAkC;AAAzB,gGAAA,MAAM,OAAA;AACf,2CAAyC;AAAhC,uGAAA,SAAS,OAAA;AAClB,iDAA+C;AAAtC,6GAAA,YAAY,OAAA;AACrB,qCAAoC;AAA3B,kGAAA,OAAO,OAAA;AAChB,2CAA0C;AAAjC,wGAAA,UAAU,OAAA;AACnB,+BAAsC;AAA7B,4FAAA,IAAI,OAAA;AAAE,8FAAA,MAAM,OAAA"}
@@ -1,61 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.Lighthouse = void 0;
7
- const index_cjs_1 = __importDefault(require("lighthouse/core/index.cjs"));
8
- class Lighthouse {
9
- page;
10
- port;
11
- constructor({ page, port }) {
12
- this.page = page;
13
- this.port = port;
14
- }
15
- /**
16
- * Returns the Lighthouse report for the current URL.
17
- *
18
- * Runs several Lighthouse audits in a separate browser window and returns
19
- * the summary.
20
- */
21
- async getReport() {
22
- // From https://github.com/GoogleChrome/lighthouse/blob/36cac182a6c637b1671c57326d7c0241633d0076/core/config/default-config.js#L381-L446
23
- const audits = {
24
- 'largest-contentful-paint': 'LCP',
25
- 'total-blocking-time': 'TBT',
26
- interactive: 'TTI',
27
- 'cumulative-layout-shift': 'CLS',
28
- 'interaction-to-next-paint': 'INP',
29
- };
30
- const report = await (0, index_cjs_1.default)(this.page.url(), { port: this.port }, {
31
- extends: 'lighthouse:default',
32
- settings: {
33
- // "provided" means no throttling.
34
- // TODO: Make configurable.
35
- throttlingMethod: 'provided',
36
- // Default is "mobile".
37
- // See https://github.com/GoogleChrome/lighthouse/blob/main/docs/emulation.md
38
- // TODO: Make configurable.
39
- formFactor: 'desktop',
40
- screenEmulation: {
41
- disabled: true,
42
- },
43
- // Speeds up the report.
44
- disableFullPageScreenshot: true,
45
- // Only run certain audits to speed things up.
46
- onlyAudits: Object.keys(audits),
47
- },
48
- });
49
- const result = {};
50
- if (!report) {
51
- return result;
52
- }
53
- const { lhr } = report;
54
- for (const [audit, acronym] of Object.entries(audits)) {
55
- result[acronym] = lhr.audits[audit]?.numericValue || 0;
56
- }
57
- return result;
58
- }
59
- }
60
- exports.Lighthouse = Lighthouse;
61
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/lighthouse/index.ts"],"names":[],"mappings":";;;;;;AAIA,0EAAmD;AAOnD;IACC,IAAI,CAAO;IACX,IAAI,CAAS;IAEb,YAAa,EAAE,IAAI,EAAE,IAAI,EAA8B;QACtD,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IAClB,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,SAAS;QACd,wIAAwI;QACxI,MAAM,MAAM,GAAG;YACd,0BAA0B,EAAE,KAAK;YACjC,qBAAqB,EAAE,KAAK;YAC5B,WAAW,EAAE,KAAK;YAClB,yBAAyB,EAAE,KAAK;YAChC,2BAA2B,EAAE,KAAK;SAClC,CAAC;QAEF,MAAM,MAAM,GAAG,MAAM,IAAA,mBAAU,EAC9B,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,EACf,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,EACnB;YACC,OAAO,EAAE,oBAAoB;YAC7B,QAAQ,EAAE;gBACT,kCAAkC;gBAClC,2BAA2B;gBAC3B,gBAAgB,EAAE,UAAU;gBAC5B,uBAAuB;gBACvB,6EAA6E;gBAC7E,2BAA2B;gBAC3B,UAAU,EAAE,SAAS;gBACrB,eAAe,EAAE;oBAChB,QAAQ,EAAE,IAAI;iBACd;gBACD,wBAAwB;gBACxB,yBAAyB,EAAE,IAAI;gBAC/B,8CAA8C;gBAC9C,UAAU,EAAE,MAAM,CAAC,IAAI,CAAE,MAAM,CAAE;aACjC;SACD,CACD,CAAC;QAEF,MAAM,MAAM,GAA6B,EAAE,CAAC;QAE5C,IAAK,CAAE,MAAM,EAAG,CAAC;YAChB,OAAO,MAAM,CAAC;QACf,CAAC;QAED,MAAM,EAAE,GAAG,EAAE,GAAG,MAAM,CAAC;QAEvB,KAAM,MAAM,CAAE,KAAK,EAAE,OAAO,CAAE,IAAI,MAAM,CAAC,OAAO,CAAE,MAAM,CAAE,EAAG,CAAC;YAC7D,MAAM,CAAE,OAAO,CAAE,GAAG,GAAG,CAAC,MAAM,CAAE,KAAK,CAAE,EAAE,YAAY,IAAI,CAAC,CAAC;QAC5D,CAAC;QAED,OAAO,MAAM,CAAC;IACf,CAAC;CACD"}
@@ -1,314 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Metrics = void 0;
4
- /**
5
- * External dependencies
6
- */
7
- const promises_1 = require("fs/promises");
8
- const path_1 = require("path");
9
- class Metrics {
10
- browser;
11
- page;
12
- trace;
13
- webVitals = {};
14
- constructor({ page }) {
15
- this.page = page;
16
- this.browser = page.context().browser();
17
- this.trace = { traceEvents: [] };
18
- }
19
- /**
20
- * Returns durations from the Server-Timing header.
21
- *
22
- * @param fields Optional fields to filter.
23
- */
24
- async getServerTiming(fields = []) {
25
- return this.page.evaluate((f) => performance.getEntriesByType('navigation')[0].serverTiming.reduce((acc, entry) => {
26
- if (f.length === 0 || f.includes(entry.name)) {
27
- acc[entry.name] = entry.duration;
28
- }
29
- return acc;
30
- }, {}), fields);
31
- }
32
- /**
33
- * Returns time to first byte (TTFB) using the Navigation Timing API.
34
- *
35
- * @see https://web.dev/ttfb/#measure-ttfb-in-javascript
36
- *
37
- * @return TTFB value.
38
- */
39
- async getTimeToFirstByte() {
40
- return await this.page.evaluate(() => {
41
- const { responseStart, startTime } = performance.getEntriesByType('navigation')[0];
42
- return responseStart - startTime;
43
- });
44
- }
45
- /**
46
- * Returns the Largest Contentful Paint (LCP) value using the dedicated API.
47
- *
48
- * @see https://w3c.github.io/largest-contentful-paint/
49
- * @see https://web.dev/lcp/#measure-lcp-in-javascript
50
- *
51
- * @return LCP value.
52
- */
53
- async getLargestContentfulPaint() {
54
- return await this.page.evaluate(() => new Promise((resolve) => {
55
- new PerformanceObserver((entryList) => {
56
- const entries = entryList.getEntries();
57
- // The last entry is the largest contentful paint.
58
- const largestPaintEntry = entries.at(-1);
59
- resolve(largestPaintEntry?.startTime || 0);
60
- }).observe({
61
- type: 'largest-contentful-paint',
62
- buffered: true,
63
- });
64
- }));
65
- }
66
- /**
67
- * Returns the Cumulative Layout Shift (CLS) value using the dedicated API.
68
- *
69
- * @see https://github.com/WICG/layout-instability
70
- * @see https://web.dev/cls/#measure-layout-shifts-in-javascript
71
- *
72
- * @return CLS value.
73
- */
74
- async getCumulativeLayoutShift() {
75
- return await this.page.evaluate(() => new Promise((resolve) => {
76
- let CLS = 0;
77
- new PerformanceObserver((l) => {
78
- const entries = l.getEntries();
79
- entries.forEach((entry) => {
80
- if (!entry.hadRecentInput) {
81
- CLS += entry.value;
82
- }
83
- });
84
- resolve(CLS);
85
- }).observe({
86
- type: 'layout-shift',
87
- buffered: true,
88
- });
89
- }));
90
- }
91
- /**
92
- * Returns the loading durations using the Navigation Timing API. All the
93
- * durations exclude the server response time.
94
- *
95
- * @return Object with loading metrics durations.
96
- */
97
- async getLoadingDurations() {
98
- return await this.page.evaluate(() => {
99
- const [{ requestStart, responseStart, responseEnd, domContentLoadedEventEnd, loadEventEnd, },] = performance.getEntriesByType('navigation');
100
- const paintTimings = performance.getEntriesByType('paint');
101
- const firstPaintStartTime = paintTimings.find(({ name }) => name === 'first-paint').startTime;
102
- const firstContentfulPaintStartTime = paintTimings.find(({ name }) => name === 'first-contentful-paint').startTime;
103
- return {
104
- // Server side metric.
105
- serverResponse: responseStart - requestStart,
106
- // For client side metrics, consider the end of the response (the
107
- // browser receives the HTML) as the start time (0).
108
- firstPaint: firstPaintStartTime - responseEnd,
109
- domContentLoaded: domContentLoadedEventEnd - responseEnd,
110
- loaded: loadEventEnd - responseEnd,
111
- firstContentfulPaint: firstContentfulPaintStartTime - responseEnd,
112
- timeSinceResponseEnd: performance.now() - responseEnd,
113
- };
114
- });
115
- }
116
- /**
117
- * Starts Chromium tracing with predefined options for performance testing.
118
- *
119
- * The category set mirrors what Chrome DevTools enables when recording in
120
- * the Performance panel: `devtools.timeline` provides the top-level event
121
- * tree, and the `disabled-by-default-v8.cpu_profiler` + companion
122
- * `devtools.timeline.stack` categories enable the V8 sampler that
123
- * populates JavaScript call stacks. Without the latter, the saved trace
124
- * shows only opaque "Function call" blocks with no JS frames inside.
125
- *
126
- * @param options Options to pass to `browser.startTracing()`.
127
- */
128
- async startTracing(options = {}) {
129
- return await this.browser.startTracing(this.page, {
130
- screenshots: false,
131
- categories: [
132
- 'devtools.timeline',
133
- 'disabled-by-default-devtools.timeline',
134
- 'disabled-by-default-devtools.timeline.stack',
135
- 'disabled-by-default-v8.cpu_profiler',
136
- 'v8.execute',
137
- ],
138
- ...options,
139
- });
140
- }
141
- /**
142
- * Stops Chromium tracing.
143
- *
144
- * When `name` is a non-empty string and the `WP_ARTIFACTS_PATH` environment
145
- * variable is set, the raw trace is written to
146
- * `${WP_ARTIFACTS_PATH}/traces/<name>.trace.json`. The resulting file can
147
- * be opened in Chrome DevTools (Performance panel → "Load profile…") to
148
- * inspect the flame graph. Pass a falsy value (or omit the argument) to
149
- * just parse the trace into `this.trace` without writing — this is the
150
- * default for iteration loops, where you typically want to save only one
151
- * representative sample. Callers pick which iteration that is, e.g.
152
- * `i === Math.floor( iterations / 2 ) && 'post-editor-first-block'`.
153
- *
154
- * @param name File name (without extension) identifying the scenario, or
155
- * `false`/`undefined` to skip writing.
156
- */
157
- async stopTracing(name) {
158
- const traceBuffer = await this.browser.stopTracing();
159
- const traceJSON = JSON.parse(traceBuffer.toString());
160
- this.trace = traceJSON;
161
- if (!name) {
162
- return;
163
- }
164
- const artifactsPath = process.env.WP_ARTIFACTS_PATH;
165
- if (!artifactsPath) {
166
- return;
167
- }
168
- // The perf comparison flow runs the same suite against multiple
169
- // branches into a single artifacts directory; the comparison branches
170
- // set WP_PERF_NO_TRACE so the head branch's traces aren't overwritten.
171
- if (process.env.WP_PERF_NO_TRACE) {
172
- return;
173
- }
174
- // Traces are saved minified. Run the following against a downloaded trace
175
- // + matching `build/` directory to rewrite minified `functionName`s back
176
- // to their source identifiers:
177
- //
178
- // node tools/build-scripts/packages/resolve-trace-source-maps.cjs
179
- //
180
- // Or via the workspace script:
181
- //
182
- // npm run --workspace @wordpress/build-scripts resolve-trace-source-maps -- <trace.json> [--build-dir <dir>]
183
- const tracesDir = (0, path_1.join)(artifactsPath, 'traces');
184
- const filePath = (0, path_1.join)(tracesDir, `${name}.trace.json`);
185
- await (0, promises_1.mkdir)(tracesDir, { recursive: true });
186
- await (0, promises_1.writeFile)(filePath, JSON.stringify(traceJSON));
187
- }
188
- /**
189
- * @return Durations of all traced `keydown`, `keypress`, and `keyup`
190
- * events.
191
- */
192
- getTypingEventDurations() {
193
- return [
194
- this.getEventDurations('keydown'),
195
- this.getEventDurations('keypress'),
196
- this.getEventDurations('keyup'),
197
- ];
198
- }
199
- /**
200
- * @return Durations of all traced `focus` and `focusin` events.
201
- */
202
- getSelectionEventDurations() {
203
- return [
204
- this.getEventDurations('focus'),
205
- this.getEventDurations('focusin'),
206
- ];
207
- }
208
- /**
209
- * @return Durations of all traced `click` events.
210
- */
211
- getClickEventDurations() {
212
- return [this.getEventDurations('click')];
213
- }
214
- /**
215
- * @return Durations of all traced `mouseover` and `mouseout` events.
216
- */
217
- getHoverEventDurations() {
218
- return [
219
- this.getEventDurations('mouseover'),
220
- this.getEventDurations('mouseout'),
221
- ];
222
- }
223
- /**
224
- * @param eventType Type of event to filter.
225
- * @return Durations of all events of a given type.
226
- */
227
- getEventDurations(eventType) {
228
- if (this.trace.traceEvents.length === 0) {
229
- throw new Error('No trace events found. Did you forget to call stopTracing()?');
230
- }
231
- return this.trace.traceEvents
232
- .filter((item) => item.cat === 'devtools.timeline' &&
233
- item.name === 'EventDispatch' &&
234
- item?.args?.data?.type === eventType &&
235
- !!item.dur)
236
- .map((item) => (item.dur ? item.dur / 1000 : 0));
237
- }
238
- /**
239
- * Initializes the web-vitals library upon next page navigation.
240
- *
241
- * Defaults to automatically triggering the navigation,
242
- * but it can also be done manually.
243
- *
244
- * @example
245
- * ```js
246
- * await metrics.initWebVitals();
247
- * console.log( await metrics.getWebVitals() );
248
- * ```
249
- *
250
- * @example
251
- * ```js
252
- * await metrics.initWebVitals( false );
253
- * await page.goto( '/some-other-page' );
254
- * console.log( await metrics.getWebVitals() );
255
- * ```
256
- *
257
- * @param reload Whether to force navigation by reloading the current page.
258
- */
259
- async initWebVitals(reload = true) {
260
- await this.page.addInitScript({
261
- path: (0, path_1.join)(__dirname, '../../../../node_modules/web-vitals/dist/web-vitals.umd.cjs'),
262
- });
263
- await this.page.exposeFunction('__reportVitals__', (data) => {
264
- const measurement = JSON.parse(data);
265
- this.webVitals[measurement.name] = measurement.value;
266
- });
267
- await this.page.addInitScript(() => {
268
- const reportVitals = (measurement) => window.__reportVitals__(JSON.stringify(measurement));
269
- window.addEventListener('DOMContentLoaded', () => {
270
- // @ts-expect-error This is valid but web-vitals does not register the global types.
271
- window.webVitals.onCLS(reportVitals);
272
- // @ts-expect-error This is valid but web-vitals does not register the global types.
273
- window.webVitals.onFCP(reportVitals);
274
- // @ts-expect-error This is valid but web-vitals does not register the global types.
275
- window.webVitals.onFID(reportVitals);
276
- // @ts-expect-error This is valid but web-vitals does not register the global types.
277
- window.webVitals.onINP(reportVitals);
278
- // @ts-expect-error This is valid but web-vitals does not register the global types.
279
- window.webVitals.onLCP(reportVitals);
280
- // @ts-expect-error This is valid but web-vitals does not register the global types.
281
- window.webVitals.onTTFB(reportVitals);
282
- });
283
- });
284
- if (reload) {
285
- // By reloading the page the script will be applied.
286
- await this.page.reload();
287
- }
288
- }
289
- /**
290
- * Returns web vitals as collected by the web-vitals library.
291
- *
292
- * If the web-vitals library hasn't been loaded on the current page yet,
293
- * it will be initialized with a page reload.
294
- *
295
- * Reloads the page to force web-vitals to report all collected metrics.
296
- *
297
- * @return {WebVitalsMeasurements} Web vitals measurements.
298
- */
299
- async getWebVitals() {
300
- // Reset values.
301
- this.webVitals = {};
302
- const hasScript = await this.page.evaluate(
303
- // @ts-expect-error This is valid but web-vitals does not register the global types.
304
- () => typeof window.webVitals !== 'undefined');
305
- if (!hasScript) {
306
- await this.initWebVitals();
307
- }
308
- // Trigger navigation so the web-vitals library reports values on unload.
309
- await this.page.reload();
310
- return this.webVitals;
311
- }
312
- }
313
- exports.Metrics = Metrics;
314
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/metrics/index.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,0CAA+C;AAC/C,+BAA4B;AA6C5B;IACC,OAAO,CAAU;IACjB,IAAI,CAAO;IACX,KAAK,CAAQ;IAEb,SAAS,GAA0B,EAAE,CAAC;IAEtC,YAAa,EAAE,IAAI,EAA2B;QAC7C,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC,OAAO,EAAG,CAAC;QACzC,IAAI,CAAC,KAAK,GAAG,EAAE,WAAW,EAAE,EAAE,EAAE,CAAC;IAClC,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,eAAe,CAAE,MAAM,GAAa,EAAE;QAC3C,OAAO,IAAI,CAAC,IAAI,CAAC,QAAQ,CACxB,CAAE,CAAW,EAAG,EAAE,CAEhB,WAAW,CAAC,gBAAgB,CAC3B,YAAY,CAEZ,CAAE,CAAC,CAAE,CAAC,YAAY,CAAC,MAAM,CAC1B,CAAE,GAAG,EAAE,KAAK,EAAG,EAAE;YAChB,IAAK,CAAC,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAE,KAAK,CAAC,IAAI,CAAE,EAAG,CAAC;gBAClD,GAAG,CAAE,KAAK,CAAC,IAAI,CAAE,GAAG,KAAK,CAAC,QAAQ,CAAC;YACpC,CAAC;YACD,OAAO,GAAG,CAA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E,CAAC;gBACvC,oFAAoF;gBACpF,MAAM,CAAC,SAAS,CAAC,KAAK,CAAE,YAAY,CAAE,CAAC;gBACvC,oFAAoF;gBACpF,MAAM,CAAC,SAAS,CAAC,MAAM,CAAE,YAAY,CAAE,CAAC;YACzC,CAAC,CAAE,CAAC;QACL,CAAC,CAAE,CAAC;QAEJ,IAAK,MAAM,EAAG,CAAC;YACd,oDAAoD;YACpD,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;QAC1B,CAAC;IACF,CAAC;IAED;;;;;;;;;OASG;IACH,KAAK,CAAC,YAAY;QACjB,gBAAgB;QAChB,IAAI,CAAC,SAAS,GAAG,EAAE,CAAC;QAEpB,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,QAAQ;QACzC,oFAAoF;QACpF,GAAG,EAAE,CAAC,OAAO,MAAM,CAAC,SAAS,KAAK,WAAW,CAC7C,CAAC;QAEF,IAAK,CAAE,SAAS,EAAG,CAAC;YACnB,MAAM,IAAI,CAAC,aAAa,EAAE,CAAC;QAC5B,CAAC;QAED,yEAAyE;QACzE,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;QAEzB,OAAO,IAAI,CAAC,SAAS,CAAC;IACvB,CAAC;CACD"}
@@ -1,119 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.dragFiles = dragFiles;
4
- /**
5
- * External dependencies
6
- */
7
- const promises_1 = require("fs/promises");
8
- const path_1 = require("path");
9
- const mime_1 = require("mime");
10
- /**
11
- * Simulate dragging files from outside the current page.
12
- *
13
- * @param this
14
- * @param files The files to be dragged.
15
- * @return The methods of the drag operation.
16
- */
17
- async function dragFiles(files) {
18
- const filesList = Array.isArray(files) ? files : [files];
19
- const fileObjects = await Promise.all(filesList.map(async (filePathOrObject) => {
20
- if (typeof filePathOrObject !== 'string') {
21
- return {
22
- name: filePathOrObject.name,
23
- mimeType: filePathOrObject.mimeType ||
24
- (0, mime_1.getType)(filePathOrObject.name),
25
- base64: filePathOrObject.buffer.toString('base64'),
26
- };
27
- }
28
- const base64 = await (0, promises_1.readFile)(filePathOrObject, 'base64');
29
- const name = (0, path_1.basename)(filePathOrObject);
30
- return {
31
- name,
32
- mimeType: (0, mime_1.getType)(filePathOrObject),
33
- base64,
34
- };
35
- }));
36
- // CDP doesn't actually support dragging files, this is only a _good enough_
37
- // dummy data so that it will correctly send the relevant events.
38
- const dragData = {
39
- items: fileObjects.map((fileObject) => ({
40
- mimeType: fileObject.mimeType ?? 'File',
41
- data: fileObject.base64,
42
- })),
43
- files: fileObjects.map((fileObject) => fileObject.name),
44
- // Copy = 1, Link = 2, Move = 16.
45
- dragOperationsMask: 1,
46
- };
47
- const cdpSession = await this.context.newCDPSession(this.page);
48
- const position = {
49
- x: 0,
50
- y: 0,
51
- };
52
- return {
53
- /**
54
- * Drag the files over an element (fires `dragenter` and `dragover` events).
55
- *
56
- * @param selectorOrLocator A selector or a locator to search for an element.
57
- * @param options The optional options.
58
- * @param options.position A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of the element.
59
- */
60
- dragOver: async (selectorOrLocator, options = {}) => {
61
- const locator = typeof selectorOrLocator === 'string'
62
- ? this.page.locator(selectorOrLocator)
63
- : selectorOrLocator;
64
- const boundingBox = await locator.boundingBox();
65
- if (!boundingBox) {
66
- throw new Error('Cannot find the element or the element is not visible on the viewport.');
67
- }
68
- position.x =
69
- boundingBox.x +
70
- (options.position?.x ?? boundingBox.width / 2);
71
- position.y =
72
- boundingBox.y +
73
- (options.position?.y ?? boundingBox.height / 2);
74
- await cdpSession.send('Input.dispatchDragEvent', {
75
- type: 'dragEnter',
76
- ...position,
77
- data: dragData,
78
- });
79
- await cdpSession.send('Input.dispatchDragEvent', {
80
- type: 'dragOver',
81
- ...position,
82
- data: dragData,
83
- });
84
- },
85
- /**
86
- * Drop the files at the current position.
87
- */
88
- drop: async () => {
89
- const topMostElement = await this.page.evaluateHandle(({ x, y }) => {
90
- const element = document.elementFromPoint(x, y);
91
- if (element instanceof HTMLIFrameElement) {
92
- const offsetBox = element.getBoundingClientRect();
93
- return element.contentDocument.elementFromPoint(x - offsetBox.x, y - offsetBox.y);
94
- }
95
- return element;
96
- }, position);
97
- const elementHandle = topMostElement.asElement();
98
- if (!elementHandle) {
99
- throw new Error('Element not found.');
100
- }
101
- const dataTransfer = await elementHandle.evaluateHandle(async (_node, _fileObjects) => {
102
- const dt = new DataTransfer();
103
- const fileInstances = await Promise.all(_fileObjects.map(async (fileObject) => {
104
- const blob = await fetch(`data:${fileObject.mimeType};base64,${fileObject.base64}`).then((res) => res.blob());
105
- return new File([blob], fileObject.name, {
106
- type: fileObject.mimeType ?? undefined,
107
- });
108
- }));
109
- fileInstances.forEach((file) => {
110
- dt.items.add(file);
111
- });
112
- return dt;
113
- }, fileObjects);
114
- await elementHandle.dispatchEvent('drop', { dataTransfer });
115
- await cdpSession.detach();
116
- },
117
- };
118
- }
119
- //# sourceMappingURL=drag-files.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"drag-files.js","sourceRoot":"","sources":["../../src/page-utils/drag-files.ts"],"names":[],"mappings":";;QA4KS,SAAS;AA5KlB;;GAEG;AACH,0CAAuC;AACvC,+BAAgC;AAChC,+BAA+B;AAkB/B;;;;;;GAMG;AACH,KAAK,UAAU,SAAS,CAEvB,KAAoD;IAEpD,MAAM,SAAS,GAAG,KAAK,CAAC,OAAO,CAAE,KAAK,CAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAE,KAAK,CAAE,CAAC;IAC7D,MAAM,WAAW,GAAG,MAAM,OAAO,CAAC,GAAG,CACpC,SAAS,CAAC,GAAG,CAAE,KAAK,EAAG,gBAAgB,EAAG,EAAE;QAC3C,IAAK,OAAO,gBAAgB,KAAK,QAAQ,EAAG,CAAC;YAC5C,OAAO;gBACN,IAAI,EAAE,gBAAgB,CAAC,IAAI;gBAC3B,QAAQ,EACP,gBAAgB,CAAC,QA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ict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.emulateNetworkConditions = emulateNetworkConditions;
4
- // Defaults from https://github.com/puppeteer/puppeteer/blob/401355610874beac23a51dcb75739a4bb4191a2b/packages/puppeteer-core/src/cdp/PredefinedNetworkConditions.ts.
5
- const PredefinedNetworkConditions = {
6
- // Generally aligned with DevTools
7
- // https://source.chromium.org/chromium/chromium/src/+/main:third_party/devtools-frontend/src/front_end/core/sdk/NetworkManager.ts;l=398;drc=225e1240f522ca684473f541ae6dae6cd766dd33.
8
- 'Slow 3G': {
9
- offline: false,
10
- // ~500Kbps down
11
- downloadThroughput: ((500 * 1000) / 8) * 0.8,
12
- // ~500Kbps up
13
- uploadThroughput: ((500 * 1000) / 8) * 0.8,
14
- // 400ms RTT
15
- latency: 400 * 5,
16
- },
17
- 'Fast 3G': {
18
- offline: false,
19
- // ~1.6 Mbps down
20
- downloadThroughput: ((1.6 * 1000 * 1000) / 8) * 0.9,
21
- // ~0.75 Mbps up
22
- uploadThroughput: ((750 * 1000) / 8) * 0.9,
23
- // 150ms RTT
24
- latency: 150 * 3.75,
25
- },
26
- // alias to Fast 3G to align with Lighthouse (crbug.com/342406608)
27
- // and DevTools (crbug.com/342406608),
28
- 'Slow 4G': {
29
- offline: false,
30
- // ~1.6 Mbps down
31
- downloadThroughput: ((1.6 * 1000 * 1000) / 8) * 0.9,
32
- // ~0.75 Mbps up
33
- uploadThroughput: ((750 * 1000) / 8) * 0.9,
34
- // 150ms RTT
35
- latency: 150 * 3.75,
36
- },
37
- 'Fast 4G': {
38
- offline: false,
39
- // 9 Mbps down
40
- downloadThroughput: ((9 * 1000 * 1000) / 8) * 0.9,
41
- // 1.5 Mbps up
42
- uploadThroughput: ((1.5 * 1000 * 1000) / 8) * 0.9,
43
- // 60ms RTT
44
- latency: 60 * 2.75,
45
- },
46
- /**
47
- * Network conditions used for desktop in Lighthouse/PSI.
48
- *
49
- * 10,240 kb/s throughput with 40 ms TCP RTT.
50
- *
51
- * @see https://github.com/paulirish/lighthouse/blob/f0855904aaffaecf3089169449646960782d7e92/core/config/constants.js#L40-L49
52
- * @see https://docs.google.com/document/d/1-p4HSp42REEA5-jCBVB6PqQcVhI1nQIblBCNKhPJUXg/edit?tab=t.0#heading=h.jsap7yf4phk6
53
- */
54
- Broadband: {
55
- offline: false,
56
- downloadThroughput: (10240 * 1000) / 8,
57
- uploadThroughput: (10240 * 1000) / 8,
58
- latency: 40,
59
- },
60
- };
61
- async function emulateNetworkConditions(condition) {
62
- if ('chromium' !== this.browserName) {
63
- throw new Error('CDP sessions are only supported on Chromium-based browsers');
64
- }
65
- const session = await this.page.context().newCDPSession(this.page);
66
- await session.send('Network.emulateNetworkConditions', 'string' === typeof condition
67
- ? PredefinedNetworkConditions[condition]
68
- : condition);
69
- await session.detach();
70
- }
71
- //# sourceMappingURL=emulate-network-conditions.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"emulate-network-conditions.js","sourceRoot":"","sources":["../../src/page-utils/emulate-network-conditions.ts"],"names":[],"mappings":";;;AAwBA,qKAAqK;AACrK,MAAM,2BAA2B,GAAwC;IACxE,kCAAkC;IAClC,sLAAsL;IACtL,SAAS,EAAE;QACV,OAAO,EAAE,KAAK;QACd,gBAAgB;QAChB,kBAAkB,EAAE,CAAE,CAAE,GAAG,GAAG,IAAI,CAAE,GAAG,CAAC,CAAE,GAAG,GAAG;QAChD,cAAc;QACd,gBAAgB,EAAE,CAAE,CAAE,GAAG,GAAG,IAAI,CAAE,GAAG,CAAC,CAAE,GAAG,GAAG;QAC9C,YAAY;QACZ,OAAO,EAAE,GAAG,GAAG,CAAC;KAChB;IACD,SAAS,EAAE;QACV,OAAO,EAAE,KAAK;QACd,iBAAiB;QACjB,kBAAkB,EAAE,CAAE,CAAE,GAAG,GAAG,IAAI,GAAG,IAAI,CAAE,GAAG,CAAC,CAAE,GAAG,GAAG;QACvD,gBAAgB;QAChB,gBAAgB,EAAE,CAAE,CAAE,GAAG,GAAG,IAAI,CAAE,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C,IAAI,CACjB,kCAAkC,EAClC,QAAQ,KAAK,OAAO,SAAS;QAC5B,CAAC,CAAC,2BAA2B,CAAE,SAAS,CAAE;QAC1C,CAAC,CAAC,SAAS,CACZ,CAAC;IACF,MAAM,OAAO,CAAC,MAAM,EAAE,CAAC;AACxB,CAAC"}
@@ -1,37 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PageUtils = void 0;
4
- /**
5
- * Internal dependencies
6
- */
7
- const drag_files_1 = require("./drag-files");
8
- const is_current_url_1 = require("./is-current-url");
9
- const press_keys_1 = require("./press-keys");
10
- const set_browser_viewport_1 = require("./set-browser-viewport");
11
- const emulate_network_conditions_1 = require("./emulate-network-conditions");
12
- class PageUtils {
13
- browser;
14
- page;
15
- context;
16
- browserName;
17
- constructor({ page, browserName }) {
18
- this.page = page;
19
- this.context = page.context();
20
- this.browser = this.context.browser();
21
- this.browserName = browserName;
22
- }
23
- /** @borrows dragFiles as this.dragFiles */
24
- dragFiles = drag_files_1.dragFiles.bind(this);
25
- /** @borrows isCurrentURL as this.isCurrentURL */
26
- isCurrentURL = is_current_url_1.isCurrentURL.bind(this);
27
- /** @borrows pressKeys as this.pressKeys */
28
- pressKeys = press_keys_1.pressKeys.bind(this);
29
- /** @borrows setBrowserViewport as this.setBrowserViewport */
30
- setBrowserViewport = set_browser_viewport_1.setBrowserViewport.bind(this);
31
- /** @borrows setClipboardData as this.setClipboardData */
32
- setClipboardData = press_keys_1.setClipboardData.bind(this);
33
- /** @borrows emulateNetworkConditions as this.emulateNetworkConditions */
34
- emulateNetworkConditions = emulate_network_conditions_1.emulateNetworkConditions.bind(this);
35
- }
36
- exports.PageUtils = PageUtils;
37
- //# sourceMappingURL=index.js.map