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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (172) hide show
  1. package/package.json +3 -3
  2. package/src/admin/create-new-post.ts +47 -0
  3. package/src/admin/edit-post.ts +24 -0
  4. package/{build/admin/get-page-error.js → src/admin/get-page-error.ts} +12 -9
  5. package/src/admin/index.ts +52 -0
  6. package/src/admin/visit-admin-page.ts +43 -0
  7. package/src/admin/visit-site-editor.ts +62 -0
  8. package/src/admin/wait-for-site-editor.ts +52 -0
  9. package/src/config.ts +12 -0
  10. package/src/editor/click-block-options-menu-item.ts +18 -0
  11. package/src/editor/click-block-toolbar-button.ts +21 -0
  12. package/src/editor/get-blocks.ts +75 -0
  13. package/src/editor/get-edited-post-content.ts +19 -0
  14. package/src/editor/index.ts +95 -0
  15. package/src/editor/insert-block.ts +54 -0
  16. package/src/editor/open-document-settings-sidebar.ts +31 -0
  17. package/src/editor/preview.ts +32 -0
  18. package/src/editor/publish-post.ts +51 -0
  19. package/src/editor/save-draft.ts +20 -0
  20. package/src/editor/select-blocks.ts +48 -0
  21. package/src/editor/set-content.ts +24 -0
  22. package/src/editor/set-is-fixed-toolbar.ts +20 -0
  23. package/src/editor/set-preferences.ts +37 -0
  24. package/src/editor/show-block-toolbar.ts +20 -0
  25. package/src/editor/site-editor.ts +55 -0
  26. package/src/editor/switch-editor-tool.ts +34 -0
  27. package/src/editor/switch-to-legacy-canvas.ts +20 -0
  28. package/src/editor/transform-block-to.ts +34 -0
  29. package/src/index.ts +8 -0
  30. package/src/lighthouse/index.ts +75 -0
  31. package/src/metrics/index.ts +441 -0
  32. package/src/page-utils/drag-files.ts +173 -0
  33. package/src/page-utils/emulate-network-conditions.ts +101 -0
  34. package/src/page-utils/index.ts +54 -0
  35. package/src/page-utils/is-current-url.ts +20 -0
  36. package/src/page-utils/keycodes.ts +48 -0
  37. package/src/page-utils/press-keys.ts +195 -0
  38. package/{build → src}/page-utils/set-browser-viewport.js +14 -12
  39. package/src/request-utils/blocks.ts +58 -0
  40. package/src/request-utils/comments.ts +80 -0
  41. package/src/request-utils/gutenberg-experiments.ts +62 -0
  42. package/src/request-utils/index.ts +222 -0
  43. package/src/request-utils/login.ts +34 -0
  44. package/src/request-utils/media.ts +102 -0
  45. package/src/request-utils/menus.ts +145 -0
  46. package/src/request-utils/pages.ts +75 -0
  47. package/src/request-utils/patterns.ts +31 -0
  48. package/src/request-utils/plugins.ts +103 -0
  49. package/src/request-utils/posts.ts +69 -0
  50. package/src/request-utils/preferences.ts +63 -0
  51. package/{build/request-utils/records.js → src/request-utils/records.ts} +15 -10
  52. package/src/request-utils/rest.ts +222 -0
  53. package/src/request-utils/site-settings.ts +58 -0
  54. package/src/request-utils/templates.ts +83 -0
  55. package/src/request-utils/themes.ts +110 -0
  56. package/src/request-utils/users.ts +125 -0
  57. package/src/request-utils/widgets.js +68 -0
  58. package/src/test.ts +204 -0
  59. package/src/types.ts +13 -0
  60. package/build/admin/create-new-post.js +0 -31
  61. package/build/admin/create-new-post.js.map +0 -1
  62. package/build/admin/edit-post.js +0 -20
  63. package/build/admin/edit-post.js.map +0 -1
  64. package/build/admin/get-page-error.js.map +0 -1
  65. package/build/admin/index.js +0 -40
  66. package/build/admin/index.js.map +0 -1
  67. package/build/admin/visit-admin-page.js +0 -32
  68. package/build/admin/visit-admin-page.js.map +0 -1
  69. package/build/admin/visit-site-editor.js +0 -45
  70. package/build/admin/visit-site-editor.js.map +0 -1
  71. package/build/admin/wait-for-site-editor.js +0 -41
  72. package/build/admin/wait-for-site-editor.js.map +0 -1
  73. package/build/config.js +0 -13
  74. package/build/config.js.map +0 -1
  75. package/build/editor/click-block-options-menu-item.js +0 -17
  76. package/build/editor/click-block-options-menu-item.js.map +0 -1
  77. package/build/editor/click-block-toolbar-button.js +0 -16
  78. package/build/editor/click-block-toolbar-button.js.map +0 -1
  79. package/build/editor/get-blocks.js +0 -45
  80. package/build/editor/get-blocks.js.map +0 -1
  81. package/build/editor/get-edited-post-content.js +0 -15
  82. package/build/editor/get-edited-post-content.js.map +0 -1
  83. package/build/editor/index.js +0 -75
  84. package/build/editor/index.js.map +0 -1
  85. package/build/editor/insert-block.js +0 -23
  86. package/build/editor/insert-block.js.map +0 -1
  87. package/build/editor/open-document-settings-sidebar.js +0 -27
  88. package/build/editor/open-document-settings-sidebar.js.map +0 -1
  89. package/build/editor/preview.js +0 -21
  90. package/build/editor/preview.js.map +0 -1
  91. package/build/editor/publish-post.js +0 -45
  92. package/build/editor/publish-post.js.map +0 -1
  93. package/build/editor/save-draft.js +0 -18
  94. package/build/editor/save-draft.js.map +0 -1
  95. package/build/editor/select-blocks.js +0 -28
  96. package/build/editor/select-blocks.js.map +0 -1
  97. package/build/editor/set-content.js +0 -17
  98. package/build/editor/set-content.js.map +0 -1
  99. package/build/editor/set-is-fixed-toolbar.js +0 -18
  100. package/build/editor/set-is-fixed-toolbar.js.map +0 -1
  101. package/build/editor/set-preferences.js +0 -21
  102. package/build/editor/set-preferences.js.map +0 -1
  103. package/build/editor/show-block-toolbar.js +0 -19
  104. package/build/editor/show-block-toolbar.js.map +0 -1
  105. package/build/editor/site-editor.js +0 -44
  106. package/build/editor/site-editor.js.map +0 -1
  107. package/build/editor/switch-editor-tool.js +0 -33
  108. package/build/editor/switch-editor-tool.js.map +0 -1
  109. package/build/editor/switch-to-legacy-canvas.js +0 -18
  110. package/build/editor/switch-to-legacy-canvas.js.map +0 -1
  111. package/build/editor/transform-block-to.js +0 -24
  112. package/build/editor/transform-block-to.js.map +0 -1
  113. package/build/index.js +0 -19
  114. package/build/index.js.map +0 -1
  115. package/build/lighthouse/index.js +0 -61
  116. package/build/lighthouse/index.js.map +0 -1
  117. package/build/metrics/index.js +0 -314
  118. package/build/metrics/index.js.map +0 -1
  119. package/build/page-utils/drag-files.js +0 -119
  120. package/build/page-utils/drag-files.js.map +0 -1
  121. package/build/page-utils/emulate-network-conditions.js +0 -71
  122. package/build/page-utils/emulate-network-conditions.js.map +0 -1
  123. package/build/page-utils/index.js +0 -37
  124. package/build/page-utils/index.js.map +0 -1
  125. package/build/page-utils/is-current-url.js +0 -21
  126. package/build/page-utils/is-current-url.js.map +0 -1
  127. package/build/page-utils/keycodes.js +0 -41
  128. package/build/page-utils/keycodes.js.map +0 -1
  129. package/build/page-utils/press-keys.js +0 -141
  130. package/build/page-utils/press-keys.js.map +0 -1
  131. package/build/page-utils/set-browser-viewport.js.map +0 -1
  132. package/build/request-utils/blocks.js +0 -40
  133. package/build/request-utils/blocks.js.map +0 -1
  134. package/build/request-utils/comments.js +0 -52
  135. package/build/request-utils/comments.js.map +0 -1
  136. package/build/request-utils/gutenberg-experiments.js +0 -47
  137. package/build/request-utils/gutenberg-experiments.js.map +0 -1
  138. package/build/request-utils/index.js +0 -196
  139. package/build/request-utils/index.js.map +0 -1
  140. package/build/request-utils/login.js +0 -21
  141. package/build/request-utils/login.js.map +0 -1
  142. package/build/request-utils/media.js +0 -106
  143. package/build/request-utils/media.js.map +0 -1
  144. package/build/request-utils/menus.js +0 -116
  145. package/build/request-utils/menus.js.map +0 -1
  146. package/build/request-utils/pages.js +0 -53
  147. package/build/request-utils/pages.js.map +0 -1
  148. package/build/request-utils/patterns.js +0 -27
  149. package/build/request-utils/patterns.js.map +0 -1
  150. package/build/request-utils/plugins.js +0 -85
  151. package/build/request-utils/plugins.js.map +0 -1
  152. package/build/request-utils/posts.js +0 -42
  153. package/build/request-utils/posts.js.map +0 -1
  154. package/build/request-utils/preferences.js +0 -54
  155. package/build/request-utils/preferences.js.map +0 -1
  156. package/build/request-utils/records.js.map +0 -1
  157. package/build/request-utils/rest.js +0 -181
  158. package/build/request-utils/rest.js.map +0 -1
  159. package/build/request-utils/site-settings.js +0 -33
  160. package/build/request-utils/site-settings.js.map +0 -1
  161. package/build/request-utils/templates.js +0 -54
  162. package/build/request-utils/templates.js.map +0 -1
  163. package/build/request-utils/themes.js +0 -69
  164. package/build/request-utils/themes.js.map +0 -1
  165. package/build/request-utils/users.js +0 -81
  166. package/build/request-utils/users.js.map +0 -1
  167. package/build/request-utils/widgets.js +0 -61
  168. package/build/request-utils/widgets.js.map +0 -1
  169. package/build/test.js +0 -189
  170. package/build/test.js.map +0 -1
  171. package/build/types.js +0 -3
  172. package/build/types.js.map +0 -1
