@wordpress/e2e-test-utils-playwright 1.46.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.
- package/build-types/admin/index.d.ts +3 -0
- package/build-types/admin/index.d.ts.map +1 -1
- package/build-types/admin/visit-site-editor.d.ts.map +1 -1
- package/build-types/admin/wait-for-site-editor.d.ts +12 -0
- package/build-types/admin/wait-for-site-editor.d.ts.map +1 -0
- package/build-types/metrics/index.d.ts +22 -5
- package/build-types/metrics/index.d.ts.map +1 -1
- package/build-types/request-utils/index.d.ts +3 -1
- package/build-types/request-utils/index.d.ts.map +1 -1
- package/build-types/request-utils/preferences.d.ts +11 -0
- package/build-types/request-utils/preferences.d.ts.map +1 -1
- package/package.json +4 -5
- package/src/admin/create-new-post.ts +47 -0
- package/src/admin/edit-post.ts +24 -0
- package/{build/admin/get-page-error.js → src/admin/get-page-error.ts} +12 -9
- package/src/admin/index.ts +52 -0
- package/src/admin/visit-admin-page.ts +43 -0
- package/src/admin/visit-site-editor.ts +62 -0
- package/src/admin/wait-for-site-editor.ts +52 -0
- package/src/config.ts +12 -0
- package/src/editor/click-block-options-menu-item.ts +18 -0
- package/src/editor/click-block-toolbar-button.ts +21 -0
- package/src/editor/get-blocks.ts +75 -0
- package/src/editor/get-edited-post-content.ts +19 -0
- package/src/editor/index.ts +95 -0
- package/src/editor/insert-block.ts +54 -0
- package/src/editor/open-document-settings-sidebar.ts +31 -0
- package/src/editor/preview.ts +32 -0
- package/src/editor/publish-post.ts +51 -0
- package/src/editor/save-draft.ts +20 -0
- package/src/editor/select-blocks.ts +48 -0
- package/src/editor/set-content.ts +24 -0
- package/src/editor/set-is-fixed-toolbar.ts +20 -0
- package/src/editor/set-preferences.ts +37 -0
- package/src/editor/show-block-toolbar.ts +20 -0
- package/src/editor/site-editor.ts +55 -0
- package/src/editor/switch-editor-tool.ts +34 -0
- package/src/editor/switch-to-legacy-canvas.ts +20 -0
- package/src/editor/transform-block-to.ts +34 -0
- package/src/index.ts +8 -0
- package/src/lighthouse/index.ts +75 -0
- package/src/metrics/index.ts +441 -0
- package/src/page-utils/drag-files.ts +173 -0
- package/src/page-utils/emulate-network-conditions.ts +101 -0
- package/src/page-utils/index.ts +54 -0
- package/src/page-utils/is-current-url.ts +20 -0
- package/src/page-utils/keycodes.ts +48 -0
- package/src/page-utils/press-keys.ts +195 -0
- package/{build → src}/page-utils/set-browser-viewport.js +14 -12
- package/src/request-utils/blocks.ts +58 -0
- package/src/request-utils/comments.ts +80 -0
- package/src/request-utils/gutenberg-experiments.ts +62 -0
- package/src/request-utils/index.ts +222 -0
- package/src/request-utils/login.ts +34 -0
- package/src/request-utils/media.ts +102 -0
- package/src/request-utils/menus.ts +145 -0
- package/src/request-utils/pages.ts +75 -0
- package/src/request-utils/patterns.ts +31 -0
- package/src/request-utils/plugins.ts +103 -0
- package/src/request-utils/posts.ts +69 -0
- package/src/request-utils/preferences.ts +63 -0
- package/{build/request-utils/records.js → src/request-utils/records.ts} +15 -10
- package/src/request-utils/rest.ts +222 -0
- package/src/request-utils/site-settings.ts +58 -0
- package/src/request-utils/templates.ts +83 -0
- package/src/request-utils/themes.ts +110 -0
- package/src/request-utils/users.ts +125 -0
- package/src/request-utils/widgets.js +68 -0
- package/src/test.ts +204 -0
- package/src/types.ts +13 -0
- package/build/admin/create-new-post.cjs +0 -51
- package/build/admin/create-new-post.cjs.map +0 -7
- package/build/admin/create-new-post.js +0 -31
- package/build/admin/create-new-post.js.map +0 -1
- package/build/admin/edit-post.cjs +0 -40
- package/build/admin/edit-post.cjs.map +0 -7
- package/build/admin/edit-post.js +0 -20
- package/build/admin/edit-post.js.map +0 -1
- package/build/admin/get-page-error.cjs +0 -36
- package/build/admin/get-page-error.cjs.map +0 -7
- package/build/admin/get-page-error.js.map +0 -1
- package/build/admin/index.cjs +0 -59
- package/build/admin/index.cjs.map +0 -7
- package/build/admin/index.js +0 -37
- package/build/admin/index.js.map +0 -1
- package/build/admin/visit-admin-page.cjs +0 -47
- package/build/admin/visit-admin-page.cjs.map +0 -7
- package/build/admin/visit-admin-page.js +0 -32
- package/build/admin/visit-admin-page.js.map +0 -1
- package/build/admin/visit-site-editor.cjs +0 -90
- package/build/admin/visit-site-editor.cjs.map +0 -7
- package/build/admin/visit-site-editor.js +0 -73
- package/build/admin/visit-site-editor.js.map +0 -1
- package/build/config.cjs +0 -45
- package/build/config.cjs.map +0 -7
- package/build/config.js +0 -13
- package/build/config.js.map +0 -1
- package/build/editor/click-block-options-menu-item.cjs +0 -34
- package/build/editor/click-block-options-menu-item.cjs.map +0 -7
- package/build/editor/click-block-options-menu-item.js +0 -17
- package/build/editor/click-block-options-menu-item.js.map +0 -1
- package/build/editor/click-block-toolbar-button.cjs +0 -38
- package/build/editor/click-block-toolbar-button.cjs.map +0 -7
- package/build/editor/click-block-toolbar-button.js +0 -16
- package/build/editor/click-block-toolbar-button.js.map +0 -1
- package/build/editor/get-blocks.cjs +0 -64
- package/build/editor/get-blocks.cjs.map +0 -7
- package/build/editor/get-blocks.js +0 -45
- package/build/editor/get-blocks.js.map +0 -1
- package/build/editor/get-edited-post-content.cjs +0 -36
- package/build/editor/get-edited-post-content.cjs.map +0 -7
- package/build/editor/get-edited-post-content.js +0 -15
- package/build/editor/get-edited-post-content.js.map +0 -1
- package/build/editor/index.cjs +0 -97
- package/build/editor/index.cjs.map +0 -7
- package/build/editor/index.js +0 -75
- package/build/editor/index.js.map +0 -1
- package/build/editor/insert-block.cjs +0 -55
- package/build/editor/insert-block.cjs.map +0 -7
- package/build/editor/insert-block.js +0 -23
- package/build/editor/insert-block.js.map +0 -1
- package/build/editor/open-document-settings-sidebar.cjs +0 -42
- package/build/editor/open-document-settings-sidebar.cjs.map +0 -7
- package/build/editor/open-document-settings-sidebar.js +0 -27
- package/build/editor/open-document-settings-sidebar.js.map +0 -1
- package/build/editor/preview.cjs +0 -42
- package/build/editor/preview.cjs.map +0 -7
- package/build/editor/preview.js +0 -21
- package/build/editor/preview.js.map +0 -1
- package/build/editor/publish-post.cjs +0 -47
- package/build/editor/publish-post.cjs.map +0 -7
- package/build/editor/publish-post.js +0 -45
- package/build/editor/publish-post.js.map +0 -1
- package/build/editor/save-draft.cjs +0 -34
- package/build/editor/save-draft.cjs.map +0 -7
- package/build/editor/save-draft.js +0 -18
- package/build/editor/save-draft.js.map +0 -1
- package/build/editor/select-blocks.cjs +0 -51
- package/build/editor/select-blocks.cjs.map +0 -7
- package/build/editor/select-blocks.js +0 -28
- package/build/editor/select-blocks.js.map +0 -1
- package/build/editor/set-content.cjs +0 -39
- package/build/editor/set-content.cjs.map +0 -7
- package/build/editor/set-content.js +0 -17
- package/build/editor/set-content.js.map +0 -1
- package/build/editor/set-is-fixed-toolbar.cjs +0 -36
- package/build/editor/set-is-fixed-toolbar.cjs.map +0 -7
- package/build/editor/set-is-fixed-toolbar.js +0 -18
- package/build/editor/set-is-fixed-toolbar.js.map +0 -1
- package/build/editor/set-preferences.cjs +0 -43
- package/build/editor/set-preferences.cjs.map +0 -7
- package/build/editor/set-preferences.js +0 -21
- package/build/editor/set-preferences.js.map +0 -1
- package/build/editor/show-block-toolbar.cjs +0 -35
- package/build/editor/show-block-toolbar.cjs.map +0 -7
- package/build/editor/show-block-toolbar.js +0 -19
- package/build/editor/show-block-toolbar.js.map +0 -1
- package/build/editor/site-editor.cjs +0 -51
- package/build/editor/site-editor.cjs.map +0 -7
- package/build/editor/site-editor.js +0 -44
- package/build/editor/site-editor.js.map +0 -1
- package/build/editor/switch-editor-tool.cjs +0 -47
- package/build/editor/switch-editor-tool.cjs.map +0 -7
- package/build/editor/switch-editor-tool.js +0 -33
- package/build/editor/switch-editor-tool.js.map +0 -1
- package/build/editor/switch-to-legacy-canvas.cjs +0 -39
- package/build/editor/switch-to-legacy-canvas.cjs.map +0 -7
- package/build/editor/switch-to-legacy-canvas.js +0 -18
- package/build/editor/switch-to-legacy-canvas.js.map +0 -1
- package/build/editor/transform-block-to.cjs +0 -46
- package/build/editor/transform-block-to.cjs.map +0 -7
- package/build/editor/transform-block-to.js +0 -24
- package/build/editor/transform-block-to.js.map +0 -1
- package/build/index.cjs +0 -51
- package/build/index.cjs.map +0 -7
- package/build/index.js +0 -19
- package/build/index.js.map +0 -1
- package/build/lighthouse/index.cjs +0 -96
- package/build/lighthouse/index.cjs.map +0 -7
- package/build/lighthouse/index.js +0 -61
- package/build/lighthouse/index.js.map +0 -1
- package/build/metrics/index.cjs +0 -309
- package/build/metrics/index.cjs.map +0 -7
- package/build/metrics/index.js +0 -258
- package/build/metrics/index.js.map +0 -1
- package/build/page-utils/drag-files.cjs +0 -143
- package/build/page-utils/drag-files.cjs.map +0 -7
- package/build/page-utils/drag-files.js +0 -119
- package/build/page-utils/drag-files.js.map +0 -1
- package/build/page-utils/emulate-network-conditions.cjs +0 -99
- package/build/page-utils/emulate-network-conditions.cjs.map +0 -7
- package/build/page-utils/emulate-network-conditions.js +0 -71
- package/build/page-utils/emulate-network-conditions.js.map +0 -1
- package/build/page-utils/index.cjs +0 -59
- package/build/page-utils/index.cjs.map +0 -7
- package/build/page-utils/index.js +0 -37
- package/build/page-utils/index.js.map +0 -1
- package/build/page-utils/is-current-url.cjs +0 -36
- package/build/page-utils/is-current-url.cjs.map +0 -7
- package/build/page-utils/is-current-url.js +0 -21
- package/build/page-utils/is-current-url.js.map +0 -1
- package/build/page-utils/keycodes.cjs +0 -55
- package/build/page-utils/keycodes.cjs.map +0 -7
- package/build/page-utils/keycodes.js +0 -41
- package/build/page-utils/keycodes.js.map +0 -1
- package/build/page-utils/press-keys.cjs +0 -165
- package/build/page-utils/press-keys.cjs.map +0 -7
- package/build/page-utils/press-keys.js +0 -141
- package/build/page-utils/press-keys.js.map +0 -1
- package/build/page-utils/set-browser-viewport.cjs +0 -39
- package/build/page-utils/set-browser-viewport.cjs.map +0 -7
- package/build/page-utils/set-browser-viewport.js.map +0 -1
- package/build/request-utils/blocks.cjs +0 -51
- package/build/request-utils/blocks.cjs.map +0 -7
- package/build/request-utils/blocks.js +0 -40
- package/build/request-utils/blocks.js.map +0 -1
- package/build/request-utils/comments.cjs +0 -66
- package/build/request-utils/comments.cjs.map +0 -7
- package/build/request-utils/comments.js +0 -52
- package/build/request-utils/comments.js.map +0 -1
- package/build/request-utils/gutenberg-experiments.cjs +0 -56
- package/build/request-utils/gutenberg-experiments.cjs.map +0 -7
- package/build/request-utils/gutenberg-experiments.js +0 -47
- package/build/request-utils/gutenberg-experiments.js.map +0 -1
- package/build/request-utils/index.cjs +0 -199
- package/build/request-utils/index.cjs.map +0 -7
- package/build/request-utils/index.js +0 -194
- package/build/request-utils/index.js.map +0 -1
- package/build/request-utils/login.cjs +0 -48
- package/build/request-utils/login.cjs.map +0 -7
- package/build/request-utils/login.js +0 -21
- package/build/request-utils/login.js.map +0 -1
- package/build/request-utils/media.cjs +0 -83
- package/build/request-utils/media.cjs.map +0 -7
- package/build/request-utils/media.js +0 -106
- package/build/request-utils/media.js.map +0 -1
- package/build/request-utils/menus.cjs +0 -128
- package/build/request-utils/menus.cjs.map +0 -7
- package/build/request-utils/menus.js +0 -116
- package/build/request-utils/menus.js.map +0 -1
- package/build/request-utils/pages.cjs +0 -66
- package/build/request-utils/pages.cjs.map +0 -7
- package/build/request-utils/pages.js +0 -53
- package/build/request-utils/pages.js.map +0 -1
- package/build/request-utils/patterns.cjs +0 -44
- package/build/request-utils/patterns.cjs.map +0 -7
- package/build/request-utils/patterns.js +0 -27
- package/build/request-utils/patterns.js.map +0 -1
- package/build/request-utils/plugins.cjs +0 -81
- package/build/request-utils/plugins.cjs.map +0 -7
- package/build/request-utils/plugins.js +0 -85
- package/build/request-utils/plugins.js.map +0 -1
- package/build/request-utils/posts.cjs +0 -56
- package/build/request-utils/posts.cjs.map +0 -7
- package/build/request-utils/posts.js +0 -42
- package/build/request-utils/posts.js.map +0 -1
- package/build/request-utils/preferences.cjs +0 -41
- package/build/request-utils/preferences.cjs.map +0 -7
- package/build/request-utils/preferences.js +0 -20
- package/build/request-utils/preferences.js.map +0 -1
- package/build/request-utils/records.cjs +0 -37
- package/build/request-utils/records.cjs.map +0 -7
- package/build/request-utils/records.js.map +0 -1
- package/build/request-utils/rest.cjs +0 -174
- package/build/request-utils/rest.cjs.map +0 -7
- package/build/request-utils/rest.js +0 -181
- package/build/request-utils/rest.js.map +0 -1
- package/build/request-utils/site-settings.cjs +0 -45
- package/build/request-utils/site-settings.cjs.map +0 -7
- package/build/request-utils/site-settings.js +0 -33
- package/build/request-utils/site-settings.js.map +0 -1
- package/build/request-utils/templates.cjs +0 -68
- package/build/request-utils/templates.cjs.map +0 -7
- package/build/request-utils/templates.js +0 -54
- package/build/request-utils/templates.js.map +0 -1
- package/build/request-utils/themes.cjs +0 -92
- package/build/request-utils/themes.cjs.map +0 -7
- package/build/request-utils/themes.js +0 -69
- package/build/request-utils/themes.js.map +0 -1
- package/build/request-utils/users.cjs +0 -83
- package/build/request-utils/users.cjs.map +0 -7
- package/build/request-utils/users.js +0 -81
- package/build/request-utils/users.js.map +0 -1
- package/build/request-utils/widgets.cjs +0 -79
- package/build/request-utils/widgets.cjs.map +0 -7
- package/build/request-utils/widgets.js +0 -61
- package/build/request-utils/widgets.js.map +0 -1
- package/build/test.cjs +0 -136
- package/build/test.cjs.map +0 -7
- package/build/test.js +0 -189
- package/build/test.js.map +0 -1
- package/build/types.cjs +0 -19
- package/build/types.cjs.map +0 -7
- package/build/types.js +0 -3
- package/build/types.js.map +0 -1
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// packages/e2e-test-utils-playwright/src/page-utils/drag-files.ts
|
|
21
|
-
var drag_files_exports = {};
|
|
22
|
-
__export(drag_files_exports, {
|
|
23
|
-
dragFiles: () => dragFiles
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(drag_files_exports);
|
|
26
|
-
var import_promises = require("fs/promises");
|
|
27
|
-
var import_path = require("path");
|
|
28
|
-
var import_mime = require("mime");
|
|
29
|
-
async function dragFiles(files) {
|
|
30
|
-
const filesList = Array.isArray(files) ? files : [files];
|
|
31
|
-
const fileObjects = await Promise.all(
|
|
32
|
-
filesList.map(async (filePathOrObject) => {
|
|
33
|
-
if (typeof filePathOrObject !== "string") {
|
|
34
|
-
return {
|
|
35
|
-
name: filePathOrObject.name,
|
|
36
|
-
mimeType: filePathOrObject.mimeType || (0, import_mime.getType)(filePathOrObject.name),
|
|
37
|
-
base64: filePathOrObject.buffer.toString("base64")
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
const base64 = await (0, import_promises.readFile)(filePathOrObject, "base64");
|
|
41
|
-
const name = (0, import_path.basename)(filePathOrObject);
|
|
42
|
-
return {
|
|
43
|
-
name,
|
|
44
|
-
mimeType: (0, import_mime.getType)(filePathOrObject),
|
|
45
|
-
base64
|
|
46
|
-
};
|
|
47
|
-
})
|
|
48
|
-
);
|
|
49
|
-
const dragData = {
|
|
50
|
-
items: fileObjects.map((fileObject) => ({
|
|
51
|
-
mimeType: fileObject.mimeType ?? "File",
|
|
52
|
-
data: fileObject.base64
|
|
53
|
-
})),
|
|
54
|
-
files: fileObjects.map((fileObject) => fileObject.name),
|
|
55
|
-
// Copy = 1, Link = 2, Move = 16.
|
|
56
|
-
dragOperationsMask: 1
|
|
57
|
-
};
|
|
58
|
-
const cdpSession = await this.context.newCDPSession(this.page);
|
|
59
|
-
const position = {
|
|
60
|
-
x: 0,
|
|
61
|
-
y: 0
|
|
62
|
-
};
|
|
63
|
-
return {
|
|
64
|
-
/**
|
|
65
|
-
* Drag the files over an element (fires `dragenter` and `dragover` events).
|
|
66
|
-
*
|
|
67
|
-
* @param selectorOrLocator A selector or a locator to search for an element.
|
|
68
|
-
* @param options The optional options.
|
|
69
|
-
* @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.
|
|
70
|
-
*/
|
|
71
|
-
dragOver: async (selectorOrLocator, options = {}) => {
|
|
72
|
-
const locator = typeof selectorOrLocator === "string" ? this.page.locator(selectorOrLocator) : selectorOrLocator;
|
|
73
|
-
const boundingBox = await locator.boundingBox();
|
|
74
|
-
if (!boundingBox) {
|
|
75
|
-
throw new Error(
|
|
76
|
-
"Cannot find the element or the element is not visible on the viewport."
|
|
77
|
-
);
|
|
78
|
-
}
|
|
79
|
-
position.x = boundingBox.x + (options.position?.x ?? boundingBox.width / 2);
|
|
80
|
-
position.y = boundingBox.y + (options.position?.y ?? boundingBox.height / 2);
|
|
81
|
-
await cdpSession.send("Input.dispatchDragEvent", {
|
|
82
|
-
type: "dragEnter",
|
|
83
|
-
...position,
|
|
84
|
-
data: dragData
|
|
85
|
-
});
|
|
86
|
-
await cdpSession.send("Input.dispatchDragEvent", {
|
|
87
|
-
type: "dragOver",
|
|
88
|
-
...position,
|
|
89
|
-
data: dragData
|
|
90
|
-
});
|
|
91
|
-
},
|
|
92
|
-
/**
|
|
93
|
-
* Drop the files at the current position.
|
|
94
|
-
*/
|
|
95
|
-
drop: async () => {
|
|
96
|
-
const topMostElement = await this.page.evaluateHandle(
|
|
97
|
-
({ x, y }) => {
|
|
98
|
-
const element = document.elementFromPoint(x, y);
|
|
99
|
-
if (element instanceof HTMLIFrameElement) {
|
|
100
|
-
const offsetBox = element.getBoundingClientRect();
|
|
101
|
-
return element.contentDocument.elementFromPoint(
|
|
102
|
-
x - offsetBox.x,
|
|
103
|
-
y - offsetBox.y
|
|
104
|
-
);
|
|
105
|
-
}
|
|
106
|
-
return element;
|
|
107
|
-
},
|
|
108
|
-
position
|
|
109
|
-
);
|
|
110
|
-
const elementHandle = topMostElement.asElement();
|
|
111
|
-
if (!elementHandle) {
|
|
112
|
-
throw new Error("Element not found.");
|
|
113
|
-
}
|
|
114
|
-
const dataTransfer = await elementHandle.evaluateHandle(
|
|
115
|
-
async (_node, _fileObjects) => {
|
|
116
|
-
const dt = new DataTransfer();
|
|
117
|
-
const fileInstances = await Promise.all(
|
|
118
|
-
_fileObjects.map(async (fileObject) => {
|
|
119
|
-
const blob = await fetch(
|
|
120
|
-
`data:${fileObject.mimeType};base64,${fileObject.base64}`
|
|
121
|
-
).then((res) => res.blob());
|
|
122
|
-
return new File([blob], fileObject.name, {
|
|
123
|
-
type: fileObject.mimeType ?? void 0
|
|
124
|
-
});
|
|
125
|
-
})
|
|
126
|
-
);
|
|
127
|
-
fileInstances.forEach((file) => {
|
|
128
|
-
dt.items.add(file);
|
|
129
|
-
});
|
|
130
|
-
return dt;
|
|
131
|
-
},
|
|
132
|
-
fileObjects
|
|
133
|
-
);
|
|
134
|
-
await elementHandle.dispatchEvent("drop", { dataTransfer });
|
|
135
|
-
await cdpSession.detach();
|
|
136
|
-
}
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
140
|
-
0 && (module.exports = {
|
|
141
|
-
dragFiles
|
|
142
|
-
});
|
|
143
|
-
//# sourceMappingURL=drag-files.cjs.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/page-utils/drag-files.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\nimport { readFile } from 'fs/promises';\nimport { basename } from 'path';\nimport { getType } from 'mime';\n\n/**\n * Internal dependencies\n */\nimport type { PageUtils } from './index';\nimport type { Locator } from '@playwright/test';\n\ntype FileObject = {\n\tname: string;\n\tmimeType?: string;\n\tbuffer: Buffer;\n};\n\ntype Options = {\n\tposition?: { x: number; y: number };\n};\n\n/**\n * Simulate dragging files from outside the current page.\n *\n * @param this\n * @param files The files to be dragged.\n * @return The methods of the drag operation.\n */\nasync function dragFiles(\n\tthis: PageUtils,\n\tfiles: string | string[] | FileObject | FileObject[]\n) {\n\tconst filesList = Array.isArray( files ) ? files : [ files ];\n\tconst fileObjects = await Promise.all(\n\t\tfilesList.map( async ( filePathOrObject ) => {\n\t\t\tif ( typeof filePathOrObject !== 'string' ) {\n\t\t\t\treturn {\n\t\t\t\t\tname: filePathOrObject.name,\n\t\t\t\t\tmimeType:\n\t\t\t\t\t\tfilePathOrObject.mimeType ||\n\t\t\t\t\t\tgetType( filePathOrObject.name ),\n\t\t\t\t\tbase64: filePathOrObject.buffer.toString( 'base64' ),\n\t\t\t\t};\n\t\t\t}\n\t\t\tconst base64 = await readFile( filePathOrObject, 'base64' );\n\t\t\tconst name = basename( filePathOrObject );\n\t\t\treturn {\n\t\t\t\tname,\n\t\t\t\tmimeType: getType( filePathOrObject ),\n\t\t\t\tbase64,\n\t\t\t};\n\t\t} )\n\t);\n\n\t// CDP doesn't actually support dragging files, this is only a _good enough_\n\t// dummy data so that it will correctly send the relevant events.\n\tconst dragData = {\n\t\titems: fileObjects.map( ( fileObject ) => ( {\n\t\t\tmimeType: fileObject.mimeType ?? 'File',\n\t\t\tdata: fileObject.base64,\n\t\t} ) ),\n\t\tfiles: fileObjects.map( ( fileObject ) => fileObject.name ),\n\t\t// Copy = 1, Link = 2, Move = 16.\n\t\tdragOperationsMask: 1,\n\t};\n\n\tconst cdpSession = await this.context.newCDPSession( this.page );\n\n\tconst position = {\n\t\tx: 0,\n\t\ty: 0,\n\t};\n\n\treturn {\n\t\t/**\n\t\t * Drag the files over an element (fires `dragenter` and `dragover` events).\n\t\t *\n\t\t * @param selectorOrLocator A selector or a locator to search for an element.\n\t\t * @param options The optional options.\n\t\t * @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.\n\t\t */\n\t\tdragOver: async (\n\t\t\tselectorOrLocator: string | Locator,\n\t\t\toptions: Options = {}\n\t\t) => {\n\t\t\tconst locator =\n\t\t\t\ttypeof selectorOrLocator === 'string'\n\t\t\t\t\t? this.page.locator( selectorOrLocator )\n\t\t\t\t\t: selectorOrLocator;\n\t\t\tconst boundingBox = await locator.boundingBox();\n\n\t\t\tif ( ! boundingBox ) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t'Cannot find the element or the element is not visible on the viewport.'\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tposition.x =\n\t\t\t\tboundingBox.x +\n\t\t\t\t( options.position?.x ?? boundingBox.width / 2 );\n\t\t\tposition.y =\n\t\t\t\tboundingBox.y +\n\t\t\t\t( options.position?.y ?? boundingBox.height / 2 );\n\n\t\t\tawait cdpSession.send( 'Input.dispatchDragEvent', {\n\t\t\t\ttype: 'dragEnter',\n\t\t\t\t...position,\n\t\t\t\tdata: dragData,\n\t\t\t} );\n\t\t\tawait cdpSession.send( 'Input.dispatchDragEvent', {\n\t\t\t\ttype: 'dragOver',\n\t\t\t\t...position,\n\t\t\t\tdata: dragData,\n\t\t\t} );\n\t\t},\n\n\t\t/**\n\t\t * Drop the files at the current position.\n\t\t */\n\t\tdrop: async () => {\n\t\t\tconst topMostElement = await this.page.evaluateHandle(\n\t\t\t\t( { x, y } ) => {\n\t\t\t\t\tconst element = document.elementFromPoint( x, y );\n\t\t\t\t\tif ( element instanceof HTMLIFrameElement ) {\n\t\t\t\t\t\tconst offsetBox = element.getBoundingClientRect();\n\t\t\t\t\t\treturn element.contentDocument!.elementFromPoint(\n\t\t\t\t\t\t\tx - offsetBox.x,\n\t\t\t\t\t\t\ty - offsetBox.y\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\treturn element;\n\t\t\t\t},\n\t\t\t\tposition\n\t\t\t);\n\t\t\tconst elementHandle = topMostElement.asElement();\n\n\t\t\tif ( ! elementHandle ) {\n\t\t\t\tthrow new Error( 'Element not found.' );\n\t\t\t}\n\n\t\t\tconst dataTransfer = await elementHandle.evaluateHandle(\n\t\t\t\tasync ( _node, _fileObjects ) => {\n\t\t\t\t\tconst dt = new DataTransfer();\n\t\t\t\t\tconst fileInstances = await Promise.all(\n\t\t\t\t\t\t_fileObjects.map( async ( fileObject: any ) => {\n\t\t\t\t\t\t\tconst blob = await fetch(\n\t\t\t\t\t\t\t\t`data:${ fileObject.mimeType };base64,${ fileObject.base64 }`\n\t\t\t\t\t\t\t).then( ( res ) => res.blob() );\n\t\t\t\t\t\t\treturn new File( [ blob ], fileObject.name, {\n\t\t\t\t\t\t\t\ttype: fileObject.mimeType ?? undefined,\n\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t} )\n\t\t\t\t\t);\n\n\t\t\t\t\tfileInstances.forEach( ( file ) => {\n\t\t\t\t\t\tdt.items.add( file );\n\t\t\t\t\t} );\n\n\t\t\t\t\treturn dt;\n\t\t\t\t},\n\t\t\t\tfileObjects\n\t\t\t);\n\n\t\t\tawait elementHandle.dispatchEvent( 'drop', { dataTransfer } );\n\n\t\t\tawait cdpSession.detach();\n\t\t},\n\t};\n}\n\nexport { dragFiles };\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,sBAAyB;AACzB,kBAAyB;AACzB,kBAAwB;AAyBxB,eAAe,UAEd,OACC;AACD,QAAM,YAAY,MAAM,QAAS,KAAM,IAAI,QAAQ,CAAE,KAAM;AAC3D,QAAM,cAAc,MAAM,QAAQ;AAAA,IACjC,UAAU,IAAK,OAA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M,WAAW,OAAO;AAAA,IACzB;AAAA,EACD;AACD;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -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,C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,CAAC,GAAG,CAAE,IAAI,CAAE,CAAC;gBACtB,CAAC,CAAE,CAAC;gBAEJ,OAAO,EAAE,CAAC;YACX,CAAC,EACD,WAAW,CACX,CAAC;YAEF,MAAM,aAAa,CAAC,aAAa,CAAE,MAAM,EAAE,EAAE,YAAY,EAAE,CAAE,CAAC;YAE9D,MAAM,UAAU,CAAC,MAAM,EAAE,CAAC;QAC3B,CAAC;KACD,CAAC;AACH,CAAC"}
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// packages/e2e-test-utils-playwright/src/page-utils/emulate-network-conditions.ts
|
|
21
|
-
var emulate_network_conditions_exports = {};
|
|
22
|
-
__export(emulate_network_conditions_exports, {
|
|
23
|
-
emulateNetworkConditions: () => emulateNetworkConditions
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(emulate_network_conditions_exports);
|
|
26
|
-
var PredefinedNetworkConditions = {
|
|
27
|
-
// Generally aligned with DevTools
|
|
28
|
-
// https://source.chromium.org/chromium/chromium/src/+/main:third_party/devtools-frontend/src/front_end/core/sdk/NetworkManager.ts;l=398;drc=225e1240f522ca684473f541ae6dae6cd766dd33.
|
|
29
|
-
"Slow 3G": {
|
|
30
|
-
offline: false,
|
|
31
|
-
// ~500Kbps down
|
|
32
|
-
downloadThroughput: 500 * 1e3 / 8 * 0.8,
|
|
33
|
-
// ~500Kbps up
|
|
34
|
-
uploadThroughput: 500 * 1e3 / 8 * 0.8,
|
|
35
|
-
// 400ms RTT
|
|
36
|
-
latency: 400 * 5
|
|
37
|
-
},
|
|
38
|
-
"Fast 3G": {
|
|
39
|
-
offline: false,
|
|
40
|
-
// ~1.6 Mbps down
|
|
41
|
-
downloadThroughput: 1.6 * 1e3 * 1e3 / 8 * 0.9,
|
|
42
|
-
// ~0.75 Mbps up
|
|
43
|
-
uploadThroughput: 750 * 1e3 / 8 * 0.9,
|
|
44
|
-
// 150ms RTT
|
|
45
|
-
latency: 150 * 3.75
|
|
46
|
-
},
|
|
47
|
-
// alias to Fast 3G to align with Lighthouse (crbug.com/342406608)
|
|
48
|
-
// and DevTools (crbug.com/342406608),
|
|
49
|
-
"Slow 4G": {
|
|
50
|
-
offline: false,
|
|
51
|
-
// ~1.6 Mbps down
|
|
52
|
-
downloadThroughput: 1.6 * 1e3 * 1e3 / 8 * 0.9,
|
|
53
|
-
// ~0.75 Mbps up
|
|
54
|
-
uploadThroughput: 750 * 1e3 / 8 * 0.9,
|
|
55
|
-
// 150ms RTT
|
|
56
|
-
latency: 150 * 3.75
|
|
57
|
-
},
|
|
58
|
-
"Fast 4G": {
|
|
59
|
-
offline: false,
|
|
60
|
-
// 9 Mbps down
|
|
61
|
-
downloadThroughput: 9 * 1e3 * 1e3 / 8 * 0.9,
|
|
62
|
-
// 1.5 Mbps up
|
|
63
|
-
uploadThroughput: 1.5 * 1e3 * 1e3 / 8 * 0.9,
|
|
64
|
-
// 60ms RTT
|
|
65
|
-
latency: 60 * 2.75
|
|
66
|
-
},
|
|
67
|
-
/**
|
|
68
|
-
* Network conditions used for desktop in Lighthouse/PSI.
|
|
69
|
-
*
|
|
70
|
-
* 10,240 kb/s throughput with 40 ms TCP RTT.
|
|
71
|
-
*
|
|
72
|
-
* @see https://github.com/paulirish/lighthouse/blob/f0855904aaffaecf3089169449646960782d7e92/core/config/constants.js#L40-L49
|
|
73
|
-
* @see https://docs.google.com/document/d/1-p4HSp42REEA5-jCBVB6PqQcVhI1nQIblBCNKhPJUXg/edit?tab=t.0#heading=h.jsap7yf4phk6
|
|
74
|
-
*/
|
|
75
|
-
Broadband: {
|
|
76
|
-
offline: false,
|
|
77
|
-
downloadThroughput: 10240 * 1e3 / 8,
|
|
78
|
-
uploadThroughput: 10240 * 1e3 / 8,
|
|
79
|
-
latency: 40
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
async function emulateNetworkConditions(condition) {
|
|
83
|
-
if ("chromium" !== this.browserName) {
|
|
84
|
-
throw new Error(
|
|
85
|
-
"CDP sessions are only supported on Chromium-based browsers"
|
|
86
|
-
);
|
|
87
|
-
}
|
|
88
|
-
const session = await this.page.context().newCDPSession(this.page);
|
|
89
|
-
await session.send(
|
|
90
|
-
"Network.emulateNetworkConditions",
|
|
91
|
-
"string" === typeof condition ? PredefinedNetworkConditions[condition] : condition
|
|
92
|
-
);
|
|
93
|
-
await session.detach();
|
|
94
|
-
}
|
|
95
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
96
|
-
0 && (module.exports = {
|
|
97
|
-
emulateNetworkConditions
|
|
98
|
-
});
|
|
99
|
-
//# sourceMappingURL=emulate-network-conditions.cjs.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/page-utils/emulate-network-conditions.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { PageUtils } from './';\n\ninterface NetworkConditions {\n\t/**\n\t * True to emulate internet disconnection.\n\t */\n\toffline: boolean;\n\t/**\n\t * Minimum latency from request sent to response headers received (ms).\n\t */\n\tlatency: number;\n\t/**\n\t * Maximal aggregated download throughput (bytes/sec). -1 disables download throttling.\n\t */\n\tdownloadThroughput: number;\n\t/**\n\t * Maximal aggregated upload throughput (bytes/sec). -1 disables upload throttling.\n\t */\n\tuploadThroughput: number;\n}\n\n// Defaults from https://github.com/puppeteer/puppeteer/blob/401355610874beac23a51dcb75739a4bb4191a2b/packages/puppeteer-core/src/cdp/PredefinedNetworkConditions.ts.\nconst PredefinedNetworkConditions: Record< string, NetworkConditions > = {\n\t// Generally aligned with DevTools\n\t// https://source.chromium.org/chromium/chromium/src/+/main:third_party/devtools-frontend/src/front_end/core/sdk/NetworkManager.ts;l=398;drc=225e1240f522ca684473f541ae6dae6cd766dd33.\n\t'Slow 3G': {\n\t\toffline: false,\n\t\t// ~500Kbps down\n\t\tdownloadThroughput: ( ( 500 * 1000 ) / 8 ) * 0.8,\n\t\t// ~500Kbps up\n\t\tuploadThroughput: ( ( 500 * 1000 ) / 8 ) * 0.8,\n\t\t// 400ms RTT\n\t\tlatency: 400 * 5,\n\t},\n\t'Fast 3G': {\n\t\toffline: false,\n\t\t// ~1.6 Mbps down\n\t\tdownloadThroughput: ( ( 1.6 * 1000 * 1000 ) / 8 ) * 0.9,\n\t\t// ~0.75 Mbps up\n\t\tuploadThroughput: ( ( 750 * 1000 ) / 8 ) * 0.9,\n\t\t// 150ms RTT\n\t\tlatency: 150 * 3.75,\n\t},\n\t// alias to Fast 3G to align with Lighthouse (crbug.com/342406608)\n\t// and DevTools (crbug.com/342406608),\n\t'Slow 4G': {\n\t\toffline: false,\n\t\t// ~1.6 Mbps down\n\t\tdownloadThroughput: ( ( 1.6 * 1000 * 1000 ) / 8 ) * 0.9,\n\t\t// ~0.75 Mbps up\n\t\tuploadThroughput: ( ( 750 * 1000 ) / 8 ) * 0.9,\n\t\t// 150ms RTT\n\t\tlatency: 150 * 3.75,\n\t},\n\t'Fast 4G': {\n\t\toffline: false,\n\t\t// 9 Mbps down\n\t\tdownloadThroughput: ( ( 9 * 1000 * 1000 ) / 8 ) * 0.9,\n\t\t// 1.5 Mbps up\n\t\tuploadThroughput: ( ( 1.5 * 1000 * 1000 ) / 8 ) * 0.9,\n\t\t// 60ms RTT\n\t\tlatency: 60 * 2.75,\n\t},\n\t/**\n\t * Network conditions used for desktop in Lighthouse/PSI.\n\t *\n\t * 10,240 kb/s throughput with 40 ms TCP RTT.\n\t *\n\t * @see https://github.com/paulirish/lighthouse/blob/f0855904aaffaecf3089169449646960782d7e92/core/config/constants.js#L40-L49\n\t * @see https://docs.google.com/document/d/1-p4HSp42REEA5-jCBVB6PqQcVhI1nQIblBCNKhPJUXg/edit?tab=t.0#heading=h.jsap7yf4phk6\n\t */\n\tBroadband: {\n\t\toffline: false,\n\t\tdownloadThroughput: ( 10240 * 1000 ) / 8,\n\t\tuploadThroughput: ( 10240 * 1000 ) / 8,\n\t\tlatency: 40,\n\t},\n};\n\nexport async function emulateNetworkConditions(\n\tthis: PageUtils,\n\tcondition: keyof typeof PredefinedNetworkConditions | NetworkConditions\n) {\n\tif ( 'chromium' !== this.browserName ) {\n\t\tthrow new Error(\n\t\t\t'CDP sessions are only supported on Chromium-based browsers'\n\t\t);\n\t}\n\n\tconst session = await this.page.context().newCDPSession( this.page );\n\tawait session.send(\n\t\t'Network.emulateNetworkConditions',\n\t\t'string' === typeof condition\n\t\t\t? PredefinedNetworkConditions[ condition ]\n\t\t\t: condition\n\t);\n\tawait session.detach();\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAyBA,IAAM,8BAAmE;AAAA;AAAA;AAAA,EAGxE,WAAW;AAAA,IACV,SAAS;AAAA;AAAA,IAET,oBAAwB,MAAM,MAAS,IAAM;AAAA;AAAA,IAE7C,kBAAsB,MAAM,MAAS,IAAM;AAAA;AAAA,IAE3C,SAAS,MAAM;AAAA,EAChB;AAAA,EACA,WAAW;AAAA,IACV,SAAS;AAAA;AAAA,IAET,oBAAwB,MAAM,MAAO,MAAS,IAAM;AAAA;AAAA,IAEpD,kBAAsB,MAAM,MAAS,IAAM;AAAA;AAAA,IAE3C,SAAS,MAAM;AAAA,EAChB;AAAA;AAAA;AAAA,EAGA,WAAW;AAAA,IACV,SAAS;AAAA;AAAA,IAET,oBAAwB,MAAM,MAAO,MAAS,IAAM;AAAA;AAAA,IAEpD,kBAAsB,MAAM,MAAS,IAAM;AAAA;AAAA,IAE3C,SAAS,MAAM;AAAA,EAChB;AAAA,EACA,WAAW;AAAA,IACV,SAAS;AAAA;AAAA,IAET,oBAAwB,IAAI,MAAO,MAAS,IAAM;AAAA;AAAA,IAElD,kBAAsB,MAAM,MAAO,MAAS,IAAM;AAAA;AAAA,IAElD,SAAS,KAAK;AAAA,EACf;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,WAAW;AAAA,IACV,SAAS;AAAA,IACT,oBAAsB,QAAQ,MAAS;AAAA,IACvC,kBAAoB,QAAQ,MAAS;AAAA,IACrC,SAAS;AAAA,EACV;AACD;AAEA,eAAsB,yBAErB,WACC;AACD,MAAK,eAAe,KAAK,aAAc;AACtC,UAAM,IAAI;AAAA,MACT;AAAA,IACD;AAAA,EACD;AAEA,QAAM,UAAU,MAAM,KAAK,KAAK,QAAQ,EAAE,cAAe,KAAK,IAAK;AACnE,QAAM,QAAQ;AAAA,IACb;AAAA,IACA,aAAa,OAAO,YACjB,4BAA6B,SAAU,IACvC;AAAA,EACJ;AACA,QAAM,QAAQ,OAAO;AACtB;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
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,EA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AK;QACd,kBAAkB,EAAE,CAAE,KAAK,GAAG,IAAI,CAAE,GAAG,CAAC;QACxC,gBAAgB,EAAE,CAAE,KAAK,GAAG,IAAI,CAAE,GAAG,CAAC;QACtC,OAAO,EAAE,EAAE;KACX;CACD,CAAC;AAEK,KAAK,mCAEX,SAAuE;IAEvE,IAAK,UAAU,KAAK,IAAI,CAAC,WAAW,EAAG,CAAC;QACvC,MAAM,IAAI,KAAK,CACd,4DAA4D,CAC5D,CAAC;IACH,CAAC;IAED,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,aAAa,CAAE,IAAI,CAAC,IAAI,CAAE,CAAC;IACrE,MAAM,OAAO,CAAC,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,59 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// packages/e2e-test-utils-playwright/src/page-utils/index.ts
|
|
21
|
-
var page_utils_exports = {};
|
|
22
|
-
__export(page_utils_exports, {
|
|
23
|
-
PageUtils: () => PageUtils
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(page_utils_exports);
|
|
26
|
-
var import_drag_files = require("./drag-files.cjs");
|
|
27
|
-
var import_is_current_url = require("./is-current-url.cjs");
|
|
28
|
-
var import_press_keys = require("./press-keys.cjs");
|
|
29
|
-
var import_set_browser_viewport = require("./set-browser-viewport.cjs");
|
|
30
|
-
var import_emulate_network_conditions = require("./emulate-network-conditions.cjs");
|
|
31
|
-
var PageUtils = class {
|
|
32
|
-
browser;
|
|
33
|
-
page;
|
|
34
|
-
context;
|
|
35
|
-
browserName;
|
|
36
|
-
constructor({ page, browserName }) {
|
|
37
|
-
this.page = page;
|
|
38
|
-
this.context = page.context();
|
|
39
|
-
this.browser = this.context.browser();
|
|
40
|
-
this.browserName = browserName;
|
|
41
|
-
}
|
|
42
|
-
/** @borrows dragFiles as this.dragFiles */
|
|
43
|
-
dragFiles = import_drag_files.dragFiles.bind(this);
|
|
44
|
-
/** @borrows isCurrentURL as this.isCurrentURL */
|
|
45
|
-
isCurrentURL = import_is_current_url.isCurrentURL.bind(this);
|
|
46
|
-
/** @borrows pressKeys as this.pressKeys */
|
|
47
|
-
pressKeys = import_press_keys.pressKeys.bind(this);
|
|
48
|
-
/** @borrows setBrowserViewport as this.setBrowserViewport */
|
|
49
|
-
setBrowserViewport = import_set_browser_viewport.setBrowserViewport.bind(this);
|
|
50
|
-
/** @borrows setClipboardData as this.setClipboardData */
|
|
51
|
-
setClipboardData = import_press_keys.setClipboardData.bind(this);
|
|
52
|
-
/** @borrows emulateNetworkConditions as this.emulateNetworkConditions */
|
|
53
|
-
emulateNetworkConditions = import_emulate_network_conditions.emulateNetworkConditions.bind(this);
|
|
54
|
-
};
|
|
55
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
56
|
-
0 && (module.exports = {
|
|
57
|
-
PageUtils
|
|
58
|
-
});
|
|
59
|
-
//# sourceMappingURL=index.cjs.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/page-utils/index.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\nimport type {\n\tBrowser,\n\tPage,\n\tBrowserContext,\n\tPlaywrightWorkerOptions,\n} from '@playwright/test';\n\n/**\n * Internal dependencies\n */\nimport { dragFiles } from './drag-files';\nimport { isCurrentURL } from './is-current-url';\nimport { setClipboardData, pressKeys } from './press-keys';\nimport { setBrowserViewport } from './set-browser-viewport';\nimport { emulateNetworkConditions } from './emulate-network-conditions';\n\ntype PageUtilConstructorParams = {\n\tpage: Page;\n\tbrowserName: PlaywrightWorkerOptions[ 'browserName' ];\n};\n\nclass PageUtils {\n\tbrowser: Browser;\n\tpage: Page;\n\tcontext: BrowserContext;\n\tbrowserName: PlaywrightWorkerOptions[ 'browserName' ];\n\n\tconstructor( { page, browserName }: PageUtilConstructorParams ) {\n\t\tthis.page = page;\n\t\tthis.context = page.context();\n\t\tthis.browser = this.context.browser()!;\n\t\tthis.browserName = browserName;\n\t}\n\n\t/** @borrows dragFiles as this.dragFiles */\n\tdragFiles: typeof dragFiles = dragFiles.bind( this );\n\t/** @borrows isCurrentURL as this.isCurrentURL */\n\tisCurrentURL: typeof isCurrentURL = isCurrentURL.bind( this );\n\t/** @borrows pressKeys as this.pressKeys */\n\tpressKeys: typeof pressKeys = pressKeys.bind( this );\n\t/** @borrows setBrowserViewport as this.setBrowserViewport */\n\tsetBrowserViewport: typeof setBrowserViewport =\n\t\tsetBrowserViewport.bind( this );\n\t/** @borrows setClipboardData as this.setClipboardData */\n\tsetClipboardData: typeof setClipboardData = setClipboardData.bind( this );\n\t/** @borrows emulateNetworkConditions as this.emulateNetworkConditions */\n\temulateNetworkConditions: typeof emulateNetworkConditions =\n\t\temulateNetworkConditions.bind( this );\n}\n\nexport { PageUtils };\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAaA,wBAA0B;AAC1B,4BAA6B;AAC7B,wBAA4C;AAC5C,kCAAmC;AACnC,wCAAyC;AAOzC,IAAM,YAAN,MAAgB;AAAA,EACf;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA,YAAa,EAAE,MAAM,YAAY,GAA+B;AAC/D,SAAK,OAAO;AACZ,SAAK,UAAU,KAAK,QAAQ;AAC5B,SAAK,UAAU,KAAK,QAAQ,QAAQ;AACpC,SAAK,cAAc;AAAA,EACpB;AAAA;AAAA,EAGA,YAA8B,4BAAU,KAAM,IAAK;AAAA;AAAA,EAEnD,eAAoC,mCAAa,KAAM,IAAK;AAAA;AAAA,EAE5D,YAA8B,4BAAU,KAAM,IAAK;AAAA;AAAA,EAEnD,qBACC,+CAAmB,KAAM,IAAK;AAAA;AAAA,EAE/B,mBAA4C,mCAAiB,KAAM,IAAK;AAAA;AAAA,EAExE,2BACC,2DAAyB,KAAM,IAAK;AACtC;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -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
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/page-utils/index.ts"],"names":[],"mappings":";;;AAUA;;GAEG;AACH,6CAAyC;AACzC,qDAAgD;AAChD,6CAA2D;AAC3D,iEAA4D;AAC5D,6EAAwE;AAOxE,MAAM,SAAS;IACd,OAAO,CAAU;IACjB,IAAI,CAAO;IACX,OAAO,CAAiB;IACxB,WAAW,CAA2C;IAEtD,YAAa,EAAE,IAAI,EAAE,WAAW,EAA6B;QAC5D,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC;QAC9B,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,EAAG,CAAC;QACvC,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;IAChC,CAAC;IAED,2CAA2C;IAC3C,SAAS,GAAqB,sBAAS,CAAC,IAAI,CAAE,IAAI,CAAE,CAAC;IACrD,iDAAiD;IACjD,YAAY,GAAwB,6BAAY,CAAC,IAAI,CAAE,IAAI,CAAE,CAAC;IAC9D,2CAA2C;IAC3C,SAAS,GAAqB,sBAAS,CAAC,IAAI,CAAE,IAAI,CAAE,CAAC;IACrD,6DAA6D;IAC7D,kBAAkB,GACjB,yCAAkB,CAAC,IAAI,CAAE,IAAI,CAAE,CAAC;IACjC,yDAAyD;IACzD,gBAAgB,GAA4B,6BAAgB,CAAC,IAAI,CAAE,IAAI,CAAE,CAAC;IAC1E,yEAAyE;IACzE,wBAAwB,GACvB,qDAAwB,CAAC,IAAI,CAAE,IAAI,CAAE,CAAC;CACvC;QAEQ,SAAS"}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// packages/e2e-test-utils-playwright/src/page-utils/is-current-url.ts
|
|
21
|
-
var is_current_url_exports = {};
|
|
22
|
-
__export(is_current_url_exports, {
|
|
23
|
-
isCurrentURL: () => isCurrentURL
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(is_current_url_exports);
|
|
26
|
-
var import_config = require("../config.cjs");
|
|
27
|
-
function isCurrentURL(path) {
|
|
28
|
-
const currentURL = new URL(this.page.url());
|
|
29
|
-
const expectedURL = new URL(path, import_config.WP_BASE_URL);
|
|
30
|
-
return expectedURL.pathname === currentURL.pathname;
|
|
31
|
-
}
|
|
32
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
33
|
-
0 && (module.exports = {
|
|
34
|
-
isCurrentURL
|
|
35
|
-
});
|
|
36
|
-
//# sourceMappingURL=is-current-url.cjs.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/page-utils/is-current-url.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport { WP_BASE_URL } from '../config';\nimport type { PageUtils } from './';\n\n/**\n * Checks if current path of the URL matches the provided path.\n *\n * @param this\n * @param path String to be serialized as pathname.\n *\n * @return Boolean represents whether current URL is or not a WordPress path.\n */\nexport function isCurrentURL( this: PageUtils, path: string ) {\n\tconst currentURL = new URL( this.page.url() );\n\tconst expectedURL = new URL( path, WP_BASE_URL );\n\n\treturn expectedURL.pathname === currentURL.pathname;\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,oBAA4B;AAWrB,SAAS,aAA+B,MAAe;AAC7D,QAAM,aAAa,IAAI,IAAK,KAAK,KAAK,IAAI,CAAE;AAC5C,QAAM,cAAc,IAAI,IAAK,MAAM,yBAAY;AAE/C,SAAO,YAAY,aAAa,WAAW;AAC5C;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|