@wordpress/e2e-test-utils-playwright 1.36.1-next.738bb1424.0 → 1.37.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/admin/create-new-post.js +48 -28
- package/build/admin/create-new-post.js.map +7 -1
- package/build/admin/edit-post.js +37 -17
- package/build/admin/edit-post.js.map +7 -1
- package/build/admin/get-page-error.js +33 -23
- package/build/admin/get-page-error.js.map +7 -1
- package/build/admin/index.js +58 -36
- package/build/admin/index.js.map +7 -1
- package/build/admin/visit-admin-page.js +44 -29
- package/build/admin/visit-admin-page.js.map +7 -1
- package/build/admin/visit-site-editor.js +73 -64
- package/build/admin/visit-site-editor.js.map +7 -1
- package/build/config.js +43 -11
- package/build/config.js.map +7 -1
- package/build/editor/click-block-options-menu-item.js +31 -14
- package/build/editor/click-block-options-menu-item.js.map +7 -1
- package/build/editor/click-block-toolbar-button.js +35 -13
- package/build/editor/click-block-toolbar-button.js.map +7 -1
- package/build/editor/get-blocks.js +61 -43
- package/build/editor/get-blocks.js.map +7 -1
- package/build/editor/get-edited-post-content.js +33 -12
- package/build/editor/get-edited-post-content.js.map +7 -1
- package/build/editor/index.js +96 -74
- package/build/editor/index.js.map +7 -1
- package/build/editor/insert-block.js +52 -21
- package/build/editor/insert-block.js.map +7 -1
- package/build/editor/open-document-settings-sidebar.js +39 -24
- package/build/editor/open-document-settings-sidebar.js.map +7 -1
- package/build/editor/preview.js +39 -18
- package/build/editor/preview.js.map +7 -1
- package/build/editor/publish-post.js +44 -42
- package/build/editor/publish-post.js.map +7 -1
- package/build/editor/save-draft.js +31 -15
- package/build/editor/save-draft.js.map +7 -1
- package/build/editor/select-blocks.js +48 -25
- package/build/editor/select-blocks.js.map +7 -1
- package/build/editor/set-content.js +36 -14
- package/build/editor/set-content.js.map +7 -1
- package/build/editor/set-is-fixed-toolbar.js +33 -15
- package/build/editor/set-is-fixed-toolbar.js.map +7 -1
- package/build/editor/set-preferences.js +40 -18
- package/build/editor/set-preferences.js.map +7 -1
- package/build/editor/show-block-toolbar.js +32 -16
- package/build/editor/show-block-toolbar.js.map +7 -1
- package/build/editor/site-editor.js +48 -41
- package/build/editor/site-editor.js.map +7 -1
- package/build/editor/switch-editor-tool.js +44 -30
- package/build/editor/switch-editor-tool.js.map +7 -1
- package/build/editor/switch-to-legacy-canvas.js +35 -14
- package/build/editor/switch-to-legacy-canvas.js.map +7 -1
- package/build/editor/transform-block-to.js +43 -21
- package/build/editor/transform-block-to.js.map +7 -1
- package/build/index.js +53 -18
- package/build/index.js.map +7 -1
- package/build/lighthouse/index.js +93 -55
- package/build/lighthouse/index.js.map +7 -1
- package/build/metrics/index.js +302 -251
- package/build/metrics/index.js.map +7 -1
- package/build/page-utils/drag-files.js +136 -112
- package/build/page-utils/drag-files.js.map +7 -1
- package/build/page-utils/emulate-network-conditions.js +95 -67
- package/build/page-utils/emulate-network-conditions.js.map +7 -1
- package/build/page-utils/index.js +58 -36
- package/build/page-utils/index.js.map +7 -1
- package/build/page-utils/is-current-url.js +33 -18
- package/build/page-utils/is-current-url.js.map +7 -1
- package/build/page-utils/keycodes.js +53 -39
- package/build/page-utils/keycodes.js.map +7 -1
- package/build/page-utils/press-keys.js +153 -130
- package/build/page-utils/press-keys.js.map +7 -1
- package/build/page-utils/set-browser-viewport.js +35 -42
- package/build/page-utils/set-browser-viewport.js.map +7 -1
- package/build/request-utils/blocks.js +51 -40
- package/build/request-utils/blocks.js.map +7 -1
- package/build/request-utils/comments.js +59 -45
- package/build/request-utils/comments.js.map +7 -1
- package/build/request-utils/gutenberg-experiments.js +63 -38
- package/build/request-utils/gutenberg-experiments.js.map +7 -1
- package/build/request-utils/index.js +191 -155
- package/build/request-utils/index.js.map +7 -1
- package/build/request-utils/login.js +45 -18
- package/build/request-utils/login.js.map +7 -1
- package/build/request-utils/media.js +74 -64
- package/build/request-utils/media.js.map +7 -1
- package/build/request-utils/menus.js +121 -109
- package/build/request-utils/menus.js.map +7 -1
- package/build/request-utils/pages.js +63 -50
- package/build/request-utils/pages.js.map +7 -1
- package/build/request-utils/patterns.js +41 -24
- package/build/request-utils/patterns.js.map +7 -1
- package/build/request-utils/plugins.js +70 -74
- package/build/request-utils/plugins.js.map +7 -1
- package/build/request-utils/posts.js +55 -41
- package/build/request-utils/posts.js.map +7 -1
- package/build/request-utils/preferences.js +38 -17
- package/build/request-utils/preferences.js.map +7 -1
- package/build/request-utils/rest.js +155 -129
- package/build/request-utils/rest.js.map +7 -1
- package/build/request-utils/site-settings.js +40 -28
- package/build/request-utils/site-settings.js.map +7 -1
- package/build/request-utils/templates.js +60 -46
- package/build/request-utils/templates.js.map +7 -1
- package/build/request-utils/themes.js +80 -53
- package/build/request-utils/themes.js.map +7 -1
- package/build/request-utils/users.js +74 -72
- package/build/request-utils/users.js.map +7 -1
- package/build/request-utils/widgets.js +73 -55
- package/build/request-utils/widgets.js.map +7 -1
- package/build/test.js +130 -146
- package/build/test.js.map +7 -1
- package/build/types.js +18 -2
- package/build/types.js.map +7 -1
- package/build-types/index.d.ts +1 -1
- package/build-types/index.d.ts.map +1 -1
- package/package.json +2 -2
- package/build/admin/create-new-post.cjs +0 -51
- package/build/admin/create-new-post.cjs.map +0 -7
- package/build/admin/edit-post.cjs +0 -40
- package/build/admin/edit-post.cjs.map +0 -7
- package/build/admin/get-page-error.cjs +0 -36
- package/build/admin/get-page-error.cjs.map +0 -7
- package/build/admin/index.cjs +0 -59
- package/build/admin/index.cjs.map +0 -7
- package/build/admin/visit-admin-page.cjs +0 -47
- package/build/admin/visit-admin-page.cjs.map +0 -7
- package/build/admin/visit-site-editor.cjs +0 -77
- package/build/admin/visit-site-editor.cjs.map +0 -7
- package/build/config.cjs +0 -45
- package/build/config.cjs.map +0 -7
- 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-toolbar-button.cjs +0 -38
- package/build/editor/click-block-toolbar-button.cjs.map +0 -7
- package/build/editor/get-blocks.cjs +0 -64
- package/build/editor/get-blocks.cjs.map +0 -7
- package/build/editor/get-edited-post-content.cjs +0 -36
- package/build/editor/get-edited-post-content.cjs.map +0 -7
- package/build/editor/index.cjs +0 -97
- package/build/editor/index.cjs.map +0 -7
- package/build/editor/insert-block.cjs +0 -55
- package/build/editor/insert-block.cjs.map +0 -7
- package/build/editor/open-document-settings-sidebar.cjs +0 -42
- package/build/editor/open-document-settings-sidebar.cjs.map +0 -7
- package/build/editor/preview.cjs +0 -42
- package/build/editor/preview.cjs.map +0 -7
- package/build/editor/publish-post.cjs +0 -47
- package/build/editor/publish-post.cjs.map +0 -7
- package/build/editor/save-draft.cjs +0 -34
- package/build/editor/save-draft.cjs.map +0 -7
- package/build/editor/select-blocks.cjs +0 -51
- package/build/editor/select-blocks.cjs.map +0 -7
- package/build/editor/set-content.cjs +0 -39
- package/build/editor/set-content.cjs.map +0 -7
- 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-preferences.cjs +0 -43
- package/build/editor/set-preferences.cjs.map +0 -7
- package/build/editor/show-block-toolbar.cjs +0 -35
- package/build/editor/show-block-toolbar.cjs.map +0 -7
- package/build/editor/site-editor.cjs +0 -51
- package/build/editor/site-editor.cjs.map +0 -7
- package/build/editor/switch-editor-tool.cjs +0 -47
- package/build/editor/switch-editor-tool.cjs.map +0 -7
- package/build/editor/switch-to-legacy-canvas.cjs +0 -39
- package/build/editor/switch-to-legacy-canvas.cjs.map +0 -7
- package/build/editor/transform-block-to.cjs +0 -46
- package/build/editor/transform-block-to.cjs.map +0 -7
- package/build/index.cjs +0 -51
- package/build/index.cjs.map +0 -7
- package/build/lighthouse/index.cjs +0 -96
- package/build/lighthouse/index.cjs.map +0 -7
- package/build/metrics/index.cjs +0 -309
- package/build/metrics/index.cjs.map +0 -7
- package/build/page-utils/drag-files.cjs +0 -143
- package/build/page-utils/drag-files.cjs.map +0 -7
- 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/index.cjs +0 -59
- package/build/page-utils/index.cjs.map +0 -7
- 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/keycodes.cjs +0 -55
- package/build/page-utils/keycodes.cjs.map +0 -7
- package/build/page-utils/press-keys.cjs +0 -165
- package/build/page-utils/press-keys.cjs.map +0 -7
- package/build/page-utils/set-browser-viewport.cjs +0 -39
- package/build/page-utils/set-browser-viewport.cjs.map +0 -7
- package/build/request-utils/blocks.cjs +0 -56
- package/build/request-utils/blocks.cjs.map +0 -7
- package/build/request-utils/comments.cjs +0 -66
- package/build/request-utils/comments.cjs.map +0 -7
- package/build/request-utils/gutenberg-experiments.cjs +0 -66
- package/build/request-utils/gutenberg-experiments.cjs.map +0 -7
- package/build/request-utils/index.cjs +0 -194
- package/build/request-utils/index.cjs.map +0 -7
- package/build/request-utils/login.cjs +0 -48
- package/build/request-utils/login.cjs.map +0 -7
- package/build/request-utils/media.cjs +0 -83
- package/build/request-utils/media.cjs.map +0 -7
- package/build/request-utils/menus.cjs +0 -132
- package/build/request-utils/menus.cjs.map +0 -7
- package/build/request-utils/pages.cjs +0 -71
- package/build/request-utils/pages.cjs.map +0 -7
- package/build/request-utils/patterns.cjs +0 -44
- package/build/request-utils/patterns.cjs.map +0 -7
- package/build/request-utils/plugins.cjs +0 -81
- package/build/request-utils/plugins.cjs.map +0 -7
- package/build/request-utils/posts.cjs +0 -61
- package/build/request-utils/posts.cjs.map +0 -7
- package/build/request-utils/preferences.cjs +0 -41
- package/build/request-utils/preferences.cjs.map +0 -7
- package/build/request-utils/rest.cjs +0 -174
- package/build/request-utils/rest.cjs.map +0 -7
- package/build/request-utils/site-settings.cjs +0 -45
- package/build/request-utils/site-settings.cjs.map +0 -7
- package/build/request-utils/templates.cjs +0 -68
- package/build/request-utils/templates.cjs.map +0 -7
- package/build/request-utils/themes.cjs +0 -89
- package/build/request-utils/themes.cjs.map +0 -7
- package/build/request-utils/users.cjs +0 -83
- package/build/request-utils/users.cjs.map +0 -7
- package/build/request-utils/widgets.cjs +0 -79
- package/build/request-utils/widgets.cjs.map +0 -7
- package/build/test.cjs +0 -136
- package/build/test.cjs.map +0 -7
- package/build/types.cjs +0 -19
- package/build/types.cjs.map +0 -7
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
// packages/e2e-test-utils-playwright/src/request-utils/rest.ts
|
|
31
|
-
var rest_exports = {};
|
|
32
|
-
__export(rest_exports, {
|
|
33
|
-
batchRest: () => batchRest,
|
|
34
|
-
getMaxBatchSize: () => getMaxBatchSize,
|
|
35
|
-
rest: () => rest,
|
|
36
|
-
setupRest: () => setupRest
|
|
37
|
-
});
|
|
38
|
-
module.exports = __toCommonJS(rest_exports);
|
|
39
|
-
var fs = __toESM(require("fs/promises"));
|
|
40
|
-
var import_path = require("path");
|
|
41
|
-
var import_test = require("@playwright/test");
|
|
42
|
-
var import_config = require("../config.cjs");
|
|
43
|
-
function splitRequestsToChunks(requests, chunkSize) {
|
|
44
|
-
const arr = [...requests];
|
|
45
|
-
const cache = [];
|
|
46
|
-
while (arr.length) {
|
|
47
|
-
cache.push(arr.splice(0, chunkSize));
|
|
48
|
-
}
|
|
49
|
-
return cache;
|
|
50
|
-
}
|
|
51
|
-
async function getAPIRootURL(request) {
|
|
52
|
-
const response = await request.head(import_config.WP_BASE_URL);
|
|
53
|
-
const links = response.headers().link;
|
|
54
|
-
const restLink = links?.match(/<([^>]+)>; rel="https:\/\/api\.w\.org\/"/);
|
|
55
|
-
if (!restLink) {
|
|
56
|
-
throw new Error(`Failed to discover REST API endpoint.
|
|
57
|
-
Link header: ${links}`);
|
|
58
|
-
}
|
|
59
|
-
const [, rootURL] = restLink;
|
|
60
|
-
return rootURL;
|
|
61
|
-
}
|
|
62
|
-
async function setupRest() {
|
|
63
|
-
let nonce = "";
|
|
64
|
-
let rootURL = "";
|
|
65
|
-
await import_test.expect.poll(
|
|
66
|
-
async () => {
|
|
67
|
-
try {
|
|
68
|
-
[nonce, rootURL] = await Promise.all([
|
|
69
|
-
this.login(),
|
|
70
|
-
getAPIRootURL(this.request)
|
|
71
|
-
]);
|
|
72
|
-
} catch (error) {
|
|
73
|
-
return error;
|
|
74
|
-
}
|
|
75
|
-
return !!(nonce && rootURL);
|
|
76
|
-
},
|
|
77
|
-
{
|
|
78
|
-
message: "Failed to setup REST API.",
|
|
79
|
-
timeout: 6e4
|
|
80
|
-
// 1 minute.
|
|
81
|
-
}
|
|
82
|
-
).toBe(true);
|
|
83
|
-
const { cookies } = await this.request.storageState();
|
|
84
|
-
const storageState = {
|
|
85
|
-
cookies,
|
|
86
|
-
nonce,
|
|
87
|
-
rootURL
|
|
88
|
-
};
|
|
89
|
-
if (this.storageStatePath) {
|
|
90
|
-
await fs.mkdir((0, import_path.dirname)(this.storageStatePath), { recursive: true });
|
|
91
|
-
await fs.writeFile(
|
|
92
|
-
this.storageStatePath,
|
|
93
|
-
JSON.stringify(storageState),
|
|
94
|
-
"utf-8"
|
|
95
|
-
);
|
|
96
|
-
}
|
|
97
|
-
this.storageState = storageState;
|
|
98
|
-
return storageState;
|
|
99
|
-
}
|
|
100
|
-
async function rest(options) {
|
|
101
|
-
const { path, ...fetchOptions } = options;
|
|
102
|
-
if (!path) {
|
|
103
|
-
throw new Error('"path" is required to make a REST call');
|
|
104
|
-
}
|
|
105
|
-
if (!this.storageState?.nonce || !this.storageState?.rootURL) {
|
|
106
|
-
await this.setupRest();
|
|
107
|
-
}
|
|
108
|
-
const relativePath = path.startsWith("/") ? path.slice(1) : path;
|
|
109
|
-
const url = this.storageState.rootURL + relativePath;
|
|
110
|
-
try {
|
|
111
|
-
const response = await this.request.fetch(url, {
|
|
112
|
-
...fetchOptions,
|
|
113
|
-
failOnStatusCode: false,
|
|
114
|
-
headers: {
|
|
115
|
-
"X-WP-Nonce": this.storageState.nonce,
|
|
116
|
-
...fetchOptions.headers || {}
|
|
117
|
-
}
|
|
118
|
-
});
|
|
119
|
-
const json = await response.json();
|
|
120
|
-
if (!response.ok()) {
|
|
121
|
-
throw json;
|
|
122
|
-
}
|
|
123
|
-
return json;
|
|
124
|
-
} catch (error) {
|
|
125
|
-
if (typeof error === "object" && error !== null && Object.prototype.hasOwnProperty.call(error, "code") && error.code === "rest_cookie_invalid_nonce") {
|
|
126
|
-
await this.setupRest();
|
|
127
|
-
return this.rest(options);
|
|
128
|
-
}
|
|
129
|
-
throw error;
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
async function getMaxBatchSize(forceRefetch = false) {
|
|
133
|
-
if (!forceRefetch && this.maxBatchSize) {
|
|
134
|
-
return this.maxBatchSize;
|
|
135
|
-
}
|
|
136
|
-
const response = await this.rest({
|
|
137
|
-
method: "OPTIONS",
|
|
138
|
-
path: "/batch/v1"
|
|
139
|
-
});
|
|
140
|
-
this.maxBatchSize = response.endpoints[0].args.requests.maxItems;
|
|
141
|
-
return this.maxBatchSize;
|
|
142
|
-
}
|
|
143
|
-
async function batchRest(requests) {
|
|
144
|
-
const maxBatchSize = await this.getMaxBatchSize();
|
|
145
|
-
if (requests.length > maxBatchSize) {
|
|
146
|
-
const chunks = splitRequestsToChunks(requests, maxBatchSize);
|
|
147
|
-
const chunkResponses = await Promise.all(
|
|
148
|
-
chunks.map(
|
|
149
|
-
(chunkRequests) => this.batchRest(chunkRequests)
|
|
150
|
-
)
|
|
151
|
-
);
|
|
152
|
-
return chunkResponses.flat();
|
|
153
|
-
}
|
|
154
|
-
const batchResponses = await this.rest({
|
|
155
|
-
method: "POST",
|
|
156
|
-
path: "/batch/v1",
|
|
157
|
-
data: {
|
|
158
|
-
requests,
|
|
159
|
-
validation: "require-all-validate"
|
|
160
|
-
}
|
|
161
|
-
});
|
|
162
|
-
if (batchResponses.failed) {
|
|
163
|
-
throw batchResponses;
|
|
164
|
-
}
|
|
165
|
-
return batchResponses.responses;
|
|
166
|
-
}
|
|
167
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
168
|
-
0 && (module.exports = {
|
|
169
|
-
batchRest,
|
|
170
|
-
getMaxBatchSize,
|
|
171
|
-
rest,
|
|
172
|
-
setupRest
|
|
173
|
-
});
|
|
174
|
-
//# sourceMappingURL=rest.cjs.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/request-utils/rest.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\nimport * as fs from 'fs/promises';\nimport { dirname } from 'path';\nimport { expect } from '@playwright/test';\nimport type { APIRequestContext } from '@playwright/test';\n\n/**\n * Internal dependencies\n */\nimport { WP_BASE_URL } from '../config';\nimport type { RequestUtils, StorageState } from './index';\n\nfunction splitRequestsToChunks( requests: BatchRequest[], chunkSize: number ) {\n\tconst arr = [ ...requests ];\n\tconst cache = [];\n\twhile ( arr.length ) {\n\t\tcache.push( arr.splice( 0, chunkSize ) );\n\t}\n\n\treturn cache;\n}\n\nasync function getAPIRootURL( request: APIRequestContext ) {\n\t// Discover the API root url using link header.\n\t// See https://developer.wordpress.org/rest-api/using-the-rest-api/discovery/#link-header\n\tconst response = await request.head( WP_BASE_URL );\n\tconst links = response.headers().link;\n\tconst restLink = links?.match( /<([^>]+)>; rel=\"https:\\/\\/api\\.w\\.org\\/\"/ );\n\n\tif ( ! restLink ) {\n\t\tthrow new Error( `Failed to discover REST API endpoint.\n Link header: ${ links }` );\n\t}\n\n\tconst [ , rootURL ] = restLink;\n\n\treturn rootURL;\n}\n\nasync function setupRest( this: RequestUtils ): Promise< StorageState > {\n\tlet nonce = '';\n\tlet rootURL = '';\n\n\t// Poll until the REST API is discovered.\n\t// See https://github.com/WordPress/gutenberg/issues/61627\n\tawait expect\n\t\t.poll(\n\t\t\tasync () => {\n\t\t\t\ttry {\n\t\t\t\t\t[ nonce, rootURL ] = await Promise.all( [\n\t\t\t\t\t\tthis.login(),\n\t\t\t\t\t\tgetAPIRootURL( this.request ),\n\t\t\t\t\t] );\n\t\t\t\t} catch ( error ) {\n\t\t\t\t\t// Prints the error if the timeout is reached.\n\t\t\t\t\treturn error;\n\t\t\t\t}\n\n\t\t\t\treturn !! ( nonce && rootURL );\n\t\t\t},\n\t\t\t{\n\t\t\t\tmessage: 'Failed to setup REST API.',\n\t\t\t\ttimeout: 60_000, // 1 minute.\n\t\t\t}\n\t\t)\n\t\t.toBe( true );\n\n\tconst { cookies } = await this.request.storageState();\n\n\tconst storageState: StorageState = {\n\t\tcookies,\n\t\tnonce,\n\t\trootURL,\n\t};\n\n\tif ( this.storageStatePath ) {\n\t\tawait fs.mkdir( dirname( this.storageStatePath ), { recursive: true } );\n\t\tawait fs.writeFile(\n\t\t\tthis.storageStatePath,\n\t\t\tJSON.stringify( storageState ),\n\t\t\t'utf-8'\n\t\t);\n\t}\n\n\tthis.storageState = storageState;\n\n\treturn storageState;\n}\n\ntype RequestFetchOptions = Exclude<\n\tParameters< APIRequestContext[ 'fetch' ] >[ 1 ],\n\tundefined\n>;\nexport interface RestOptions extends RequestFetchOptions {\n\tpath: string;\n}\n\nasync function rest< RestResponse = any >(\n\tthis: RequestUtils,\n\toptions: RestOptions\n): Promise< RestResponse > {\n\tconst { path, ...fetchOptions } = options;\n\n\tif ( ! path ) {\n\t\tthrow new Error( '\"path\" is required to make a REST call' );\n\t}\n\n\tif ( ! this.storageState?.nonce || ! this.storageState?.rootURL ) {\n\t\tawait this.setupRest();\n\t}\n\n\tconst relativePath = path.startsWith( '/' ) ? path.slice( 1 ) : path;\n\n\tconst url = this.storageState!.rootURL + relativePath;\n\n\ttry {\n\t\tconst response = await this.request.fetch( url, {\n\t\t\t...fetchOptions,\n\t\t\tfailOnStatusCode: false,\n\t\t\theaders: {\n\t\t\t\t'X-WP-Nonce': this.storageState!.nonce,\n\t\t\t\t...( fetchOptions.headers || {} ),\n\t\t\t},\n\t\t} );\n\t\tconst json: RestResponse = await response.json();\n\n\t\tif ( ! response.ok() ) {\n\t\t\tthrow json;\n\t\t}\n\n\t\treturn json;\n\t} catch ( error ) {\n\t\t// Nonce in invalid, retry again with a renewed nonce.\n\t\tif (\n\t\t\ttypeof error === 'object' &&\n\t\t\terror !== null &&\n\t\t\tObject.prototype.hasOwnProperty.call( error, 'code' ) &&\n\t\t\t( error as { code: string } ).code === 'rest_cookie_invalid_nonce'\n\t\t) {\n\t\t\tawait this.setupRest();\n\n\t\t\treturn this.rest( options );\n\t\t}\n\n\t\tthrow error;\n\t}\n}\n\n/**\n * Get the maximum batch size for the REST API.\n *\n * @param this\n * @param forceRefetch Force revalidate the cached max batch size.\n */\nasync function getMaxBatchSize( this: RequestUtils, forceRefetch = false ) {\n\tif ( ! forceRefetch && this.maxBatchSize ) {\n\t\treturn this.maxBatchSize;\n\t}\n\n\tconst response = await this.rest< {\n\t\tendpoints: {\n\t\t\targs: {\n\t\t\t\trequests: {\n\t\t\t\t\tmaxItems: number;\n\t\t\t\t};\n\t\t\t};\n\t\t}[];\n\t} >( {\n\t\tmethod: 'OPTIONS',\n\t\tpath: '/batch/v1',\n\t} );\n\tthis.maxBatchSize = response.endpoints[ 0 ].args.requests.maxItems;\n\treturn this.maxBatchSize;\n}\n\nexport interface BatchRequest {\n\tmethod?: string;\n\tpath: string;\n\theaders?: Record< string, string | string[] >;\n\tbody?: any;\n}\n\nasync function batchRest< BatchResponse >(\n\tthis: RequestUtils,\n\trequests: BatchRequest[]\n): Promise< BatchResponse[] > {\n\tconst maxBatchSize = await this.getMaxBatchSize();\n\n\tif ( requests.length > maxBatchSize ) {\n\t\tconst chunks = splitRequestsToChunks( requests, maxBatchSize );\n\n\t\tconst chunkResponses = await Promise.all(\n\t\t\tchunks.map( ( chunkRequests ) =>\n\t\t\t\tthis.batchRest< BatchResponse >( chunkRequests )\n\t\t\t)\n\t\t);\n\n\t\treturn chunkResponses.flat();\n\t}\n\n\tconst batchResponses = await this.rest< {\n\t\tfailed?: string;\n\t\tresponses: BatchResponse[];\n\t} >( {\n\t\tmethod: 'POST',\n\t\tpath: '/batch/v1',\n\t\tdata: {\n\t\t\trequests,\n\t\t\tvalidation: 'require-all-validate',\n\t\t},\n\t} );\n\n\tif ( batchResponses.failed ) {\n\t\tthrow batchResponses;\n\t}\n\n\treturn batchResponses.responses;\n}\n\nexport { setupRest, r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QAAQ;AAAA,IACR,MAAM;AAAA,EACP,CAAE;AACF,OAAK,eAAe,SAAS,UAAW,CAAE,EAAE,KAAK,SAAS;AAC1D,SAAO,KAAK;AACb;AASA,eAAe,UAEd,UAC6B;AAC7B,QAAM,eAAe,MAAM,KAAK,gBAAgB;AAEhD,MAAK,SAAS,SAAS,cAAe;AACrC,UAAM,SAAS,sBAAuB,UAAU,YAAa;AAE7D,UAAM,iBAAiB,MAAM,QAAQ;AAAA,MACpC,OAAO;AAAA,QAAK,CAAE,kBACb,KAAK,UAA4B,aAAc;AAAA,MAChD;AAAA,IACD;AAEA,WAAO,eAAe,KAAK;AAAA,EAC5B;AAEA,QAAM,iBAAiB,MAAM,KAAK,KAG7B;AAAA,IACJ,QAAQ;AAAA,IACR,MAAM;AAAA,IACN,MAAM;AAAA,MACL;AAAA,MACA,YAAY;AAAA,IACb;AAAA,EACD,CAAE;AAEF,MAAK,eAAe,QAAS;AAC5B,UAAM;AAAA,EACP;AAEA,SAAO,eAAe;AACvB;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,45 +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/request-utils/site-settings.ts
|
|
21
|
-
var site_settings_exports = {};
|
|
22
|
-
__export(site_settings_exports, {
|
|
23
|
-
getSiteSettings: () => getSiteSettings,
|
|
24
|
-
updateSiteSettings: () => updateSiteSettings
|
|
25
|
-
});
|
|
26
|
-
module.exports = __toCommonJS(site_settings_exports);
|
|
27
|
-
async function getSiteSettings() {
|
|
28
|
-
return await this.rest({
|
|
29
|
-
path: "/wp/v2/settings",
|
|
30
|
-
method: "GET"
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
async function updateSiteSettings(siteSettings) {
|
|
34
|
-
return await this.rest({
|
|
35
|
-
path: "/wp/v2/settings",
|
|
36
|
-
method: "POST",
|
|
37
|
-
data: siteSettings
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
41
|
-
0 && (module.exports = {
|
|
42
|
-
getSiteSettings,
|
|
43
|
-
updateSiteSettings
|
|
44
|
-
});
|
|
45
|
-
//# sourceMappingURL=site-settings.cjs.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/request-utils/site-settings.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { RequestUtils } from './index';\n\ntype SiteSettings = {\n\ttitle: string;\n\tdescription: string;\n\turl: string;\n\temail: string;\n\ttimezone: string;\n\tdate_format: string;\n\ttime_format: string;\n\tstart_of_week: number;\n\tlanguage: string;\n\tuse_smilies: boolean;\n\tdefault_category: number;\n\tdefault_post_format: string;\n\tposts_per_page: number;\n\tdefault_ping_status: 'open' | 'closed';\n\tdefault_comment_status: 'open' | 'closed';\n\tshow_on_front: 'posts' | 'page';\n\tpage_on_front: number;\n\tpage_for_posts: number;\n};\n\n/**\n * Get the site settings.\n *\n * @see https://developer.wordpress.org/rest-api/reference/settings/#retrieve-a-site-setting\n *\n * @param this RequestUtils.\n */\nexport async function getSiteSettings( this: RequestUtils ) {\n\treturn await this.rest< SiteSettings >( {\n\t\tpath: '/wp/v2/settings',\n\t\tmethod: 'GET',\n\t} );\n}\n\n/**\n * Update the site settings.\n *\n * @see https://developer.wordpress.org/rest-api/reference/settings/#update-a-site-setting\n *\n * @param this RequestUtils.\n * @param siteSettings The partial settings payload to update.\n */\nexport async function updateSiteSettings(\n\tthis: RequestUtils,\n\tsiteSettings: Partial< SiteSettings >\n) {\n\treturn await this.rest< SiteSettings >( {\n\t\tpath: '/wp/v2/settings',\n\t\tmethod: 'POST',\n\t\tdata: siteSettings,\n\t} );\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAiCA,eAAsB,kBAAsC;AAC3D,SAAO,MAAM,KAAK,KAAsB;AAAA,IACvC,MAAM;AAAA,IACN,QAAQ;AAAA,EACT,CAAE;AACH;AAUA,eAAsB,mBAErB,cACC;AACD,SAAO,MAAM,KAAK,KAAsB;AAAA,IACvC,MAAM;AAAA,IACN,QAAQ;AAAA,IACR,MAAM;AAAA,EACP,CAAE;AACH;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,68 +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/request-utils/templates.ts
|
|
21
|
-
var templates_exports = {};
|
|
22
|
-
__export(templates_exports, {
|
|
23
|
-
createTemplate: () => createTemplate,
|
|
24
|
-
deleteAllTemplates: () => deleteAllTemplates
|
|
25
|
-
});
|
|
26
|
-
module.exports = __toCommonJS(templates_exports);
|
|
27
|
-
var PATH_MAPPING = {
|
|
28
|
-
wp_template: "/wp/v2/templates",
|
|
29
|
-
wp_template_part: "/wp/v2/template-parts"
|
|
30
|
-
};
|
|
31
|
-
async function deleteAllTemplates(type) {
|
|
32
|
-
const path = PATH_MAPPING[type];
|
|
33
|
-
if (!path) {
|
|
34
|
-
throw new Error(`Unsupported template type: ${type}.`);
|
|
35
|
-
}
|
|
36
|
-
const templates = await this.rest({ path });
|
|
37
|
-
for (const template of templates) {
|
|
38
|
-
if (!template?.id || !template?.wp_id) {
|
|
39
|
-
continue;
|
|
40
|
-
}
|
|
41
|
-
try {
|
|
42
|
-
await this.rest({
|
|
43
|
-
method: "DELETE",
|
|
44
|
-
path: `${path}/${template.id}`,
|
|
45
|
-
params: { force: true }
|
|
46
|
-
});
|
|
47
|
-
} catch (responseError) {
|
|
48
|
-
console.warn(
|
|
49
|
-
`deleteAllTemplates failed to delete template (id: ${template.wp_id}) with the following error`,
|
|
50
|
-
responseError
|
|
51
|
-
);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
async function createTemplate(type, payload) {
|
|
56
|
-
const template = await this.rest({
|
|
57
|
-
method: "POST",
|
|
58
|
-
path: PATH_MAPPING[type],
|
|
59
|
-
params: { ...payload, type, status: "publish", is_wp_suggestion: true }
|
|
60
|
-
});
|
|
61
|
-
return template;
|
|
62
|
-
}
|
|
63
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
64
|
-
0 && (module.exports = {
|
|
65
|
-
createTemplate,
|
|
66
|
-
deleteAllTemplates
|
|
67
|
-
});
|
|
68
|
-
//# sourceMappingURL=templates.cjs.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/request-utils/templates.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { RequestUtils } from './index';\n\ntype TemplateType = 'wp_template' | 'wp_template_part';\n\ninterface Template {\n\twp_id: number;\n\tid: string;\n}\n\ninterface CreateTemplatePayload {\n\tslug: string;\n\ttitle?: string;\n\tcontent?: string;\n\tdescription?: string;\n}\n\nconst PATH_MAPPING = {\n\twp_template: '/wp/v2/templates',\n\twp_template_part: '/wp/v2/template-parts',\n};\n\n/**\n * Delete all the templates of given type.\n *\n * @param this\n * @param type - Template type to delete.\n */\nasync function deleteAllTemplates( this: RequestUtils, type: TemplateType ) {\n\tconst path = PATH_MAPPING[ type ];\n\n\tif ( ! path ) {\n\t\tthrow new Error( `Unsupported template type: ${ type }.` );\n\t}\n\n\tconst templates = await this.rest< Template[] >( { path } );\n\n\tfor ( const template of templates ) {\n\t\tif ( ! template?.id || ! template?.wp_id ) {\n\t\t\tcontinue;\n\t\t}\n\n\t\ttry {\n\t\t\tawait this.rest( {\n\t\t\t\tmethod: 'DELETE',\n\t\t\t\tpath: `${ path }/${ template.id }`,\n\t\t\t\tparams: { force: true },\n\t\t\t} );\n\t\t} catch ( responseError ) {\n\t\t\t// Disable reason - the error provides valuable feedback about issues with tests.\n\t\t\t// eslint-disable-next-line no-console\n\t\t\tconsole.warn(\n\t\t\t\t`deleteAllTemplates failed to delete template (id: ${ template.wp_id }) with the following error`,\n\t\t\t\tresponseError\n\t\t\t);\n\t\t}\n\t}\n}\n\n/**\n * Creates a new template using the REST API.\n *\n * @param this\n * @param type Template type to delete.\n * @param payload Template attributes.\n */\nasync function createTemplate(\n\tthis: RequestUtils,\n\ttype: TemplateType,\n\tpayload: CreateTemplatePayload\n) {\n\tconst template = await this.rest< Template >( {\n\t\tmethod: 'POST',\n\t\tpath: PATH_MAPPING[ type ],\n\t\tparams: { ...payload, type, status: 'publish', is_wp_suggestion: true },\n\t} );\n\n\treturn template;\n}\n\nexport { deleteAllTemplates, createTemplate };\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAmBA,IAAM,eAAe;AAAA,EACpB,aAAa;AAAA,EACb,kBAAkB;AACnB;AAQA,eAAe,mBAAwC,MAAqB;AAC3E,QAAM,OAAO,aAAc,IAAK;AAEhC,MAAK,CAAE,MAAO;AACb,UAAM,IAAI,MAAO,8BAA+B,IAAK,GAAI;AAAA,EAC1D;AAEA,QAAM,YAAY,MAAM,KAAK,KAAoB,EAAE,KAAK,CAAE;AAE1D,aAAY,YAAY,WAAY;AACnC,QAAK,CAAE,UAAU,MAAM,CAAE,UAAU,OAAQ;AAC1C;AAAA,IACD;AAEA,QAAI;AACH,YAAM,KAAK,KAAM;AAAA,QAChB,QAAQ;AAAA,QACR,MAAM,GAAI,IAAK,IAAK,SAAS,EAAG;AAAA,QAChC,QAAQ,EAAE,OAAO,KAAK;AAAA,MACvB,CAAE;AAAA,IACH,SAAU,eAAgB;AAGzB,cAAQ;AAAA,QACP,qDAAsD,SAAS,KAAM;AAAA,QACrE;AAAA,MACD;AAAA,IACD;AAAA,EACD;AACD;AASA,eAAe,eAEd,MACA,SACC;AACD,QAAM,WAAW,MAAM,KAAK,KAAkB;AAAA,IAC7C,QAAQ;AAAA,IACR,MAAM,aAAc,IAAK;AAAA,IACzB,QAAQ,EAAE,GAAG,SAAS,MAAM,QAAQ,WAAW,kBAAkB,KAAK;AAAA,EACvE,CAAE;AAEF,SAAO;AACR;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,89 +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/request-utils/themes.ts
|
|
21
|
-
var themes_exports = {};
|
|
22
|
-
__export(themes_exports, {
|
|
23
|
-
activateTheme: () => activateTheme,
|
|
24
|
-
getCurrentThemeGlobalStylesPostId: () => getCurrentThemeGlobalStylesPostId,
|
|
25
|
-
getThemeGlobalStylesRevisions: () => getThemeGlobalStylesRevisions
|
|
26
|
-
});
|
|
27
|
-
module.exports = __toCommonJS(themes_exports);
|
|
28
|
-
var import_config = require("../config.cjs");
|
|
29
|
-
var THEMES_URL = new URL("wp-admin/themes.php", import_config.WP_BASE_URL).href;
|
|
30
|
-
async function activateTheme(themeSlug) {
|
|
31
|
-
let response = await this.request.get(THEMES_URL);
|
|
32
|
-
const html = await response.text();
|
|
33
|
-
const optionalFolder = "([a-z0-9-]+%2F)?";
|
|
34
|
-
let matchGroup = html.match(
|
|
35
|
-
`action=activate&stylesheet=${encodeURIComponent(
|
|
36
|
-
themeSlug
|
|
37
|
-
)}&_wpnonce=[a-z0-9]+`
|
|
38
|
-
);
|
|
39
|
-
if (!matchGroup) {
|
|
40
|
-
matchGroup = html.match(
|
|
41
|
-
`action=activate&stylesheet=${optionalFolder}${encodeURIComponent(
|
|
42
|
-
themeSlug
|
|
43
|
-
)}&_wpnonce=[a-z0-9]+`
|
|
44
|
-
);
|
|
45
|
-
}
|
|
46
|
-
if (!matchGroup) {
|
|
47
|
-
if (html.includes(`data-slug="${themeSlug}"`)) {
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
throw new Error(`The theme "${themeSlug}" is not installed`);
|
|
51
|
-
}
|
|
52
|
-
const [activateQuery] = matchGroup;
|
|
53
|
-
const activateLink = THEMES_URL + `?${activateQuery}`.replace(/&/g, "&");
|
|
54
|
-
response = await this.request.get(activateLink);
|
|
55
|
-
await response.dispose();
|
|
56
|
-
}
|
|
57
|
-
async function getCurrentThemeGlobalStylesPostId() {
|
|
58
|
-
const themes = await this.rest({
|
|
59
|
-
path: "/wp/v2/themes"
|
|
60
|
-
});
|
|
61
|
-
let themeGlobalStylesId = "";
|
|
62
|
-
if (themes && themes.length) {
|
|
63
|
-
const currentTheme = themes.find(
|
|
64
|
-
({ status }) => status === "active"
|
|
65
|
-
);
|
|
66
|
-
const globalStylesURL = currentTheme?._links?.["wp:user-global-styles"]?.[0]?.href;
|
|
67
|
-
if (globalStylesURL) {
|
|
68
|
-
themeGlobalStylesId = globalStylesURL?.split(
|
|
69
|
-
"rest_route=/wp/v2/global-styles/"
|
|
70
|
-
)[1];
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
return themeGlobalStylesId;
|
|
74
|
-
}
|
|
75
|
-
async function getThemeGlobalStylesRevisions(parentId) {
|
|
76
|
-
return await this.rest({
|
|
77
|
-
path: `/wp/v2/global-styles/${parentId}/revisions`,
|
|
78
|
-
params: {
|
|
79
|
-
per_page: 100
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
84
|
-
0 && (module.exports = {
|
|
85
|
-
activateTheme,
|
|
86
|
-
getCurrentThemeGlobalStylesPostId,
|
|
87
|
-
getThemeGlobalStylesRevisions
|
|
88
|
-
});
|
|
89
|
-
//# sourceMappingURL=themes.cjs.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/request-utils/themes.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { RequestUtils } from './index';\nimport { WP_BASE_URL } from '../config';\n\nconst THEMES_URL = new URL( 'wp-admin/themes.php', WP_BASE_URL ).href;\n\nasync function activateTheme(\n\tthis: RequestUtils,\n\tthemeSlug: string\n): Promise< void > {\n\tlet response = await this.request.get( THEMES_URL );\n\tconst html = await response.text();\n\tconst optionalFolder = '([a-z0-9-]+%2F)?';\n\n\t// The `optionalFolder` regex part matches paths with a folder,\n\t// so it will return the first match, which might contain a folder.\n\t// First try to honor the included theme slug, that is, without a folder.\n\tlet matchGroup = html.match(\n\t\t`action=activate&stylesheet=${ encodeURIComponent(\n\t\t\tthemeSlug\n\t\t) }&_wpnonce=[a-z0-9]+`\n\t);\n\n\t// If the theme is not found, try to match the theme slug with a folder.\n\tif ( ! matchGroup ) {\n\t\tmatchGroup = html.match(\n\t\t\t`action=activate&stylesheet=${ optionalFolder }${ encodeURIComponent(\n\t\t\t\tthemeSlug\n\t\t\t) }&_wpnonce=[a-z0-9]+`\n\t\t);\n\t}\n\n\tif ( ! matchGroup ) {\n\t\tif ( html.includes( `data-slug=\"${ themeSlug }\"` ) ) {\n\t\t\t// The theme is already activated.\n\t\t\treturn;\n\t\t}\n\n\t\tthrow new Error( `The theme \"${ themeSlug }\" is not installed` );\n\t}\n\n\tconst [ activateQuery ] = matchGroup;\n\tconst activateLink =\n\t\tTHEMES_URL + `?${ activateQuery }`.replace( /&/g, '&' );\n\n\tresponse = await this.request.get( activateLink );\n\n\tawait response.dispose();\n}\n\n// https://developer.wordpress.org/rest-api/reference/themes/#definition\nasync function getCurrentThemeGlobalStylesPostId( this: RequestUtils ) {\n\ttype ThemeItem = {\n\t\tstylesheet: string;\n\t\tstatus: string;\n\t\t_links: { 'wp:user-global-styles': { href: string }[] };\n\t};\n\tconst themes = await this.rest< ThemeItem[] >( {\n\t\tpath: '/wp/v2/themes',\n\t} );\n\tlet themeGlobalStylesId: string = '';\n\tif ( themes && themes.length ) {\n\t\tconst currentTheme: ThemeItem | undefined = themes.find(\n\t\t\t( { status } ) => status === 'active'\n\t\t);\n\n\t\tconst globalStylesURL =\n\t\t\tcurrentTheme?._links?.[ 'wp:user-global-styles' ]?.[ 0 ]?.href;\n\t\tif ( globalStylesURL ) {\n\t\t\tthemeGlobalStylesId = globalStylesURL?.split(\n\t\t\t\t'rest_route=/wp/v2/global-styles/'\n\t\t\t)[ 1 ];\n\t\t}\n\t}\n\treturn themeGlobalStylesId;\n}\n\n/**\n * Deletes all post revisions using the REST API.\n *\n * @param {} this RequestUtils.\n * @param {string|number} parentId Post attributes.\n */\nasync function getThemeGlobalStylesRevisions(\n\tthis: RequestUtils,\n\tparentId: number | string\n) {\n\t// Lists all global styles revisions.\n\treturn await this.rest< Record< string, Object >[] >( {\n\t\tpath: `/wp/v2/global-styles/${ parentId }/revisions`,\n\t\tparams: {\n\t\t\tper_page: 100,\n\t\t},\n\t} );\n}\n\nexport {\n\tactivateTheme,\n\tgetCurrentThemeGlobalStylesPostId,\n\tgetThemeGlobalStylesRevisions,\n};\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,oBAA4B;AAE5B,IAAM,a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A,EACD,CAAE;AACH;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,83 +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/request-utils/users.ts
|
|
21
|
-
var users_exports = {};
|
|
22
|
-
__export(users_exports, {
|
|
23
|
-
createUser: () => createUser,
|
|
24
|
-
deleteAllUsers: () => deleteAllUsers
|
|
25
|
-
});
|
|
26
|
-
module.exports = __toCommonJS(users_exports);
|
|
27
|
-
async function listUsers() {
|
|
28
|
-
const response = await this.rest({
|
|
29
|
-
method: "GET",
|
|
30
|
-
path: "/wp/v2/users",
|
|
31
|
-
params: {
|
|
32
|
-
per_page: 100
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
return response;
|
|
36
|
-
}
|
|
37
|
-
async function createUser(user) {
|
|
38
|
-
const userData = {
|
|
39
|
-
username: user.username,
|
|
40
|
-
email: user.email
|
|
41
|
-
};
|
|
42
|
-
if (user.firstName) {
|
|
43
|
-
userData.first_name = user.firstName;
|
|
44
|
-
}
|
|
45
|
-
if (user.lastName) {
|
|
46
|
-
userData.last_name = user.lastName;
|
|
47
|
-
}
|
|
48
|
-
if (user.password) {
|
|
49
|
-
userData.password = user.password;
|
|
50
|
-
}
|
|
51
|
-
if (user.roles) {
|
|
52
|
-
userData.roles = user.roles;
|
|
53
|
-
}
|
|
54
|
-
const response = await this.rest({
|
|
55
|
-
method: "POST",
|
|
56
|
-
path: "/wp/v2/users",
|
|
57
|
-
data: userData
|
|
58
|
-
});
|
|
59
|
-
return response;
|
|
60
|
-
}
|
|
61
|
-
async function deleteUser(userId) {
|
|
62
|
-
const response = await this.rest({
|
|
63
|
-
method: "DELETE",
|
|
64
|
-
path: `/wp/v2/users/${userId}`,
|
|
65
|
-
params: { force: true, reassign: 1 }
|
|
66
|
-
});
|
|
67
|
-
return response;
|
|
68
|
-
}
|
|
69
|
-
async function deleteAllUsers() {
|
|
70
|
-
const users = await listUsers.bind(this)();
|
|
71
|
-
const responses = await Promise.all(
|
|
72
|
-
users.filter(
|
|
73
|
-
(user) => user.id !== 1 && user.name !== this.user.username
|
|
74
|
-
).map((user) => deleteUser.bind(this)(user.id))
|
|
75
|
-
);
|
|
76
|
-
return responses;
|
|
77
|
-
}
|
|
78
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
79
|
-
0 && (module.exports = {
|
|
80
|
-
createUser,
|
|
81
|
-
deleteAllUsers
|
|
82
|
-
});
|
|
83
|
-
//# sourceMappingURL=users.cjs.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/request-utils/users.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { RequestUtils } from './index';\n\nexport interface User {\n\tid: number;\n\tname: string;\n\temail: string;\n}\n\nexport interface UserData {\n\tusername: string;\n\temail: string;\n\tfirstName?: string;\n\tlastName?: string;\n\tpassword?: string;\n\troles?: string[];\n}\n\nexport interface UserRequestData {\n\tusername: string;\n\temail: string;\n\tfirst_name?: string;\n\tlast_name?: string;\n\tpassword?: string;\n\troles?: string[];\n}\n\n/**\n * List all users.\n *\n * @see https://developer.wordpress.org/rest-api/reference/users/#list-users\n * @param this\n */\nasync function listUsers( this: RequestUtils ) {\n\tconst response = await this.rest< User[] >( {\n\t\tmethod: 'GET',\n\t\tpath: '/wp/v2/users',\n\t\tparams: {\n\t\t\tper_page: 100,\n\t\t},\n\t} );\n\n\treturn response;\n}\n\n/**\n * Add a test user.\n *\n * @see https://developer.wordpress.org/rest-api/reference/users/#create-a-user\n * @param this\n * @param user User data to create.\n */\nasync function createUser( this: RequestUtils, user: UserData ) {\n\tconst userData: UserRequestData = {\n\t\tusername: user.username,\n\t\temail: user.email,\n\t};\n\n\tif ( user.firstName ) {\n\t\tuserData.first_name = user.firstName;\n\t}\n\n\tif ( user.lastName ) {\n\t\tuserData.last_name = user.lastName;\n\t}\n\n\tif ( user.password ) {\n\t\tuserData.password = user.password;\n\t}\n\n\tif ( user.roles ) {\n\t\tuserData.roles = user.roles;\n\t}\n\n\tconst response = await this.rest< User >( {\n\t\tmethod: 'POST',\n\t\tpath: '/wp/v2/users',\n\t\tdata: userData,\n\t} );\n\n\treturn response;\n}\n\n/**\n * Delete a user.\n *\n * @see https://developer.wordpress.org/rest-api/reference/users/#delete-a-user\n * @param this\n * @param userId The ID of the user.\n */\nasync function deleteUser( this: RequestUtils, userId: number ) {\n\tconst response = await this.rest( {\n\t\tmethod: 'DELETE',\n\t\tpath: `/wp/v2/users/${ userId }`,\n\t\tparams: { force: true, reassign: 1 },\n\t} );\n\n\treturn response;\n}\n\n/**\n * Delete all users except main root user.\n *\n * @param this\n */\nasync function deleteAllUsers( this: RequestUtils ) {\n\tconst users = await listUsers.bind( this )();\n\n\t// The users endpoint doesn't support batch request yet.\n\tconst responses = await Promise.all(\n\t\tusers\n\t\t\t// Do not delete neither root user nor the current user.\n\t\t\t.filter(\n\t\t\t\t( user: User ) =>\n\t\t\t\t\tuser.id !== 1 && user.name !== this.user.username\n\t\t\t)\n\t\t\t.map( ( user: User ) => deleteUser.bind( this )( user.id ) )\n\t);\n\n\treturn responses;\n}\n\nexport { createUser, deleteAllUsers };\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAmCA,eAAe,YAAgC;AAC9C,QAAM,WAAW,MAAM,KAAK,KAAgB;AAAA,IAC3C,QAAQ;AAAA,IACR,MAAM;AAAA,IACN,QAAQ;AAAA,MACP,UAAU;AAAA,IACX;AAAA,EACD,CAAE;AAEF,SAAO;AACR;AASA,eAAe,WAAgC,MAAiB;AAC/D,QAAM,WAA4B;AAAA,IACjC,UAAU,KAAK;AAAA,IACf,OAAO,KAAK;AAAA,EACb;AAEA,MAAK,KAAK,WAAY;AACrB,aAAS,aAAa,KAAK;AAAA,EAC5B;AAEA,MAAK,KAAK,UAAW;AACpB,aAAS,YAAY,KAAK;AAAA,EAC3B;AAEA,MAAK,KAAK,UAAW;AACpB,aAAS,WAAW,KAAK;AAAA,EAC1B;AAEA,MAAK,KAAK,OAAQ;AACjB,aAAS,QAAQ,KAAK;AAAA,EACvB;AAEA,QAAM,WAAW,MAAM,KAAK,KAAc;AAAA,IACzC,QAAQ;AAAA,IACR,MAAM;AAAA,IACN,MAAM;AAAA,EACP,CAAE;AAEF,SAAO;AACR;AASA,eAAe,WAAgC,QAAiB;AAC/D,QAAM,WAAW,MAAM,KAAK,KAAM;AAAA,IACjC,QAAQ;AAAA,IACR,MAAM,gBAAiB,MAAO;AAAA,IAC9B,QAAQ,EAAE,OAAO,MAAM,UAAU,EAAE;AAAA,EACpC,CAAE;AAEF,SAAO;AACR;AAOA,eAAe,iBAAqC;AACnD,QAAM,QAAQ,MAAM,UAAU,KAAM,IAAK,EAAE;AAG3C,QAAM,YAAY,MAAM,QAAQ;AAAA,IAC/B,MAEE;AAAA,MACA,CAAE,SACD,KAAK,OAAO,KAAK,KAAK,SAAS,KAAK,KAAK;AAAA,IAC3C,EACC,IAAK,CAAE,SAAgB,WAAW,KAAM,IAAK,EAAG,KAAK,EAAG,CAAE;AAAA,EAC7D;AAEA,SAAO;AACR;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,79 +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/request-utils/widgets.js
|
|
21
|
-
var widgets_exports = {};
|
|
22
|
-
__export(widgets_exports, {
|
|
23
|
-
addWidgetBlock: () => addWidgetBlock,
|
|
24
|
-
deleteAllWidgets: () => deleteAllWidgets
|
|
25
|
-
});
|
|
26
|
-
module.exports = __toCommonJS(widgets_exports);
|
|
27
|
-
async function deleteAllWidgets() {
|
|
28
|
-
const [widgets, sidebars] = await Promise.all([
|
|
29
|
-
this.rest({ path: "/wp/v2/widgets" }),
|
|
30
|
-
this.rest({ path: "/wp/v2/sidebars" })
|
|
31
|
-
]);
|
|
32
|
-
await this.batchRest(
|
|
33
|
-
widgets.map((widget) => ({
|
|
34
|
-
method: "DELETE",
|
|
35
|
-
path: `/wp/v2/widgets/${widget.id}?force=true`
|
|
36
|
-
}))
|
|
37
|
-
);
|
|
38
|
-
await Promise.all(
|
|
39
|
-
sidebars.map(
|
|
40
|
-
(sidebar) => this.rest({
|
|
41
|
-
method: "POST",
|
|
42
|
-
path: `/wp/v2/sidebars/${sidebar.id}`,
|
|
43
|
-
data: { id: sidebar.id, widgets: [] }
|
|
44
|
-
})
|
|
45
|
-
)
|
|
46
|
-
);
|
|
47
|
-
}
|
|
48
|
-
async function addWidgetBlock(serializedBlock, widgetAreaId) {
|
|
49
|
-
const { id: blockId } = await this.rest({
|
|
50
|
-
method: "POST",
|
|
51
|
-
path: "/wp/v2/widgets",
|
|
52
|
-
data: {
|
|
53
|
-
id_base: "block",
|
|
54
|
-
sidebar: widgetAreaId,
|
|
55
|
-
instance: {
|
|
56
|
-
raw: { content: serializedBlock }
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
const { widgets } = await this.rest({
|
|
61
|
-
path: `/wp/v2/sidebars/${widgetAreaId}`
|
|
62
|
-
});
|
|
63
|
-
const updatedWidgets = new Set(widgets);
|
|
64
|
-
updatedWidgets.delete(blockId);
|
|
65
|
-
updatedWidgets.add(blockId);
|
|
66
|
-
await this.rest({
|
|
67
|
-
method: "PUT",
|
|
68
|
-
path: `/wp/v2/sidebars/${widgetAreaId}`,
|
|
69
|
-
data: {
|
|
70
|
-
widgets: [...updatedWidgets]
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
75
|
-
0 && (module.exports = {
|
|
76
|
-
addWidgetBlock,
|
|
77
|
-
deleteAllWidgets
|
|
78
|
-
});
|
|
79
|
-
//# sourceMappingURL=widgets.cjs.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/request-utils/widgets.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * Delete all the widgets in the widgets screen.\n *\n * @this {import('./index').RequestUtils}\n */\nexport async function deleteAllWidgets() {\n\tconst [ widgets, sidebars ] = await Promise.all( [\n\t\tthis.rest( { path: '/wp/v2/widgets' } ),\n\t\tthis.rest( { path: '/wp/v2/sidebars' } ),\n\t] );\n\n\tawait this.batchRest(\n\t\twidgets.map( ( widget ) => ( {\n\t\t\tmethod: 'DELETE',\n\t\t\tpath: `/wp/v2/widgets/${ widget.id }?force=true`,\n\t\t} ) )\n\t);\n\n\t// The endpoint doesn't support batch requests yet.\n\tawait Promise.all(\n\t\tsidebars.map( ( sidebar ) =>\n\t\t\tthis.rest( {\n\t\t\t\tmethod: 'POST',\n\t\t\t\tpath: `/wp/v2/sidebars/${ sidebar.id }`,\n\t\t\t\tdata: { id: sidebar.id, widgets: [] },\n\t\t\t} )\n\t\t)\n\t);\n}\n\n/**\n * Add a widget block to the widget area.\n *\n * @this {import('./index').RequestUtils}\n * @param {string} serializedBlock The serialized content of the inserted block HTML.\n * @param {string} widgetAreaId The ID of the widget area.\n */\nexport async function addWidgetBlock( serializedBlock, widgetAreaId ) {\n\tconst { id: blockId } = await this.rest( {\n\t\tmethod: 'POST',\n\t\tpath: '/wp/v2/widgets',\n\t\tdata: {\n\t\t\tid_base: 'block',\n\t\t\tsidebar: widgetAreaId,\n\t\t\tinstance: {\n\t\t\t\traw: { content: serializedBlock },\n\t\t\t},\n\t\t},\n\t} );\n\n\tconst { widgets } = await this.rest( {\n\t\tpath: `/wp/v2/sidebars/${ widgetAreaId }`,\n\t} );\n\n\tconst updatedWidgets = new Set( widgets );\n\t// Remove duplicate.\n\tupdatedWidgets.delete( blockId );\n\t// Add to last block.\n\tupdatedWidgets.add( blockId );\n\n\tawait this.rest( {\n\t\tmethod: 'PUT',\n\t\tpath: `/wp/v2/sidebars/${ widgetAreaId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