@@ -0,0 +1,125 @@
1
+ /**
2
+ * Internal dependencies
3
+ */
4
+ import type { RequestUtils } from './index';
5
+
6
+ export interface User {
7
+ id: number;
8
+ name: string;
9
+ email: string;
10
+ }
11
+
12
+ export interface UserData {
13
+ username: string;
14
+ email: string;
15
+ firstName?: string;
16
+ lastName?: string;
17
+ password?: string;
18
+ roles?: string[];
19
+ }
20
+
21
+ export interface UserRequestData {
22
+ username: string;
23
+ email: string;
24
+ first_name?: string;
25
+ last_name?: string;
26
+ password?: string;
27
+ roles?: string[];
28
+ }
29
+
30
+ /**
31
+ * List all users.
32
+ *
33
+ * @see https://developer.wordpress.org/rest-api/reference/users/#list-users
34
+ * @param this
35
+ */
36
+ async function listUsers( this: RequestUtils ) {
37
+ const response = await this.rest< User[] >( {
38
+ method: 'GET',
39
+ path: '/wp/v2/users',
40
+ params: {
41
+ per_page: 100,
42
+ },
43
+ } );
44
+
45
+ return response;
46
+ }
47
+
48
+ /**
49
+ * Add a test user.
50
+ *
51
+ * @see https://developer.wordpress.org/rest-api/reference/users/#create-a-user
52
+ * @param this
53
+ * @param user User data to create.
54
+ */
55
+ async function createUser( this: RequestUtils, user: UserData ) {
56
+ const userData: UserRequestData = {
57
+ username: user.username,
58
+ email: user.email,
59
+ };
60
+
61
+ if ( user.firstName ) {
62
+ userData.first_name = user.firstName;
63
+ }
64
+
65
+ if ( user.lastName ) {
66
+ userData.last_name = user.lastName;
67
+ }
68
+
69
+ if ( user.password ) {
70
+ userData.password = user.password;
71
+ }
72
+
73
+ if ( user.roles ) {
74
+ userData.roles = user.roles;
75
+ }
76
+
77
+ const response = await this.rest< User >( {
78
+ method: 'POST',
79
+ path: '/wp/v2/users',
80
+ data: userData,
81
+ } );
82
+
83
+ return response;
84
+ }
85
+
86
+ /**
87
+ * Delete a user.
88
+ *
89
+ * @see https://developer.wordpress.org/rest-api/reference/users/#delete-a-user
90
+ * @param this
91
+ * @param userId The ID of the user.
92
+ */
93
+ async function deleteUser( this: RequestUtils, userId: number ) {
94
+ const response = await this.rest( {
95
+ method: 'DELETE',
96
+ path: `/wp/v2/users/${ userId }`,
97
+ params: { force: true, reassign: 1 },
98
+ } );
99
+
100
+ return response;
101
+ }
102
+
103
+ /**
104
+ * Delete all users except main root user.
105
+ *
106
+ * @param this
107
+ */
108
+ async function deleteAllUsers( this: RequestUtils ) {
109
+ const users = await listUsers.bind( this )();
110
+
111
+ // The users endpoint doesn't support batch request yet.
112
+ const responses = await Promise.all(
113
+ users
114
+ // Do not delete neither root user nor the current user.
115
+ .filter(
116
+ ( user: User ) =>
117
+ user.id !== 1 && user.name !== this.user.username
118
+ )
119
+ .map( ( user: User ) => deleteUser.bind( this )( user.id ) )
120
+ );
121
+
122
+ return responses;
123
+ }
124
+
125
+ export { createUser, deleteAllUsers };
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Delete all the widgets in the widgets screen.
3
+ *
4
+ * @this {import('./index').RequestUtils}
5
+ */
6
+ export async function deleteAllWidgets() {
7
+ const [ widgets, sidebars ] = await Promise.all( [
8
+ this.rest( { path: '/wp/v2/widgets' } ),
9
+ this.rest( { path: '/wp/v2/sidebars' } ),
10
+ ] );
11
+
12
+ await this.batchRest(
13
+ widgets.map( ( widget ) => ( {
14
+ method: 'DELETE',
15
+ path: `/wp/v2/widgets/${ widget.id }?force=true`,
16
+ } ) )
17
+ );
18
+
19
+ // The endpoint doesn't support batch requests yet.
20
+ await Promise.all(
21
+ sidebars.map( ( sidebar ) =>
22
+ this.rest( {
23
+ method: 'POST',
24
+ path: `/wp/v2/sidebars/${ sidebar.id }`,
25
+ data: { id: sidebar.id, widgets: [] },
26
+ } )
27
+ )
28
+ );
29
+ }
30
+
31
+ /**
32
+ * Add a widget block to the widget area.
33
+ *
34
+ * @this {import('./index').RequestUtils}
35
+ * @param {string} serializedBlock The serialized content of the inserted block HTML.
36
+ * @param {string} widgetAreaId The ID of the widget area.
37
+ */
38
+ export async function addWidgetBlock( serializedBlock, widgetAreaId ) {
39
+ const { id: blockId } = await this.rest( {
40
+ method: 'POST',
41
+ path: '/wp/v2/widgets',
42
+ data: {
43
+ id_base: 'block',
44
+ sidebar: widgetAreaId,
45
+ instance: {
46
+ raw: { content: serializedBlock },
47
+ },
48
+ },
49
+ } );
50
+
51
+ const { widgets } = await this.rest( {
52
+ path: `/wp/v2/sidebars/${ widgetAreaId }`,
53
+ } );
54
+
55
+ const updatedWidgets = new Set( widgets );
56
+ // Remove duplicate.
57
+ updatedWidgets.delete( blockId );
58
+ // Add to last block.
59
+ updatedWidgets.add( blockId );
60
+
61
+ await this.rest( {
62
+ method: 'PUT',
63
+ path: `/wp/v2/sidebars/${ widgetAreaId }`,
64
+ data: {
65
+ widgets: [ ...updatedWidgets ],
66
+ },
67
+ } );
68
+ }
package/src/test.ts ADDED
@@ -0,0 +1,204 @@
1
+ // Playwright fixtures use `use()` which is not a React hook.
2
+
3
+ /**
4
+ * External dependencies
5
+ */
6
+ import * as path from 'path';
7
+ import { test as base, expect, chromium } from '@playwright/test';
8
+ import type { ConsoleMessage } from '@playwright/test';
9
+ import getPort from 'get-port';
10
+
11
+ /**
12
+ * Internal dependencies
13
+ */
14
+ import {
15
+ Admin,
16
+ Editor,
17
+ PageUtils,
18
+ RequestUtils,
19
+ Metrics,
20
+ Lighthouse,
21
+ } from './index';
22
+
23
+ const STORAGE_STATE_PATH =
24
+ process.env.STORAGE_STATE_PATH ||
25
+ path.join( process.cwd(), 'artifacts/storage-states/admin.json' );
26
+
27
+ /**
28
+ * Set of console logging types observed to protect against unexpected yet
29
+ * handled (i.e. not catastrophic) errors or warnings. Each key corresponds
30
+ * to the Playwright ConsoleMessage type, its value the corresponding function
31
+ * on the console global object.
32
+ */
33
+ const OBSERVED_CONSOLE_MESSAGE_TYPES = [ 'warn', 'error' ] as const;
34
+
35
+ /**
36
+ * Adds a page event handler to emit uncaught exception to process if one of
37
+ * the observed console logging types is encountered.
38
+ *
39
+ * @param message The console message.
40
+ */
41
+ function observeConsoleLogging( message: ConsoleMessage ) {
42
+ const type = message.type();
43
+ if (
44
+ ! OBSERVED_CONSOLE_MESSAGE_TYPES.includes(
45
+ type as ( typeof OBSERVED_CONSOLE_MESSAGE_TYPES )[ number ]
46
+ )
47
+ ) {
48
+ return;
49
+ }
50
+
51
+ const text = message.text();
52
+
53
+ // An exception is made for _blanket_ deprecation warnings: Those
54
+ // which log regardless of whether a deprecated feature is in use.
55
+ if ( text.includes( 'This is a global warning' ) ) {
56
+ return;
57
+ }
58
+
59
+ // A chrome advisory warning about SameSite cookies is informational
60
+ // about future changes, tracked separately for improvement in core.
61
+ //
62
+ // See: https://core.trac.wordpress.org/ticket/37000
63
+ // See: https://www.chromestatus.com/feature/5088147346030592
64
+ // See: https://www.chromestatus.com/feature/5633521622188032
65
+ if (
66
+ text.includes( 'A cookie associated with a cross-site resource' ) ||
67
+ text.includes(
68
+ 'https://developer.mozilla.org/docs/Web/HTTP/Headers/Set-Cookie/SameSite'
69
+ )
70
+ ) {
71
+ return;
72
+ }
73
+
74
+ // Viewing posts on the front end can result in this error, which
75
+ // has nothing to do with Gutenberg.
76
+ if ( text.includes( 'net::ERR_UNKNOWN_URL_SCHEME' ) ) {
77
+ return;
78
+ }
79
+
80
+ // TODO: Not implemented yet.
81
+ // Network errors are ignored only if we are intentionally testing
82
+ // offline mode.
83
+ // if (
84
+ // text.includes( 'net::ERR_INTERNET_DISCONNECTED' ) &&
85
+ // isOfflineMode()
86
+ // ) {
87
+ // return;
88
+ // }
89
+
90
+ // As of WordPress 5.3.2 in Chrome 79, navigating to the block editor
91
+ // (Posts > Add New) will display a console warning about
92
+ // non - unique IDs.
93
+ // See: https://core.trac.wordpress.org/ticket/23165
94
+ if ( text.includes( 'elements with non-unique id #_wpnonce' ) ) {
95
+ return;
96
+ }
97
+
98
+ // Ignore all JQMIGRATE (jQuery migrate) deprecation warnings.
99
+ if ( text.includes( 'JQMIGRATE' ) ) {
100
+ return;
101
+ }
102
+
103
+ // https://bugzilla.mozilla.org/show_bug.cgi?id=1404468
104
+ if (
105
+ text.includes( 'Layout was forced before the page was fully loaded' )
106
+ ) {
107
+ return;
108
+ }
109
+
110
+ // Deprecated warnings coming from the third-party libraries.
111
+ if ( text.includes( 'MouseEvent.moz' ) ) {
112
+ return;
113
+ }
114
+
115
+ const logFunction =
116
+ type as ( typeof OBSERVED_CONSOLE_MESSAGE_TYPES )[ number ];
117
+
118
+ // Disable reason: We intentionally bubble up the console message
119
+ // which, unless the test explicitly anticipates the logging via
120
+ // @wordpress/jest-console matchers, will cause the intended test
121
+ // failure.
122
+ // eslint-disable-next-line no-console
123
+ console[ logFunction ]( text );
124
+ }
125
+
126
+ const test = base.extend<
127
+ {
128
+ admin: Admin;
129
+ editor: Editor;
130
+ pageUtils: PageUtils;
131
+ snapshotConfig: void;
132
+ metrics: Metrics;
133
+ lighthouse: Lighthouse;
134
+ },
135
+ {
136
+ requestUtils: RequestUtils;
137
+ lighthousePort: number;
138
+ }
139
+ >( {
140
+ admin: async ( { page, pageUtils, editor }, use ) => {
141
+ await use( new Admin( { page, pageUtils, editor } ) );
142
+ },
143
+ editor: async ( { page }, use ) => {
144
+ await use( new Editor( { page } ) );
145
+ },
146
+ page: async ( { page }, use ) => {
147
+ page.on( 'console', observeConsoleLogging );
148
+
149
+ await use( page );
150
+
151
+ // Clear local storage after each test.
152
+ // This needs to be wrapped with a try/catch because it can fail when
153
+ // the test is skipped (e.g. via fixme).
154
+ try {
155
+ await page.evaluate( () => {
156
+ window.localStorage.clear();
157
+ } );
158
+ } catch {
159
+ // noop.
160
+ }
161
+
162
+ await page.close();
163
+ },
164
+ pageUtils: async ( { page, browserName }, use ) => {
165
+ await use( new PageUtils( { page, browserName } ) );
166
+ },
167
+ requestUtils: [
168
+ async ( {}, use, workerInfo ) => {
169
+ const requestUtils = await RequestUtils.setup( {
170
+ baseURL: workerInfo.project.use.baseURL,
171
+ storageStatePath: STORAGE_STATE_PATH,
172
+ } );
173
+
174
+ await use( requestUtils );
175
+ },
176
+ { scope: 'worker', auto: true },
177
+ ],
178
+ // Spins up a new browser for use by the Lighthouse fixture
179
+ // so that Lighthouse can connect to the debugging port.
180
+ // As a worker-scoped fixture, this will only launch 1
181
+ // instance for the whole test worker, so multiple tests
182
+ // will share the same instance with the same port.
183
+ lighthousePort: [
184
+ async ( {}, use ) => {
185
+ const port = await getPort();
186
+ const browser = await chromium.launch( {
187
+ args: [ `--remote-debugging-port=${ port }` ],
188
+ } );
189
+
190
+ await use( port );
191
+
192
+ await browser.close();
193
+ },
194
+ { scope: 'worker' },
195
+ ],
196
+ lighthouse: async ( { page, lighthousePort }, use ) => {
197
+ await use( new Lighthouse( { page, port: lighthousePort } ) );
198
+ },
199
+ metrics: async ( { page }, use ) => {
200
+ await use( new Metrics( { page } ) );
201
+ },
202
+ } );
203
+
204
+ export { test, expect };
package/src/types.ts ADDED
@@ -0,0 +1,13 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ declare global {
5
+ interface Window {
6
+ // Silence the warning for `window.wp` in Playwright's evaluate functions.
7
+ wp: any;
8
+ // Helper function added by Metrics fixture for web-vitals.js.
9
+ __reportVitals__: ( data: string ) => void;
10
+ }
11
+ }
12
+
13
+ export {};
@@ -1,31 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createNewPost = createNewPost;
4
- /**
5
- * Creates new post.
6
- *
7
- * @param this
8
- * @param options Options to create new post.
9
- */
10
- async function createNewPost(options = {}) {
11
- const query = new URLSearchParams();
12
- const { postType, title, content, excerpt } = options;
13
- if (postType) {
14
- query.set('post_type', postType);
15
- }
16
- if (title) {
17
- query.set('post_title', title);
18
- }
19
- if (content) {
20
- query.set('content', content);
21
- }
22
- if (excerpt) {
23
- query.set('excerpt', excerpt);
24
- }
25
- await this.visitAdminPage('post-new.php', query.toString());
26
- await this.editor.setPreferences('core/edit-post', {
27
- welcomeGuide: options.showWelcomeGuide ?? false,
28
- fullscreenMode: options.fullscreenMode ?? false,
29
- });
30
- }
31
- //# sourceMappingURL=create-new-post.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"create-new-post.js","sourceRoot":"","sources":["../../src/admin/create-new-post.ts"],"names":[],"mappings":";;;AAcA;;;;;GAKG;AACI,KAAK,wBAEX,OAAO,GAAmB,EAAE;IAE5B,MAAM,KAAK,GAAG,IAAI,eAAe,EAAE,CAAC;IACpC,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;IAEtD,IAAK,QAAQ,EAAG,CAAC;QAChB,KAAK,CAAC,GAAG,CAAE,WAAW,EAAE,QAAQ,CAAE,CAAC;IACpC,CAAC;IACD,IAAK,KAAK,EAAG,CAAC;QACb,KAAK,CAAC,GAAG,CAAE,YAAY,EAAE,KAAK,CAAE,CAAC;IAClC,CAAC;IACD,IAAK,OAAO,EAAG,CAAC;QACf,KAAK,CAAC,GAAG,CAAE,SAAS,EAAE,OAAO,CAAE,CAAC;IACjC,CAAC;IACD,IAAK,OAAO,EAAG,CAAC;QACf,KAAK,CAAC,GAAG,CAAE,SAAS,EAAE,OAAO,CAAE,CAAC;IACjC,CAAC;IAED,MAAM,IAAI,CAAC,cAAc,CAAE,cAAc,EAAE,KAAK,CAAC,QAAQ,EAAE,CAAE,CAAC;IAE9D,MAAM,IAAI,CAAC,MAAM,CAAC,cAAc,CAAE,gBAAgB,EAAE;QACnD,YAAY,EAAE,OAAO,CAAC,gBAAgB,IAAI,KAAK;QAC/C,cAAc,EAAE,OAAO,CAAC,cAAc,IAAI,KAAK;KAC/C,CAAE,CAAC;AACL,CAAC"}
@@ -1,20 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.editPost = editPost;
4
- /**
5
- * Open the post with given ID in the editor.
6
- *
7
- * @param this
8
- * @param postId Post ID to visit.
9
- */
10
- async function editPost(postId) {
11
- const query = new URLSearchParams();
12
- query.set('post', String(postId));
13
- query.set('action', 'edit');
14
- await this.visitAdminPage('post.php', query.toString());
15
- await this.editor.setPreferences('core/edit-post', {
16
- welcomeGuide: false,
17
- fullscreenMode: false,
18
- });
19
- }
20
- //# sourceMappingURL=edit-post.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"edit-post.js","sourceRoot":"","sources":["../../src/admin/edit-post.ts"],"names":[],"mappings":";;;AAKA;;;;;GAKG;AACI,KAAK,mBAAiC,MAAuB;IACnE,MAAM,KAAK,GAAG,IAAI,eAAe,EAAE,CAAC;IAEpC,KAAK,CAAC,GAAG,CAAE,MAAM,EAAE,MAAM,CAAE,MAAM,CAAE,CAAE,CAAC;IACtC,KAAK,CAAC,GAAG,CAAE,QAAQ,EAAE,MAAM,CAAE,CAAC;IAE9B,MAAM,IAAI,CAAC,cAAc,CAAE,UAAU,EAAE,KAAK,CAAC,QAAQ,EAAE,CAAE,CAAC;IAE1D,MAAM,IAAI,CAAC,MAAM,CAAC,cAAc,CAAE,gBAAgB,EAAE;QACnD,YAAY,EAAE,KAAK;QACnB,cAAc,EAAE,KAAK;KACrB,CAAE,CAAC;AACL,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"get-page-error.js","sourceRoot":"","sources":["../../src/admin/get-page-error.ts"],"names":[],"mappings":";;;AAKA;;;;GAIG;AACH,MAAM,gBAAgB,GACrB,oKAAoK,CAAC;AAEtK;;;;;;;;;;GAUG;AACI,KAAK;IACX,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;IAC1C,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAE,gBAAgB,CAAE,CAAC;IAChD,OAAO,KAAK,CAAC,CAAC,CAAC,KAAK,CAAE,CAAC,CAAE,CAAC,CAAC,CAAC,IAAI,CAAC;AAClC,CAAC"}
@@ -1,40 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Admin = void 0;
4
- /**
5
- * Internal dependencies
6
- */
7
- const create_new_post_1 = require("./create-new-post");
8
- const get_page_error_1 = require("./get-page-error");
9
- const visit_admin_page_1 = require("./visit-admin-page");
10
- const edit_post_1 = require("./edit-post");
11
- const visit_site_editor_1 = require("./visit-site-editor");
12
- const wait_for_site_editor_1 = require("./wait-for-site-editor");
13
- class Admin {
14
- page;
15
- context;
16
- browser;
17
- pageUtils;
18
- editor;
19
- constructor({ page, pageUtils, editor }) {
20
- this.page = page;
21
- this.context = page.context();
22
- this.browser = this.context.browser();
23
- this.pageUtils = pageUtils;
24
- this.editor = editor;
25
- }
26
- /** @borrows createNewPost as this.createNewPost */
27
- createNewPost = create_new_post_1.createNewPost.bind(this);
28
- /** @borrows editPost as this.editPost */
29
- editPost = edit_post_1.editPost.bind(this);
30
- /** @borrows getPageError as this.getPageError */
31
- getPageError = get_page_error_1.getPageError.bind(this);
32
- /** @borrows visitAdminPage as this.visitAdminPage */
33
- visitAdminPage = visit_admin_page_1.visitAdminPage.bind(this);
34
- /** @borrows visitSiteEditor as this.visitSiteEditor */
35
- visitSiteEditor = visit_site_editor_1.visitSiteEditor.bind(this);
36
- /** @borrows waitForSiteEditor as this.waitForSiteEditor */
37
- waitForSiteEditor = wait_for_site_editor_1.waitForSiteEditor.bind(this);
38
- }
39
- exports.Admin = Admin;
40
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/admin/index.ts"],"names":[],"mappings":";;;AAKA;;GAEG;AACH,uDAAkD;AAClD,qDAAgD;AAChD,yDAAoD;AACpD,2CAAuC;AACvC,2DAAsD;AACtD,iEAA2D;AAU3D;IACC,IAAI,CAAO;IACX,OAAO,CAAiB;IACxB,OAAO,CAAU;IACjB,SAAS,CAAY;IACrB,MAAM,CAAS;IAEf,YAAa,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAyB;QAC9D,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,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACtB,CAAC;IAED,mDAAmD;IACnD,aAAa,GAAyB,+BAAa,CAAC,IAAI,CAAE,IAAI,CAAE,CAAC;IACjE,yCAAyC;IACzC,QAAQ,GAAoB,oBAAQ,CAAC,IAAI,CAAE,IAAI,CAAE,CAAC;IAClD,iDAAiD;IACjD,YAAY,GAAwB,6BAAY,CAAC,IAAI,CAAE,IAAI,CAAE,CAAC;IAC9D,qDAAqD;IACrD,cAAc,GAA0B,iCAAc,CAAC,IAAI,CAAE,IAAI,CAAE,CAAC;IACpE,uDAAuD;IACvD,eAAe,GAA2B,mCAAe,CAAC,IAAI,CAAE,IAAI,CAAE,CAAC;IACvE,2DAA2D;IAC3D,iBAAiB,GAChB,wCAAiB,CAAC,IAAI,CAAE,IAAI,CAAE,CAAC;CAChC"}
@@ -1,32 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.visitAdminPage = visitAdminPage;
4
- /**
5
- * External dependencies
6
- */
7
- const path_1 = require("path");
8
- /**
9
- * Visits admin page and handle errors.
10
- *
11
- * @param this
12
- * @param adminPath String to be serialized as pathname.
13
- * @param query String to be serialized as query portion of URL.
14
- */
15
- async function visitAdminPage(adminPath, query) {
16
- await this.page.goto((0, path_1.join)('wp-admin', adminPath) + (query ? `?${query}` : ''));
17
- // Handle upgrade required screen
18
- if (this.pageUtils.isCurrentURL('wp-admin/upgrade.php')) {
19
- // Click update
20
- await this.page.click('.button.button-large.button-primary');
21
- // Click continue
22
- await this.page.click('.button.button-large');
23
- }
24
- if (this.pageUtils.isCurrentURL('wp-login.php')) {
25
- throw new Error('Not logged in');
26
- }
27
- const error = await this.getPageError();
28
- if (error) {
29
- throw new Error('Unexpected error in page content: ' + error);
30
- }
31
- }
32
- //# sourceMappingURL=visit-admin-page.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"visit-admin-page.js","sourceRoot":"","sources":["../../src/admin/visit-admin-page.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,+BAA4B;AAO5B;;;;;;GAMG;AACI,KAAK,yBAEX,SAAiB,EACjB,KAAc;IAEd,MAAM,IAAI,CAAC,IAAI,CAAC,IAAI,CACnB,IAAA,WAAI,EAAE,UAAU,EAAE,SAAS,CAAE,GAAG,CAAE,KAAK,CAAC,CAAC,CAAC,IAAK,KAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAE,CAC9D,CAAC;IAEF,iCAAiC;IACjC,IAAK,IAAI,CAAC,SAAS,CAAC,YAAY,CAAE,sBAAsB,CAAE,EAAG,CAAC;QAC7D,eAAe;QACf,MAAM,IAAI,CAAC,IAAI,CAAC,KAAK,CAAE,qCAAqC,CAAE,CAAC;QAC/D,iBAAiB;QACjB,MAAM,IAAI,CAAC,IAAI,CAAC,KAAK,CAAE,sBAAsB,CAAE,CAAC;IACjD,CAAC;IAED,IAAK,IAAI,CAAC,SAAS,CAAC,YAAY,CAAE,cAAc,CAAE,EAAG,CAAC;QACrD,MAAM,IAAI,KAAK,CAAE,eAAe,CAAE,CAAC;IACpC,CAAC;IAED,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,YAAY,EAAE,CAAC;IACxC,IAAK,KAAK,EAAG,CAAC;QACb,MAAM,IAAI,KAAK,CAAE,oCAAoC,GAAG,KAAK,CAAE,CAAC;IACjE,CAAC;AACF,CAAC"}
@@ -1,45 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.visitSiteEditor = visitSiteEditor;
4
- /**
5
- * Visits the Site Editor main page.
6
- *
7
- * @param this
8
- * @param options Options to visit the site editor.
9
- */
10
- async function visitSiteEditor(options = {}) {
11
- const { postId, postType, path, canvas, activeView } = options;
12
- const query = new URLSearchParams();
13
- if (postId) {
14
- query.set('postId', String(postId));
15
- }
16
- if (postType) {
17
- query.set('postType', postType);
18
- }
19
- if (path) {
20
- query.set('path', path);
21
- }
22
- if (canvas) {
23
- query.set('canvas', canvas);
24
- }
25
- if (activeView) {
26
- query.set('activeView', activeView);
27
- }
28
- await this.visitAdminPage('site-editor.php', query.toString());
29
- if (!options.showWelcomeGuide) {
30
- await this.editor.setPreferences('core/edit-site', {
31
- welcomeGuide: false,
32
- welcomeGuideStyles: false,
33
- welcomeGuidePage: false,
34
- welcomeGuideTemplate: false,
35
- });
36
- }
37
- /**
38
- * Wait until the editor is loaded. The logic is a copy of the
39
- * `waitWhileSiteEditorLoading` function in the `edit-site` package.
40
- */
41
- if (!query.size || postId || canvas === 'edit') {
42
- await this.waitForSiteEditor();
43
- }
44
- }
45
- //# sourceMappingURL=visit-site-editor.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"visit-site-editor.js","sourceRoot":"","sources":["../../src/admin/visit-site-editor.ts"],"names":[],"mappings":";;;AAcA;;;;;GAKG;AACI,KAAK,0BAEX,OAAO,GAAsB,EAAE;IAE/B,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC;IAC/D,MAAM,KAAK,GAAG,IAAI,eAAe,EAAE,CAAC;IAEpC,IAAK,MAAM,EAAG,CAAC;QACd,KAAK,CAAC,GAAG,CAAE,QAAQ,EAAE,MAAM,CAAE,MAAM,CAAE,CAAE,CAAC;IACzC,CAAC;IACD,IAAK,QAAQ,EAAG,CAAC;QAChB,KAAK,CAAC,GAAG,CAAE,UAAU,EAAE,QAAQ,CAAE,CAAC;IACnC,CAAC;IACD,IAAK,IAAI,EAAG,CAAC;QACZ,KAAK,CAAC,GAAG,CAAE,MAAM,EAAE,IAAI,CAAE,CAAC;IAC3B,CAAC;IACD,IAAK,MAAM,EAAG,CAAC;QACd,KAAK,CAAC,GAAG,CAAE,QAAQ,EAAE,MAAM,CAAE,CAAC;IAC/B,CAAC;IACD,IAAK,UAAU,EAAG,CAAC;QAClB,KAAK,CAAC,GAAG,CAAE,YAAY,EAAE,UAAU,CAAE,CAAC;IACvC,CAAC;IAED,MAAM,IAAI,CAAC,cAAc,CAAE,iBAAiB,EAAE,KAAK,CAAC,QAAQ,EAAE,CAAE,CAAC;IAEjE,IAAK,CAAE,OAAO,CAAC,gBAAgB,EAAG,CAAC;QAClC,MAAM,IAAI,CAAC,MAAM,CAAC,cAAc,CAAE,gBAAgB,EAAE;YACnD,YAAY,EAAE,KAAK;YACnB,kBAAkB,EAAE,KAAK;YACzB,gBAAgB,EAAE,KAAK;YACvB,oBAAoB,EAAE,KAAK;SAC3B,CAAE,CAAC;IACL,CAAC;IAED;;;OAGG;IACH,IAAK,CAAE,KAAK,CAAC,IAAI,IAAI,MAAM,IAAI,MAAM,KAAK,MAAM,EAAG,CAAC;QACnD,MAAM,IAAI,CAAC,iBAAiB,EAAE,CAAC;IAChC,CAAC;AACF,CAAC"}
@@ -1,41 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.waitForSiteEditor = waitForSiteEditor;
4
- /**
5
- * Waits for the Site Editor to finish loading, i.e., for all resolvers
6
- * in the `core` store to finish and then pause for a short period.
7
- *
8
- * @param this
9
- */
10
- async function waitForSiteEditor() {
11
- await this.page.evaluate(() => {
12
- const MAX_LOADING_TIME = 10000;
13
- const MAX_PAUSE_TIME = 100;
14
- return new Promise((resolve) => {
15
- let pauseTimeout;
16
- function finish() {
17
- unsubscribe();
18
- clearTimeout(pauseTimeout);
19
- clearTimeout(maxTimeout);
20
- resolve();
21
- }
22
- const maxTimeout = setTimeout(finish, MAX_LOADING_TIME);
23
- function checkResolving() {
24
- const isResolving = window.wp.data
25
- .select('core')
26
- .hasResolvingSelectors();
27
- if (isResolving) {
28
- clearTimeout(pauseTimeout);
29
- pauseTimeout = undefined;
30
- return;
31
- }
32
- if (!pauseTimeout) {
33
- pauseTimeout = setTimeout(finish, MAX_PAUSE_TIME);
34
- }
35
- }
36
- const unsubscribe = window.wp.data.subscribe(checkResolving, 'core');
37
- checkResolving();
38
- });
39
- });
40
- }
41
- //# sourceMappingURL=wait-for-site-editor.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"wait-for-site-editor.js","sourceRoot":"","sources":["../../src/admin/wait-for-site-editor.ts"],"names":[],"mappings":";;;AAKA;;;;;GAKG;AACI,KAAK;IACX,MAAM,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAE,GAAG,EAAE;QAC9B,MAAM,gBAAgB,GAAG,KAAK,CAAC;QAC/B,MAAM,cAAc,GAAG,GAAG,CAAC;QAE3B,OAAO,IAAI,OAAO,CAAU,CAAE,OAAO,EAAG,EAAE;YACzC,IAAI,YAAyD,CAAC;YAE9D,SAAS,MAAM;gBACd,WAAW,EAAE,CAAC;gBACd,YAAY,CAAE,YAAY,CAAE,CAAC;gBAC7B,YAAY,CAAE,UAAU,CAAE,CAAC;gBAC3B,OAAO,EAAE,CAAC;YACX,CAAC;YAED,MAAM,UAAU,GAAG,UAAU,CAAE,MAAM,EAAE,gBAAgB,CAAE,CAAC;YAE1D,SAAS,cAAc;gBACtB,MAAM,WAAW,GAAG,MAAM,CAAC,EAAE,CAAC,IAAI;qBAChC,MAAM,CAAE,MAAM,CAAE;qBAChB,qBAAqB,EAAE,CAAC;gBAE1B,IAAK,WAAW,EAAG,CAAC;oBACnB,YAAY,CAAE,YAAY,CAAE,CAAC;oBAC7B,YAAY,GAAG,SAAS,CAAC;oBACzB,OAAO;gBACR,CAAC;gBAED,IAAK,CAAE,YAAY,EAAG,CAAC;oBACtB,YAAY,GAAG,UAAU,CAAE,MAAM,EAAE,cAAc,CAAE,CAAC;gBACrD,CAAC;YACF,CAAC;YAED,MAAM,WAAW,GAAG,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,SAAS,CAC3C,cAAc,EACd,MAAM,CACN,CAAC;YACF,cAAc,EAAE,CAAC;QAClB,CAAC,CAAE,CAAC;IACL,CAAC,CAAE,CAAC;AACL,CAAC"}
package/build/config.js DELETED
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.WP_BASE_URL = exports.WP_PASSWORD = exports.WP_USERNAME = exports.WP_ADMIN_USER = void 0;
4
- const { WP_USERNAME = 'admin', WP_PASSWORD = 'password', WP_BASE_URL = 'http://localhost:8889', } = process.env;
5
- exports.WP_USERNAME = WP_USERNAME;
6
- exports.WP_PASSWORD = WP_PASSWORD;
7
- exports.WP_BASE_URL = WP_BASE_URL;
8
- const WP_ADMIN_USER = {
9
- username: WP_USERNAME,
10
- password: WP_PASSWORD,
11
- };
12
- exports.WP_ADMIN_USER = WP_ADMIN_USER;
13
- //# sourceMappingURL=config.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":";;;AAAA,MAAM,EACL,WAAW,GAAG,OAAO,EACrB,WAAW,GAAG,UAAU,EACxB,WAAW,GAAG,uBAAuB,GACrC,GAAG,OAAO,CAAC,GAAG,CAAC;QAOQ,WAAW;QAAE,WAAW;QAAE,WAAW;AAL7D,MAAM,aAAa,GAAG;IACrB,QAAQ,EAAE,WAAW;IACrB,QAAQ,EAAE,WAAW;CACZ,CAAC;QAEF,aAAa"}