@wordpress/e2e-test-utils-playwright 1.48.0 → 1.48.2-next.v.202606191442.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 +31 -0
- package/build/admin/create-new-post.js.map +1 -0
- package/build/admin/edit-post.js +20 -0
- package/build/admin/edit-post.js.map +1 -0
- package/{src/admin/get-page-error.ts → build/admin/get-page-error.js} +9 -12
- package/build/admin/get-page-error.js.map +1 -0
- package/build/admin/index.js +40 -0
- package/build/admin/index.js.map +1 -0
- package/build/admin/visit-admin-page.js +32 -0
- package/build/admin/visit-admin-page.js.map +1 -0
- package/build/admin/visit-site-editor.js +45 -0
- package/build/admin/visit-site-editor.js.map +1 -0
- package/build/admin/wait-for-site-editor.js +41 -0
- package/build/admin/wait-for-site-editor.js.map +1 -0
- package/build/config.js +13 -0
- package/build/config.js.map +1 -0
- package/build/editor/click-block-options-menu-item.js +17 -0
- package/build/editor/click-block-options-menu-item.js.map +1 -0
- package/build/editor/click-block-toolbar-button.js +16 -0
- package/build/editor/click-block-toolbar-button.js.map +1 -0
- package/build/editor/get-blocks.js +45 -0
- package/build/editor/get-blocks.js.map +1 -0
- package/build/editor/get-edited-post-content.js +15 -0
- package/build/editor/get-edited-post-content.js.map +1 -0
- package/build/editor/index.js +75 -0
- package/build/editor/index.js.map +1 -0
- package/build/editor/insert-block.js +23 -0
- package/build/editor/insert-block.js.map +1 -0
- package/build/editor/open-document-settings-sidebar.js +27 -0
- package/build/editor/open-document-settings-sidebar.js.map +1 -0
- package/build/editor/preview.js +21 -0
- package/build/editor/preview.js.map +1 -0
- package/build/editor/publish-post.js +45 -0
- package/build/editor/publish-post.js.map +1 -0
- package/build/editor/save-draft.js +18 -0
- package/build/editor/save-draft.js.map +1 -0
- package/build/editor/select-blocks.js +28 -0
- package/build/editor/select-blocks.js.map +1 -0
- package/build/editor/set-content.js +17 -0
- package/build/editor/set-content.js.map +1 -0
- package/build/editor/set-is-fixed-toolbar.js +18 -0
- package/build/editor/set-is-fixed-toolbar.js.map +1 -0
- package/build/editor/set-preferences.js +21 -0
- package/build/editor/set-preferences.js.map +1 -0
- package/build/editor/show-block-toolbar.js +19 -0
- package/build/editor/show-block-toolbar.js.map +1 -0
- package/build/editor/site-editor.js +44 -0
- package/build/editor/site-editor.js.map +1 -0
- package/build/editor/switch-editor-tool.js +33 -0
- package/build/editor/switch-editor-tool.js.map +1 -0
- package/build/editor/switch-to-legacy-canvas.js +18 -0
- package/build/editor/switch-to-legacy-canvas.js.map +1 -0
- package/build/editor/transform-block-to.js +24 -0
- package/build/editor/transform-block-to.js.map +1 -0
- package/build/index.js +19 -0
- package/build/index.js.map +1 -0
- package/build/lighthouse/index.js +61 -0
- package/build/lighthouse/index.js.map +1 -0
- package/build/metrics/index.js +314 -0
- package/build/metrics/index.js.map +1 -0
- package/build/page-utils/drag-files.js +119 -0
- package/build/page-utils/drag-files.js.map +1 -0
- package/build/page-utils/emulate-network-conditions.js +71 -0
- package/build/page-utils/emulate-network-conditions.js.map +1 -0
- package/build/page-utils/index.js +37 -0
- package/build/page-utils/index.js.map +1 -0
- package/build/page-utils/is-current-url.js +21 -0
- package/build/page-utils/is-current-url.js.map +1 -0
- package/build/page-utils/keycodes.js +41 -0
- package/build/page-utils/keycodes.js.map +1 -0
- package/build/page-utils/press-keys.js +141 -0
- package/build/page-utils/press-keys.js.map +1 -0
- package/{src → build}/page-utils/set-browser-viewport.js +12 -14
- package/build/page-utils/set-browser-viewport.js.map +1 -0
- package/build/request-utils/blocks.js +40 -0
- package/build/request-utils/blocks.js.map +1 -0
- package/build/request-utils/comments.js +52 -0
- package/build/request-utils/comments.js.map +1 -0
- package/build/request-utils/gutenberg-experiments.js +47 -0
- package/build/request-utils/gutenberg-experiments.js.map +1 -0
- package/build/request-utils/index.js +196 -0
- package/build/request-utils/index.js.map +1 -0
- package/build/request-utils/login.js +21 -0
- package/build/request-utils/login.js.map +1 -0
- package/build/request-utils/media.js +106 -0
- package/build/request-utils/media.js.map +1 -0
- package/build/request-utils/menus.js +116 -0
- package/build/request-utils/menus.js.map +1 -0
- package/build/request-utils/pages.js +53 -0
- package/build/request-utils/pages.js.map +1 -0
- package/build/request-utils/patterns.js +27 -0
- package/build/request-utils/patterns.js.map +1 -0
- package/build/request-utils/plugins.js +85 -0
- package/build/request-utils/plugins.js.map +1 -0
- package/build/request-utils/posts.js +42 -0
- package/build/request-utils/posts.js.map +1 -0
- package/build/request-utils/preferences.js +54 -0
- package/build/request-utils/preferences.js.map +1 -0
- package/{src/request-utils/records.ts → build/request-utils/records.js} +10 -15
- package/build/request-utils/records.js.map +1 -0
- package/build/request-utils/rest.js +181 -0
- package/build/request-utils/rest.js.map +1 -0
- package/build/request-utils/site-settings.js +33 -0
- package/build/request-utils/site-settings.js.map +1 -0
- package/build/request-utils/templates.js +54 -0
- package/build/request-utils/templates.js.map +1 -0
- package/build/request-utils/themes.js +69 -0
- package/build/request-utils/themes.js.map +1 -0
- package/build/request-utils/users.js +81 -0
- package/build/request-utils/users.js.map +1 -0
- package/build/request-utils/widgets.js +61 -0
- package/build/request-utils/widgets.js.map +1 -0
- package/build/test.js +189 -0
- package/build/test.js.map +1 -0
- package/build/types.js +3 -0
- package/build/types.js.map +1 -0
- package/package.json +8 -5
- package/src/admin/create-new-post.ts +0 -47
- package/src/admin/edit-post.ts +0 -24
- package/src/admin/index.ts +0 -52
- package/src/admin/visit-admin-page.ts +0 -43
- package/src/admin/visit-site-editor.ts +0 -62
- package/src/admin/wait-for-site-editor.ts +0 -52
- package/src/config.ts +0 -12
- package/src/editor/click-block-options-menu-item.ts +0 -18
- package/src/editor/click-block-toolbar-button.ts +0 -21
- package/src/editor/get-blocks.ts +0 -75
- package/src/editor/get-edited-post-content.ts +0 -19
- package/src/editor/index.ts +0 -95
- package/src/editor/insert-block.ts +0 -54
- package/src/editor/open-document-settings-sidebar.ts +0 -31
- package/src/editor/preview.ts +0 -32
- package/src/editor/publish-post.ts +0 -51
- package/src/editor/save-draft.ts +0 -20
- package/src/editor/select-blocks.ts +0 -48
- package/src/editor/set-content.ts +0 -24
- package/src/editor/set-is-fixed-toolbar.ts +0 -20
- package/src/editor/set-preferences.ts +0 -37
- package/src/editor/show-block-toolbar.ts +0 -20
- package/src/editor/site-editor.ts +0 -55
- package/src/editor/switch-editor-tool.ts +0 -34
- package/src/editor/switch-to-legacy-canvas.ts +0 -20
- package/src/editor/transform-block-to.ts +0 -34
- package/src/index.ts +0 -8
- package/src/lighthouse/index.ts +0 -75
- package/src/metrics/index.ts +0 -441
- package/src/page-utils/drag-files.ts +0 -173
- package/src/page-utils/emulate-network-conditions.ts +0 -101
- package/src/page-utils/index.ts +0 -54
- package/src/page-utils/is-current-url.ts +0 -20
- package/src/page-utils/keycodes.ts +0 -48
- package/src/page-utils/press-keys.ts +0 -195
- package/src/request-utils/blocks.ts +0 -58
- package/src/request-utils/comments.ts +0 -80
- package/src/request-utils/gutenberg-experiments.ts +0 -62
- package/src/request-utils/index.ts +0 -222
- package/src/request-utils/login.ts +0 -34
- package/src/request-utils/media.ts +0 -102
- package/src/request-utils/menus.ts +0 -145
- package/src/request-utils/pages.ts +0 -75
- package/src/request-utils/patterns.ts +0 -31
- package/src/request-utils/plugins.ts +0 -103
- package/src/request-utils/posts.ts +0 -69
- package/src/request-utils/preferences.ts +0 -63
- package/src/request-utils/rest.ts +0 -222
- package/src/request-utils/site-settings.ts +0 -58
- package/src/request-utils/templates.ts +0 -83
- package/src/request-utils/themes.ts +0 -110
- package/src/request-utils/users.ts +0 -125
- package/src/request-utils/widgets.js +0 -68
- package/src/test.ts +0 -204
- package/src/types.ts +0 -13
package/build/test.js
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Playwright fixtures use `use()` which is not a React hook.
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
+
}) : function(o, v) {
|
|
17
|
+
o["default"] = v;
|
|
18
|
+
});
|
|
19
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
20
|
+
var ownKeys = function(o) {
|
|
21
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
22
|
+
var ar = [];
|
|
23
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
24
|
+
return ar;
|
|
25
|
+
};
|
|
26
|
+
return ownKeys(o);
|
|
27
|
+
};
|
|
28
|
+
return function (mod) {
|
|
29
|
+
if (mod && mod.__esModule) return mod;
|
|
30
|
+
var result = {};
|
|
31
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
32
|
+
__setModuleDefault(result, mod);
|
|
33
|
+
return result;
|
|
34
|
+
};
|
|
35
|
+
})();
|
|
36
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
37
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
38
|
+
};
|
|
39
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
+
exports.expect = exports.test = void 0;
|
|
41
|
+
/**
|
|
42
|
+
* External dependencies
|
|
43
|
+
*/
|
|
44
|
+
const path = __importStar(require("path"));
|
|
45
|
+
const test_1 = require("@playwright/test");
|
|
46
|
+
Object.defineProperty(exports, "expect", { enumerable: true, get: function () { return test_1.expect; } });
|
|
47
|
+
const get_port_1 = __importDefault(require("get-port"));
|
|
48
|
+
/**
|
|
49
|
+
* Internal dependencies
|
|
50
|
+
*/
|
|
51
|
+
const index_1 = require("./index");
|
|
52
|
+
const STORAGE_STATE_PATH = process.env.STORAGE_STATE_PATH ||
|
|
53
|
+
path.join(process.cwd(), 'artifacts/storage-states/admin.json');
|
|
54
|
+
/**
|
|
55
|
+
* Set of console logging types observed to protect against unexpected yet
|
|
56
|
+
* handled (i.e. not catastrophic) errors or warnings. Each key corresponds
|
|
57
|
+
* to the Playwright ConsoleMessage type, its value the corresponding function
|
|
58
|
+
* on the console global object.
|
|
59
|
+
*/
|
|
60
|
+
const OBSERVED_CONSOLE_MESSAGE_TYPES = ['warn', 'error'];
|
|
61
|
+
/**
|
|
62
|
+
* Adds a page event handler to emit uncaught exception to process if one of
|
|
63
|
+
* the observed console logging types is encountered.
|
|
64
|
+
*
|
|
65
|
+
* @param message The console message.
|
|
66
|
+
*/
|
|
67
|
+
function observeConsoleLogging(message) {
|
|
68
|
+
const type = message.type();
|
|
69
|
+
if (!OBSERVED_CONSOLE_MESSAGE_TYPES.includes(type)) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const text = message.text();
|
|
73
|
+
// An exception is made for _blanket_ deprecation warnings: Those
|
|
74
|
+
// which log regardless of whether a deprecated feature is in use.
|
|
75
|
+
if (text.includes('This is a global warning')) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
// A chrome advisory warning about SameSite cookies is informational
|
|
79
|
+
// about future changes, tracked separately for improvement in core.
|
|
80
|
+
//
|
|
81
|
+
// See: https://core.trac.wordpress.org/ticket/37000
|
|
82
|
+
// See: https://www.chromestatus.com/feature/5088147346030592
|
|
83
|
+
// See: https://www.chromestatus.com/feature/5633521622188032
|
|
84
|
+
if (text.includes('A cookie associated with a cross-site resource') ||
|
|
85
|
+
text.includes('https://developer.mozilla.org/docs/Web/HTTP/Headers/Set-Cookie/SameSite')) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
// Viewing posts on the front end can result in this error, which
|
|
89
|
+
// has nothing to do with Gutenberg.
|
|
90
|
+
if (text.includes('net::ERR_UNKNOWN_URL_SCHEME')) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
// TODO: Not implemented yet.
|
|
94
|
+
// Network errors are ignored only if we are intentionally testing
|
|
95
|
+
// offline mode.
|
|
96
|
+
// if (
|
|
97
|
+
// text.includes( 'net::ERR_INTERNET_DISCONNECTED' ) &&
|
|
98
|
+
// isOfflineMode()
|
|
99
|
+
// ) {
|
|
100
|
+
// return;
|
|
101
|
+
// }
|
|
102
|
+
// As of WordPress 5.3.2 in Chrome 79, navigating to the block editor
|
|
103
|
+
// (Posts > Add New) will display a console warning about
|
|
104
|
+
// non - unique IDs.
|
|
105
|
+
// See: https://core.trac.wordpress.org/ticket/23165
|
|
106
|
+
if (text.includes('elements with non-unique id #_wpnonce')) {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
// Ignore all JQMIGRATE (jQuery migrate) deprecation warnings.
|
|
110
|
+
if (text.includes('JQMIGRATE')) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
// https://bugzilla.mozilla.org/show_bug.cgi?id=1404468
|
|
114
|
+
if (text.includes('Layout was forced before the page was fully loaded')) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
// Deprecated warnings coming from the third-party libraries.
|
|
118
|
+
if (text.includes('MouseEvent.moz')) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
const logFunction = type;
|
|
122
|
+
// Disable reason: We intentionally bubble up the console message
|
|
123
|
+
// which, unless the test explicitly anticipates the logging via
|
|
124
|
+
// @wordpress/jest-console matchers, will cause the intended test
|
|
125
|
+
// failure.
|
|
126
|
+
// eslint-disable-next-line no-console
|
|
127
|
+
console[logFunction](text);
|
|
128
|
+
}
|
|
129
|
+
const test = test_1.test.extend({
|
|
130
|
+
admin: async ({ page, pageUtils, editor }, use) => {
|
|
131
|
+
await use(new index_1.Admin({ page, pageUtils, editor }));
|
|
132
|
+
},
|
|
133
|
+
editor: async ({ page }, use) => {
|
|
134
|
+
await use(new index_1.Editor({ page }));
|
|
135
|
+
},
|
|
136
|
+
page: async ({ page }, use) => {
|
|
137
|
+
page.on('console', observeConsoleLogging);
|
|
138
|
+
await use(page);
|
|
139
|
+
// Clear local storage after each test.
|
|
140
|
+
// This needs to be wrapped with a try/catch because it can fail when
|
|
141
|
+
// the test is skipped (e.g. via fixme).
|
|
142
|
+
try {
|
|
143
|
+
await page.evaluate(() => {
|
|
144
|
+
window.localStorage.clear();
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
catch {
|
|
148
|
+
// noop.
|
|
149
|
+
}
|
|
150
|
+
await page.close();
|
|
151
|
+
},
|
|
152
|
+
pageUtils: async ({ page, browserName }, use) => {
|
|
153
|
+
await use(new index_1.PageUtils({ page, browserName }));
|
|
154
|
+
},
|
|
155
|
+
requestUtils: [
|
|
156
|
+
async ({}, use, workerInfo) => {
|
|
157
|
+
const requestUtils = await index_1.RequestUtils.setup({
|
|
158
|
+
baseURL: workerInfo.project.use.baseURL,
|
|
159
|
+
storageStatePath: STORAGE_STATE_PATH,
|
|
160
|
+
});
|
|
161
|
+
await use(requestUtils);
|
|
162
|
+
},
|
|
163
|
+
{ scope: 'worker', auto: true },
|
|
164
|
+
],
|
|
165
|
+
// Spins up a new browser for use by the Lighthouse fixture
|
|
166
|
+
// so that Lighthouse can connect to the debugging port.
|
|
167
|
+
// As a worker-scoped fixture, this will only launch 1
|
|
168
|
+
// instance for the whole test worker, so multiple tests
|
|
169
|
+
// will share the same instance with the same port.
|
|
170
|
+
lighthousePort: [
|
|
171
|
+
async ({}, use) => {
|
|
172
|
+
const port = await (0, get_port_1.default)();
|
|
173
|
+
const browser = await test_1.chromium.launch({
|
|
174
|
+
args: [`--remote-debugging-port=${port}`],
|
|
175
|
+
});
|
|
176
|
+
await use(port);
|
|
177
|
+
await browser.close();
|
|
178
|
+
},
|
|
179
|
+
{ scope: 'worker' },
|
|
180
|
+
],
|
|
181
|
+
lighthouse: async ({ page, lighthousePort }, use) => {
|
|
182
|
+
await use(new index_1.Lighthouse({ page, port: lighthousePort }));
|
|
183
|
+
},
|
|
184
|
+
metrics: async ({ page }, use) => {
|
|
185
|
+
await use(new index_1.Metrics({ page }));
|
|
186
|
+
},
|
|
187
|
+
});
|
|
188
|
+
exports.test = test;
|
|
189
|
+
//# sourceMappingURL=test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test.js","sourceRoot":"","sources":["../src/test.ts"],"names":[],"mappings":"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"}
|
package/build/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/e2e-test-utils-playwright",
|
|
3
|
-
"version": "1.48.0",
|
|
3
|
+
"version": "1.48.2-next.v.202606191442.0+17fe7db8a",
|
|
4
4
|
"description": "End-To-End (E2E) test utils for WordPress.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -25,13 +25,13 @@
|
|
|
25
25
|
"npm": ">=8.19.2"
|
|
26
26
|
},
|
|
27
27
|
"files": [
|
|
28
|
-
"
|
|
28
|
+
"build",
|
|
29
29
|
"build-types"
|
|
30
30
|
],
|
|
31
31
|
"exports": {
|
|
32
32
|
".": {
|
|
33
33
|
"types": "./build-types/index.d.ts",
|
|
34
|
-
"default": "./
|
|
34
|
+
"default": "./build/index.js"
|
|
35
35
|
},
|
|
36
36
|
"./package.json": "./package.json"
|
|
37
37
|
},
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"web-vitals": "^4.2.1"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"@types/mime": "2.0.3",
|
|
47
|
+
"@types/mime": "^2.0.3",
|
|
48
48
|
"@types/node": "^20.19.39"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
@@ -54,5 +54,8 @@
|
|
|
54
54
|
"publishConfig": {
|
|
55
55
|
"access": "public"
|
|
56
56
|
},
|
|
57
|
-
"
|
|
57
|
+
"scripts": {
|
|
58
|
+
"build": "tsc -p tsconfig.json"
|
|
59
|
+
},
|
|
60
|
+
"gitHead": "1b6a19222df5a88f161880b5789efb3171d8f425"
|
|
58
61
|
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Internal dependencies
|
|
3
|
-
*/
|
|
4
|
-
import type { Admin } from './';
|
|
5
|
-
|
|
6
|
-
interface NewPostOptions {
|
|
7
|
-
postType?: string;
|
|
8
|
-
title?: string;
|
|
9
|
-
content?: string;
|
|
10
|
-
excerpt?: string;
|
|
11
|
-
showWelcomeGuide?: boolean;
|
|
12
|
-
fullscreenMode?: boolean;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Creates new post.
|
|
17
|
-
*
|
|
18
|
-
* @param this
|
|
19
|
-
* @param options Options to create new post.
|
|
20
|
-
*/
|
|
21
|
-
export async function createNewPost(
|
|
22
|
-
this: Admin,
|
|
23
|
-
options: NewPostOptions = {}
|
|
24
|
-
) {
|
|
25
|
-
const query = new URLSearchParams();
|
|
26
|
-
const { postType, title, content, excerpt } = options;
|
|
27
|
-
|
|
28
|
-
if ( postType ) {
|
|
29
|
-
query.set( 'post_type', postType );
|
|
30
|
-
}
|
|
31
|
-
if ( title ) {
|
|
32
|
-
query.set( 'post_title', title );
|
|
33
|
-
}
|
|
34
|
-
if ( content ) {
|
|
35
|
-
query.set( 'content', content );
|
|
36
|
-
}
|
|
37
|
-
if ( excerpt ) {
|
|
38
|
-
query.set( 'excerpt', excerpt );
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
await this.visitAdminPage( 'post-new.php', query.toString() );
|
|
42
|
-
|
|
43
|
-
await this.editor.setPreferences( 'core/edit-post', {
|
|
44
|
-
welcomeGuide: options.showWelcomeGuide ?? false,
|
|
45
|
-
fullscreenMode: options.fullscreenMode ?? false,
|
|
46
|
-
} );
|
|
47
|
-
}
|
package/src/admin/edit-post.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Internal dependencies
|
|
3
|
-
*/
|
|
4
|
-
import type { Admin } from '.';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Open the post with given ID in the editor.
|
|
8
|
-
*
|
|
9
|
-
* @param this
|
|
10
|
-
* @param postId Post ID to visit.
|
|
11
|
-
*/
|
|
12
|
-
export async function editPost( this: Admin, postId: string | number ) {
|
|
13
|
-
const query = new URLSearchParams();
|
|
14
|
-
|
|
15
|
-
query.set( 'post', String( postId ) );
|
|
16
|
-
query.set( 'action', 'edit' );
|
|
17
|
-
|
|
18
|
-
await this.visitAdminPage( 'post.php', query.toString() );
|
|
19
|
-
|
|
20
|
-
await this.editor.setPreferences( 'core/edit-post', {
|
|
21
|
-
welcomeGuide: false,
|
|
22
|
-
fullscreenMode: false,
|
|
23
|
-
} );
|
|
24
|
-
}
|
package/src/admin/index.ts
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* External dependencies
|
|
3
|
-
*/
|
|
4
|
-
import type { Browser, Page, BrowserContext } from '@playwright/test';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Internal dependencies
|
|
8
|
-
*/
|
|
9
|
-
import { createNewPost } from './create-new-post';
|
|
10
|
-
import { getPageError } from './get-page-error';
|
|
11
|
-
import { visitAdminPage } from './visit-admin-page';
|
|
12
|
-
import { editPost } from './edit-post';
|
|
13
|
-
import { visitSiteEditor } from './visit-site-editor';
|
|
14
|
-
import { waitForSiteEditor } from './wait-for-site-editor';
|
|
15
|
-
import type { PageUtils } from '../page-utils';
|
|
16
|
-
import type { Editor } from '../editor';
|
|
17
|
-
|
|
18
|
-
type AdminConstructorProps = {
|
|
19
|
-
page: Page;
|
|
20
|
-
pageUtils: PageUtils;
|
|
21
|
-
editor: Editor;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export class Admin {
|
|
25
|
-
page: Page;
|
|
26
|
-
context: BrowserContext;
|
|
27
|
-
browser: Browser;
|
|
28
|
-
pageUtils: PageUtils;
|
|
29
|
-
editor: Editor;
|
|
30
|
-
|
|
31
|
-
constructor( { page, pageUtils, editor }: AdminConstructorProps ) {
|
|
32
|
-
this.page = page;
|
|
33
|
-
this.context = page.context();
|
|
34
|
-
this.browser = this.context.browser()!;
|
|
35
|
-
this.pageUtils = pageUtils;
|
|
36
|
-
this.editor = editor;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/** @borrows createNewPost as this.createNewPost */
|
|
40
|
-
createNewPost: typeof createNewPost = createNewPost.bind( this );
|
|
41
|
-
/** @borrows editPost as this.editPost */
|
|
42
|
-
editPost: typeof editPost = editPost.bind( this );
|
|
43
|
-
/** @borrows getPageError as this.getPageError */
|
|
44
|
-
getPageError: typeof getPageError = getPageError.bind( this );
|
|
45
|
-
/** @borrows visitAdminPage as this.visitAdminPage */
|
|
46
|
-
visitAdminPage: typeof visitAdminPage = visitAdminPage.bind( this );
|
|
47
|
-
/** @borrows visitSiteEditor as this.visitSiteEditor */
|
|
48
|
-
visitSiteEditor: typeof visitSiteEditor = visitSiteEditor.bind( this );
|
|
49
|
-
/** @borrows waitForSiteEditor as this.waitForSiteEditor */
|
|
50
|
-
waitForSiteEditor: typeof waitForSiteEditor =
|
|
51
|
-
waitForSiteEditor.bind( this );
|
|
52
|
-
}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* External dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { join } from 'path';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Internal dependencies
|
|
8
|
-
*/
|
|
9
|
-
import type { Admin } from './';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Visits admin page and handle errors.
|
|
13
|
-
*
|
|
14
|
-
* @param this
|
|
15
|
-
* @param adminPath String to be serialized as pathname.
|
|
16
|
-
* @param query String to be serialized as query portion of URL.
|
|
17
|
-
*/
|
|
18
|
-
export async function visitAdminPage(
|
|
19
|
-
this: Admin,
|
|
20
|
-
adminPath: string,
|
|
21
|
-
query?: string
|
|
22
|
-
) {
|
|
23
|
-
await this.page.goto(
|
|
24
|
-
join( 'wp-admin', adminPath ) + ( query ? `?${ query }` : '' )
|
|
25
|
-
);
|
|
26
|
-
|
|
27
|
-
// Handle upgrade required screen
|
|
28
|
-
if ( this.pageUtils.isCurrentURL( 'wp-admin/upgrade.php' ) ) {
|
|
29
|
-
// Click update
|
|
30
|
-
await this.page.click( '.button.button-large.button-primary' );
|
|
31
|
-
// Click continue
|
|
32
|
-
await this.page.click( '.button.button-large' );
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
if ( this.pageUtils.isCurrentURL( 'wp-login.php' ) ) {
|
|
36
|
-
throw new Error( 'Not logged in' );
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const error = await this.getPageError();
|
|
40
|
-
if ( error ) {
|
|
41
|
-
throw new Error( 'Unexpected error in page content: ' + error );
|
|
42
|
-
}
|
|
43
|
-
}
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Internal dependencies
|
|
3
|
-
*/
|
|
4
|
-
import type { Admin } from './';
|
|
5
|
-
|
|
6
|
-
interface SiteEditorOptions {
|
|
7
|
-
postId?: string | number;
|
|
8
|
-
postType?: string;
|
|
9
|
-
path?: string;
|
|
10
|
-
canvas?: string;
|
|
11
|
-
activeView?: string;
|
|
12
|
-
showWelcomeGuide?: boolean;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Visits the Site Editor main page.
|
|
17
|
-
*
|
|
18
|
-
* @param this
|
|
19
|
-
* @param options Options to visit the site editor.
|
|
20
|
-
*/
|
|
21
|
-
export async function visitSiteEditor(
|
|
22
|
-
this: Admin,
|
|
23
|
-
options: SiteEditorOptions = {}
|
|
24
|
-
) {
|
|
25
|
-
const { postId, postType, path, canvas, activeView } = options;
|
|
26
|
-
const query = new URLSearchParams();
|
|
27
|
-
|
|
28
|
-
if ( postId ) {
|
|
29
|
-
query.set( 'postId', String( postId ) );
|
|
30
|
-
}
|
|
31
|
-
if ( postType ) {
|
|
32
|
-
query.set( 'postType', postType );
|
|
33
|
-
}
|
|
34
|
-
if ( path ) {
|
|
35
|
-
query.set( 'path', path );
|
|
36
|
-
}
|
|
37
|
-
if ( canvas ) {
|
|
38
|
-
query.set( 'canvas', canvas );
|
|
39
|
-
}
|
|
40
|
-
if ( activeView ) {
|
|
41
|
-
query.set( 'activeView', activeView );
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
await this.visitAdminPage( 'site-editor.php', query.toString() );
|
|
45
|
-
|
|
46
|
-
if ( ! options.showWelcomeGuide ) {
|
|
47
|
-
await this.editor.setPreferences( 'core/edit-site', {
|
|
48
|
-
welcomeGuide: false,
|
|
49
|
-
welcomeGuideStyles: false,
|
|
50
|
-
welcomeGuidePage: false,
|
|
51
|
-
welcomeGuideTemplate: false,
|
|
52
|
-
} );
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Wait until the editor is loaded. The logic is a copy of the
|
|
57
|
-
* `waitWhileSiteEditorLoading` function in the `edit-site` package.
|
|
58
|
-
*/
|
|
59
|
-
if ( ! query.size || postId || canvas === 'edit' ) {
|
|
60
|
-
await this.waitForSiteEditor();
|
|
61
|
-
}
|
|
62
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Internal dependencies
|
|
3
|
-
*/
|
|
4
|
-
import type { Admin } from './';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Waits for the Site Editor to finish loading, i.e., for all resolvers
|
|
8
|
-
* in the `core` store to finish and then pause for a short period.
|
|
9
|
-
*
|
|
10
|
-
* @param this
|
|
11
|
-
*/
|
|
12
|
-
export async function waitForSiteEditor( this: Admin ) {
|
|
13
|
-
await this.page.evaluate( () => {
|
|
14
|
-
const MAX_LOADING_TIME = 10000;
|
|
15
|
-
const MAX_PAUSE_TIME = 100;
|
|
16
|
-
|
|
17
|
-
return new Promise< void >( ( resolve ) => {
|
|
18
|
-
let pauseTimeout: ReturnType< typeof setTimeout > | undefined;
|
|
19
|
-
|
|
20
|
-
function finish() {
|
|
21
|
-
unsubscribe();
|
|
22
|
-
clearTimeout( pauseTimeout );
|
|
23
|
-
clearTimeout( maxTimeout );
|
|
24
|
-
resolve();
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const maxTimeout = setTimeout( finish, MAX_LOADING_TIME );
|
|
28
|
-
|
|
29
|
-
function checkResolving() {
|
|
30
|
-
const isResolving = window.wp.data
|
|
31
|
-
.select( 'core' )
|
|
32
|
-
.hasResolvingSelectors();
|
|
33
|
-
|
|
34
|
-
if ( isResolving ) {
|
|
35
|
-
clearTimeout( pauseTimeout );
|
|
36
|
-
pauseTimeout = undefined;
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
if ( ! pauseTimeout ) {
|
|
41
|
-
pauseTimeout = setTimeout( finish, MAX_PAUSE_TIME );
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const unsubscribe = window.wp.data.subscribe(
|
|
46
|
-
checkResolving,
|
|
47
|
-
'core'
|
|
48
|
-
);
|
|
49
|
-
checkResolving();
|
|
50
|
-
} );
|
|
51
|
-
} );
|
|
52
|
-
}
|
package/src/config.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
const {
|
|
2
|
-
WP_USERNAME = 'admin',
|
|
3
|
-
WP_PASSWORD = 'password',
|
|
4
|
-
WP_BASE_URL = 'http://localhost:8889',
|
|
5
|
-
} = process.env;
|
|
6
|
-
|
|
7
|
-
const WP_ADMIN_USER = {
|
|
8
|
-
username: WP_USERNAME,
|
|
9
|
-
password: WP_PASSWORD,
|
|
10
|
-
} as const;
|
|
11
|
-
|
|
12
|
-
export { WP_ADMIN_USER, WP_USERNAME, WP_PASSWORD, WP_BASE_URL };
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Internal dependencies
|
|
3
|
-
*/
|
|
4
|
-
import type { Editor } from './index';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Clicks a block toolbar button.
|
|
8
|
-
*
|
|
9
|
-
* @param this
|
|
10
|
-
* @param label The text string of the button label.
|
|
11
|
-
*/
|
|
12
|
-
export async function clickBlockOptionsMenuItem( this: Editor, label: string ) {
|
|
13
|
-
await this.clickBlockToolbarButton( 'Options' );
|
|
14
|
-
await this.page
|
|
15
|
-
.getByRole( 'menu', { name: 'Options' } )
|
|
16
|
-
.getByRole( 'menuitem', { name: label } )
|
|
17
|
-
.click();
|
|
18
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Internal dependencies
|
|
3
|
-
*/
|
|
4
|
-
import type { Editor } from './index';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Clicks a block toolbar button.
|
|
8
|
-
*
|
|
9
|
-
* @param this
|
|
10
|
-
* @param label The text string of the button label.
|
|
11
|
-
*/
|
|
12
|
-
export async function clickBlockToolbarButton( this: Editor, label: string ) {
|
|
13
|
-
await this.showBlockToolbar();
|
|
14
|
-
|
|
15
|
-
const blockToolbar = this.page.locator(
|
|
16
|
-
'role=toolbar[name="Block tools"i]'
|
|
17
|
-
);
|
|
18
|
-
const button = blockToolbar.locator( `role=button[name="${ label }"]` );
|
|
19
|
-
|
|
20
|
-
await button.click();
|
|
21
|
-
}
|
package/src/editor/get-blocks.ts
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Internal dependencies
|
|
3
|
-
*/
|
|
4
|
-
import type { Editor } from './index';
|
|
5
|
-
|
|
6
|
-
type Block = {
|
|
7
|
-
name: string;
|
|
8
|
-
attributes: Record< string, unknown >;
|
|
9
|
-
innerBlocks: Block[];
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Returns the edited blocks.
|
|
14
|
-
*
|
|
15
|
-
* @param options
|
|
16
|
-
* @param options.clientId Limit the results to be only under a partial tree of the specified clientId.
|
|
17
|
-
* @param options.full Whether to return the full block data or just the name and attributes.
|
|
18
|
-
*
|
|
19
|
-
* @return The blocks.
|
|
20
|
-
*/
|
|
21
|
-
export async function getBlocks(
|
|
22
|
-
this: Editor,
|
|
23
|
-
{ clientId, full = false }: { clientId?: string; full?: boolean } = {}
|
|
24
|
-
) {
|
|
25
|
-
await this.page.waitForFunction(
|
|
26
|
-
() => window?.wp?.blocks && window?.wp?.data
|
|
27
|
-
);
|
|
28
|
-
|
|
29
|
-
return await this.page.evaluate(
|
|
30
|
-
( [ _full, _clientId ] ) => {
|
|
31
|
-
// Serialize serializable attributes of blocks.
|
|
32
|
-
function serializeAttributes(
|
|
33
|
-
attributes: Record< string, unknown >
|
|
34
|
-
) {
|
|
35
|
-
return Object.fromEntries(
|
|
36
|
-
Object.entries( attributes ).map( ( [ key, value ] ) => {
|
|
37
|
-
// Serialize RichTextData to string.
|
|
38
|
-
if (
|
|
39
|
-
value instanceof window.wp.richText.RichTextData
|
|
40
|
-
) {
|
|
41
|
-
return [ key, ( value as string ).toString() ];
|
|
42
|
-
}
|
|
43
|
-
return [ key, value ];
|
|
44
|
-
} )
|
|
45
|
-
);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// Remove other unpredictable properties like clientId from blocks for testing purposes.
|
|
49
|
-
function recursivelyTransformBlocks( blocks: Block[] ): Block[] {
|
|
50
|
-
return blocks.map( ( block ) => ( {
|
|
51
|
-
name: block.name,
|
|
52
|
-
attributes: serializeAttributes( block.attributes ),
|
|
53
|
-
innerBlocks: recursivelyTransformBlocks(
|
|
54
|
-
block.innerBlocks
|
|
55
|
-
),
|
|
56
|
-
} ) );
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const blocks = window.wp.data
|
|
60
|
-
.select( 'core/block-editor' )
|
|
61
|
-
.getBlocks( _clientId ) as Block[];
|
|
62
|
-
|
|
63
|
-
// The editor might still contain an unmodified empty block even when it's technically "empty".
|
|
64
|
-
if (
|
|
65
|
-
blocks.length === 1 &&
|
|
66
|
-
window.wp.blocks.isUnmodifiedDefaultBlock( blocks[ 0 ] )
|
|
67
|
-
) {
|
|
68
|
-
return [];
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
return _full ? blocks : recursivelyTransformBlocks( blocks );
|
|
72
|
-
},
|
|
73
|
-
[ full, clientId ]
|
|
74
|
-
);
|
|
75
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Internal dependencies
|
|
3
|
-
*/
|
|
4
|
-
import type { Editor } from './index';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Returns a promise which resolves with the edited post content (HTML string).
|
|
8
|
-
*
|
|
9
|
-
* @param this
|
|
10
|
-
*
|
|
11
|
-
* @return Promise resolving with post content markup.
|
|
12
|
-
*/
|
|
13
|
-
export async function getEditedPostContent( this: Editor ) {
|
|
14
|
-
await this.page.waitForFunction( () => window?.wp?.data );
|
|
15
|
-
|
|
16
|
-
return await this.page.evaluate( () =>
|
|
17
|
-
window.wp.data.select( 'core/editor' ).getEditedPostContent()
|
|
18
|
-
);
|
|
19
|
-
}
|