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

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 (188) hide show
  1. package/build/admin/create-new-post.js +31 -0
  2. package/build/admin/create-new-post.js.map +1 -0
  3. package/build/admin/edit-post.js +20 -0
  4. package/build/admin/edit-post.js.map +1 -0
  5. package/{src/admin/get-page-error.ts → build/admin/get-page-error.js} +9 -12
  6. package/build/admin/get-page-error.js.map +1 -0
  7. package/build/admin/index.js +40 -0
  8. package/build/admin/index.js.map +1 -0
  9. package/build/admin/visit-admin-page.js +32 -0
  10. package/build/admin/visit-admin-page.js.map +1 -0
  11. package/build/admin/visit-site-editor.js +45 -0
  12. package/build/admin/visit-site-editor.js.map +1 -0
  13. package/build/admin/wait-for-site-editor.js +41 -0
  14. package/build/admin/wait-for-site-editor.js.map +1 -0
  15. package/build/config.js +13 -0
  16. package/build/config.js.map +1 -0
  17. package/build/editor/click-block-options-menu-item.js +17 -0
  18. package/build/editor/click-block-options-menu-item.js.map +1 -0
  19. package/build/editor/click-block-toolbar-button.js +16 -0
  20. package/build/editor/click-block-toolbar-button.js.map +1 -0
  21. package/build/editor/get-blocks.js +45 -0
  22. package/build/editor/get-blocks.js.map +1 -0
  23. package/build/editor/get-edited-post-content.js +15 -0
  24. package/build/editor/get-edited-post-content.js.map +1 -0
  25. package/build/editor/index.js +75 -0
  26. package/build/editor/index.js.map +1 -0
  27. package/build/editor/insert-block.js +23 -0
  28. package/build/editor/insert-block.js.map +1 -0
  29. package/build/editor/open-document-settings-sidebar.js +27 -0
  30. package/build/editor/open-document-settings-sidebar.js.map +1 -0
  31. package/build/editor/preview.js +21 -0
  32. package/build/editor/preview.js.map +1 -0
  33. package/build/editor/publish-post.js +45 -0
  34. package/build/editor/publish-post.js.map +1 -0
  35. package/build/editor/save-draft.js +18 -0
  36. package/build/editor/save-draft.js.map +1 -0
  37. package/build/editor/select-blocks.js +28 -0
  38. package/build/editor/select-blocks.js.map +1 -0
  39. package/build/editor/set-content.js +17 -0
  40. package/build/editor/set-content.js.map +1 -0
  41. package/build/editor/set-is-fixed-toolbar.js +18 -0
  42. package/build/editor/set-is-fixed-toolbar.js.map +1 -0
  43. package/build/editor/set-preferences.js +21 -0
  44. package/build/editor/set-preferences.js.map +1 -0
  45. package/build/editor/show-block-toolbar.js +19 -0
  46. package/build/editor/show-block-toolbar.js.map +1 -0
  47. package/build/editor/site-editor.js +44 -0
  48. package/build/editor/site-editor.js.map +1 -0
  49. package/build/editor/switch-editor-tool.js +33 -0
  50. package/build/editor/switch-editor-tool.js.map +1 -0
  51. package/build/editor/switch-to-legacy-canvas.js +18 -0
  52. package/build/editor/switch-to-legacy-canvas.js.map +1 -0
  53. package/build/editor/transform-block-to.js +24 -0
  54. package/build/editor/transform-block-to.js.map +1 -0
  55. package/build/index.js +19 -0
  56. package/build/index.js.map +1 -0
  57. package/build/lighthouse/index.js +61 -0
  58. package/build/lighthouse/index.js.map +1 -0
  59. package/build/metrics/index.js +314 -0
  60. package/build/metrics/index.js.map +1 -0
  61. package/build/page-utils/drag-files.js +119 -0
  62. package/build/page-utils/drag-files.js.map +1 -0
  63. package/build/page-utils/emulate-network-conditions.js +71 -0
  64. package/build/page-utils/emulate-network-conditions.js.map +1 -0
  65. package/build/page-utils/index.js +37 -0
  66. package/build/page-utils/index.js.map +1 -0
  67. package/build/page-utils/is-current-url.js +21 -0
  68. package/build/page-utils/is-current-url.js.map +1 -0
  69. package/build/page-utils/keycodes.js +41 -0
  70. package/build/page-utils/keycodes.js.map +1 -0
  71. package/build/page-utils/press-keys.js +141 -0
  72. package/build/page-utils/press-keys.js.map +1 -0
  73. package/{src → build}/page-utils/set-browser-viewport.js +12 -14
  74. package/build/page-utils/set-browser-viewport.js.map +1 -0
  75. package/build/request-utils/blocks.js +40 -0
  76. package/build/request-utils/blocks.js.map +1 -0
  77. package/build/request-utils/comments.js +52 -0
  78. package/build/request-utils/comments.js.map +1 -0
  79. package/build/request-utils/gutenberg-experiments.js +47 -0
  80. package/build/request-utils/gutenberg-experiments.js.map +1 -0
  81. package/build/request-utils/index.js +196 -0
  82. package/build/request-utils/index.js.map +1 -0
  83. package/build/request-utils/login.js +21 -0
  84. package/build/request-utils/login.js.map +1 -0
  85. package/build/request-utils/media.js +106 -0
  86. package/build/request-utils/media.js.map +1 -0
  87. package/build/request-utils/menus.js +116 -0
  88. package/build/request-utils/menus.js.map +1 -0
  89. package/build/request-utils/pages.js +53 -0
  90. package/build/request-utils/pages.js.map +1 -0
  91. package/build/request-utils/patterns.js +27 -0
  92. package/build/request-utils/patterns.js.map +1 -0
  93. package/build/request-utils/plugins.js +85 -0
  94. package/build/request-utils/plugins.js.map +1 -0
  95. package/build/request-utils/posts.js +42 -0
  96. package/build/request-utils/posts.js.map +1 -0
  97. package/build/request-utils/preferences.js +54 -0
  98. package/build/request-utils/preferences.js.map +1 -0
  99. package/{src/request-utils/records.ts → build/request-utils/records.js} +10 -15
  100. package/build/request-utils/records.js.map +1 -0
  101. package/build/request-utils/rest.js +181 -0
  102. package/build/request-utils/rest.js.map +1 -0
  103. package/build/request-utils/site-settings.js +33 -0
  104. package/build/request-utils/site-settings.js.map +1 -0
  105. package/build/request-utils/templates.js +54 -0
  106. package/build/request-utils/templates.js.map +1 -0
  107. package/build/request-utils/themes.js +69 -0
  108. package/build/request-utils/themes.js.map +1 -0
  109. package/build/request-utils/users.js +81 -0
  110. package/build/request-utils/users.js.map +1 -0
  111. package/build/request-utils/widgets.js +61 -0
  112. package/build/request-utils/widgets.js.map +1 -0
  113. package/build/test.js +189 -0
  114. package/build/test.js.map +1 -0
  115. package/build/types.js +3 -0
  116. package/build/types.js.map +1 -0
  117. package/build-types/admin/index.d.ts.map +1 -1
  118. package/build-types/config.d.ts.map +1 -1
  119. package/build-types/editor/index.d.ts.map +1 -1
  120. package/build-types/lighthouse/index.d.ts.map +1 -1
  121. package/build-types/metrics/index.d.ts.map +1 -1
  122. package/build-types/page-utils/index.d.ts.map +1 -1
  123. package/build-types/page-utils/press-keys.d.ts +1 -1
  124. package/build-types/page-utils/set-browser-viewport.d.ts +22 -12
  125. package/build-types/page-utils/set-browser-viewport.d.ts.map +1 -1
  126. package/build-types/request-utils/index.d.ts +2 -2
  127. package/build-types/request-utils/index.d.ts.map +1 -1
  128. package/build-types/request-utils/pages.d.ts +1 -1
  129. package/build-types/request-utils/pages.d.ts.map +1 -1
  130. package/build-types/request-utils/widgets.d.ts +2 -2
  131. package/build-types/request-utils/widgets.d.ts.map +1 -1
  132. package/build-types/types.d.ts.map +1 -1
  133. package/package.json +8 -5
  134. package/src/admin/create-new-post.ts +0 -47
  135. package/src/admin/edit-post.ts +0 -24
  136. package/src/admin/index.ts +0 -52
  137. package/src/admin/visit-admin-page.ts +0 -43
  138. package/src/admin/visit-site-editor.ts +0 -62
  139. package/src/admin/wait-for-site-editor.ts +0 -52
  140. package/src/config.ts +0 -12
  141. package/src/editor/click-block-options-menu-item.ts +0 -18
  142. package/src/editor/click-block-toolbar-button.ts +0 -21
  143. package/src/editor/get-blocks.ts +0 -75
  144. package/src/editor/get-edited-post-content.ts +0 -19
  145. package/src/editor/index.ts +0 -95
  146. package/src/editor/insert-block.ts +0 -54
  147. package/src/editor/open-document-settings-sidebar.ts +0 -31
  148. package/src/editor/preview.ts +0 -32
  149. package/src/editor/publish-post.ts +0 -51
  150. package/src/editor/save-draft.ts +0 -20
  151. package/src/editor/select-blocks.ts +0 -48
  152. package/src/editor/set-content.ts +0 -24
  153. package/src/editor/set-is-fixed-toolbar.ts +0 -20
  154. package/src/editor/set-preferences.ts +0 -37
  155. package/src/editor/show-block-toolbar.ts +0 -20
  156. package/src/editor/site-editor.ts +0 -55
  157. package/src/editor/switch-editor-tool.ts +0 -34
  158. package/src/editor/switch-to-legacy-canvas.ts +0 -20
  159. package/src/editor/transform-block-to.ts +0 -34
  160. package/src/index.ts +0 -8
  161. package/src/lighthouse/index.ts +0 -75
  162. package/src/metrics/index.ts +0 -441
  163. package/src/page-utils/drag-files.ts +0 -173
  164. package/src/page-utils/emulate-network-conditions.ts +0 -101
  165. package/src/page-utils/index.ts +0 -54
  166. package/src/page-utils/is-current-url.ts +0 -20
  167. package/src/page-utils/keycodes.ts +0 -48
  168. package/src/page-utils/press-keys.ts +0 -195
  169. package/src/request-utils/blocks.ts +0 -58
  170. package/src/request-utils/comments.ts +0 -80
  171. package/src/request-utils/gutenberg-experiments.ts +0 -62
  172. package/src/request-utils/index.ts +0 -222
  173. package/src/request-utils/login.ts +0 -34
  174. package/src/request-utils/media.ts +0 -102
  175. package/src/request-utils/menus.ts +0 -145
  176. package/src/request-utils/pages.ts +0 -75
  177. package/src/request-utils/patterns.ts +0 -31
  178. package/src/request-utils/plugins.ts +0 -103
  179. package/src/request-utils/posts.ts +0 -69
  180. package/src/request-utils/preferences.ts +0 -63
  181. package/src/request-utils/rest.ts +0 -222
  182. package/src/request-utils/site-settings.ts +0 -58
  183. package/src/request-utils/templates.ts +0 -83
  184. package/src/request-utils/themes.ts +0 -110
  185. package/src/request-utils/users.ts +0 -125
  186. package/src/request-utils/widgets.js +0 -68
  187. package/src/test.ts +0 -204
  188. package/src/types.ts +0 -13
@@ -1,80 +0,0 @@
1
- /**
2
- * Internal dependencies
3
- */
4
- import type { RequestUtils } from './index';
5
-
6
- export interface Comment {
7
- id: number;
8
- author: number;
9
- content: string;
10
- post: number;
11
- }
12
-
13
- export interface CreateCommentPayload {
14
- content: string;
15
- post: number;
16
- }
17
-
18
- export interface User {
19
- id: number;
20
- }
21
-
22
- /**
23
- * Create new comment using the REST API.
24
- *
25
- * @param this
26
- * @param payload
27
- */
28
- export async function createComment(
29
- this: RequestUtils,
30
- payload: CreateCommentPayload
31
- ) {
32
- const currentUser = await this.rest< User >( {
33
- path: '/wp/v2/users/me',
34
- method: 'GET',
35
- } );
36
-
37
- const author = currentUser.id;
38
-
39
- const comment = await this.rest< Comment >( {
40
- method: 'POST',
41
- path: '/wp/v2/comments',
42
- data: { ...payload, author },
43
- } );
44
-
45
- return comment;
46
- }
47
-
48
- /**
49
- * Delete all comments using the REST API.
50
- *
51
- * @param this
52
- * @param type - Optional comment type to delete.
53
- */
54
- export async function deleteAllComments( this: RequestUtils, type?: string ) {
55
- // List all comments.
56
- // https://developer.wordpress.org/rest-api/reference/comments/#list-comments
57
- const comments = await this.rest( {
58
- path: '/wp/v2/comments',
59
- params: {
60
- per_page: 100,
61
- status: 'all',
62
- type: type || 'comment',
63
- },
64
- } );
65
-
66
- // Delete all comments one by one.
67
- // https://developer.wordpress.org/rest-api/reference/comments/#delete-a-comment
68
- // "/wp/v2/comments" doesn't support batch requests yet.
69
- await Promise.all(
70
- comments.map( ( comment: Comment ) =>
71
- this.rest( {
72
- method: 'DELETE',
73
- path: `/wp/v2/comments/${ comment.id }`,
74
- params: {
75
- force: true,
76
- },
77
- } )
78
- )
79
- );
80
- }
@@ -1,62 +0,0 @@
1
- /**
2
- * Internal dependencies
3
- */
4
- import type { RequestUtils } from './index';
5
-
6
- /**
7
- * Sets the Gutenberg experiments.
8
- *
9
- * @param this
10
- * @param experiments Array of experimental flags to enable. Pass in an empty array to disable all experiments.
11
- * Use 'active_templates' for the template activation feature.
12
- */
13
- async function setGutenbergExperiments(
14
- this: RequestUtils,
15
- experiments: string[]
16
- ) {
17
- // Separate regular experiments from active_templates.
18
- // active_templates is stored as a separate option, not in the experiments array.
19
- const regularExperiments = experiments.filter(
20
- ( exp ) => exp !== 'active_templates'
21
- );
22
- const hasActiveTemplates = experiments.includes( 'active_templates' );
23
-
24
- // Build the experiments object with boolean values.
25
- // When empty array is passed, we send an empty object to disable all experiments.
26
- const experimentsData: Record< string, boolean > = {};
27
-
28
- for ( const experiment of regularExperiments ) {
29
- experimentsData[ experiment ] = true;
30
- }
31
-
32
- const settingsData: Record< string, unknown > = {
33
- 'gutenberg-experiments': experimentsData,
34
- };
35
-
36
- // active_templates lives in a separate top-level option. Sending `{}`
37
- // enables the experiment; sending `null` deletes the option and disables
38
- // it.
39
- if ( hasActiveTemplates ) {
40
- settingsData.active_templates = {};
41
- } else {
42
- // WP_REST_Settings_Controller rejects null updates when the stored
43
- // value does not match the `type: 'object'` schema (including when the
44
- // option is absent and `get_option` falls back to `false`), so we only
45
- // send null when the option actually exists.
46
- const currentSiteSettings =
47
- ( await this.getSiteSettings() ) as unknown as {
48
- active_templates?: unknown;
49
- };
50
- if ( currentSiteSettings.active_templates !== null ) {
51
- settingsData.active_templates = null;
52
- }
53
- }
54
-
55
- await this.rest( {
56
- path: '/wp/v2/settings',
57
- method: 'POST',
58
- data: settingsData,
59
- } );
60
- }
61
-
62
- export { setGutenbergExperiments };
@@ -1,222 +0,0 @@
1
- /**
2
- * External dependencies
3
- */
4
- import * as fs from 'fs/promises';
5
- import * as path from 'path';
6
- import { request } from '@playwright/test';
7
- import type { APIRequestContext, Cookie } from '@playwright/test';
8
-
9
- /**
10
- * Internal dependencies
11
- */
12
- import { WP_ADMIN_USER, WP_BASE_URL } from '../config';
13
- import type { User } from './login';
14
- import { login } from './login';
15
- import { listMedia, uploadMedia, deleteMedia, deleteAllMedia } from './media';
16
- import { createUser, deleteAllUsers } from './users';
17
- import { setupRest, rest, getMaxBatchSize, batchRest } from './rest';
18
- import { getPluginsMap, activatePlugin, deactivatePlugin } from './plugins';
19
- import { deleteAllTemplates, createTemplate } from './templates';
20
- import {
21
- activateTheme,
22
- getCurrentThemeGlobalStylesPostId,
23
- getThemeGlobalStylesRevisions,
24
- } from './themes';
25
- import { createBlock, deleteAllBlocks } from './blocks';
26
- import { createComment, deleteAllComments } from './comments';
27
- import { createPost, deleteAllPosts } from './posts';
28
- import {
29
- createClassicMenu,
30
- createNavigationMenu,
31
- deleteAllMenus,
32
- getNavigationMenus,
33
- } from './menus';
34
- import { deleteAllPages, createPage } from './pages';
35
- import { createRecord } from './records';
36
- import { resetPreferences, setPreferences } from './preferences';
37
- import { getSiteSettings, updateSiteSettings } from './site-settings';
38
- import { deleteAllWidgets, addWidgetBlock } from './widgets';
39
- import { deleteAllPatternCategories } from './patterns';
40
- import { setGutenbergExperiments } from './gutenberg-experiments';
41
-
42
- interface StorageState {
43
- cookies: Cookie[];
44
- nonce: string;
45
- rootURL: string;
46
- }
47
-
48
- class RequestUtils {
49
- request: APIRequestContext;
50
- user: User;
51
- maxBatchSize?: number;
52
- storageState?: StorageState;
53
- storageStatePath?: string;
54
- baseURL?: string;
55
-
56
- pluginsMap: Record< string, string > | null = null;
57
-
58
- static async setup( {
59
- user,
60
- storageStatePath,
61
- baseURL = WP_BASE_URL,
62
- }: {
63
- user?: User;
64
- storageStatePath?: string;
65
- baseURL?: string;
66
- } ) {
67
- let storageState: StorageState | undefined;
68
- if ( storageStatePath ) {
69
- await fs.mkdir( path.dirname( storageStatePath ), {
70
- recursive: true,
71
- } );
72
-
73
- try {
74
- storageState = JSON.parse(
75
- await fs.readFile( storageStatePath, 'utf-8' )
76
- );
77
- } catch ( error ) {
78
- if (
79
- error instanceof Error &&
80
- ( error as NodeJS.ErrnoException ).code === 'ENOENT'
81
- ) {
82
- // Ignore errors if the state is not found.
83
- } else {
84
- throw error;
85
- }
86
- }
87
- }
88
-
89
- const requestContext = await request.newContext( {
90
- baseURL,
91
- storageState: storageState && {
92
- cookies: storageState.cookies,
93
- origins: [],
94
- },
95
- } );
96
-
97
- const requestUtils = new this( requestContext, {
98
- user,
99
- storageState,
100
- storageStatePath,
101
- baseURL,
102
- } );
103
-
104
- return requestUtils;
105
- }
106
-
107
- constructor(
108
- requestContext: APIRequestContext,
109
- {
110
- user = WP_ADMIN_USER,
111
- storageState,
112
- storageStatePath,
113
- baseURL = WP_BASE_URL,
114
- }: {
115
- user?: User;
116
- storageState?: StorageState;
117
- storageStatePath?: string;
118
- baseURL?: string;
119
- } = {}
120
- ) {
121
- this.user = user;
122
- this.request = requestContext;
123
- this.storageStatePath = storageStatePath;
124
- this.storageState = storageState;
125
- this.baseURL = baseURL;
126
- }
127
-
128
- /** @borrows login as this.login */
129
- login: typeof login = login.bind( this );
130
- /** @borrows setupRest as this.setupRest */
131
- setupRest: typeof setupRest = setupRest.bind( this );
132
- // .bind() drops the generic types. Re-casting it to keep the type signature.
133
- rest: typeof rest = rest.bind( this ) as typeof rest;
134
- /** @borrows getMaxBatchSize as this.getMaxBatchSize */
135
- getMaxBatchSize: typeof getMaxBatchSize = getMaxBatchSize.bind( this );
136
- // .bind() drops the generic types. Re-casting it to keep the type signature.
137
- batchRest: typeof batchRest = batchRest.bind( this ) as typeof batchRest;
138
- // .bind() drops the generic types. Re-casting it to keep the type signature.
139
- createRecord: typeof createRecord = createRecord.bind(
140
- this
141
- ) as typeof createRecord;
142
- /** @borrows getPluginsMap as this.getPluginsMap */
143
- getPluginsMap: typeof getPluginsMap = getPluginsMap.bind( this );
144
- /** @borrows activatePlugin as this.activatePlugin */
145
- activatePlugin: typeof activatePlugin = activatePlugin.bind( this );
146
- /** @borrows deactivatePlugin as this.deactivatePlugin */
147
- deactivatePlugin: typeof deactivatePlugin = deactivatePlugin.bind( this );
148
- /** @borrows activateTheme as this.activateTheme */
149
- activateTheme: typeof activateTheme = activateTheme.bind( this );
150
- /** @borrows createBlock as this.createBlock */
151
- createBlock: typeof createBlock = createBlock.bind( this );
152
- /** @borrows deleteAllBlocks as this.deleteAllBlocks */
153
- deleteAllBlocks = deleteAllBlocks.bind( this );
154
- /** @borrows createPost as this.createPost */
155
- createPost: typeof createPost = createPost.bind( this );
156
- /** @borrows deleteAllPosts as this.deleteAllPosts */
157
- deleteAllPosts: typeof deleteAllPosts = deleteAllPosts.bind( this );
158
- /** @borrows createClassicMenu as this.createClassicMenu */
159
- createClassicMenu: typeof createClassicMenu =
160
- createClassicMenu.bind( this );
161
- /** @borrows createNavigationMenu as this.createNavigationMenu */
162
- createNavigationMenu: typeof createNavigationMenu =
163
- createNavigationMenu.bind( this );
164
- /** @borrows deleteAllMenus as this.deleteAllMenus */
165
- deleteAllMenus: typeof deleteAllMenus = deleteAllMenus.bind( this );
166
- /** @borrows getNavigationMenus as this.getNavigationMenus */
167
- getNavigationMenus: typeof getNavigationMenus =
168
- getNavigationMenus.bind( this );
169
- /** @borrows createComment as this.createComment */
170
- createComment: typeof createComment = createComment.bind( this );
171
- /** @borrows deleteAllComments as this.deleteAllComments */
172
- deleteAllComments: typeof deleteAllComments =
173
- deleteAllComments.bind( this );
174
- /** @borrows deleteAllWidgets as this.deleteAllWidgets */
175
- deleteAllWidgets: typeof deleteAllWidgets = deleteAllWidgets.bind( this );
176
- /** @borrows addWidgetBlock as this.addWidgetBlock */
177
- addWidgetBlock: typeof addWidgetBlock = addWidgetBlock.bind( this );
178
- /** @borrows deleteAllTemplates as this.deleteAllTemplates */
179
- deleteAllTemplates: typeof deleteAllTemplates =
180
- deleteAllTemplates.bind( this );
181
- /** @borrows createTemplate as this.createTemplate */
182
- createTemplate: typeof createTemplate = createTemplate.bind( this );
183
- /** @borrows resetPreferences as this.resetPreferences */
184
- resetPreferences: typeof resetPreferences = resetPreferences.bind( this );
185
- /** @borrows setPreferences as this.setPreferences */
186
- setPreferences: typeof setPreferences = setPreferences.bind( this );
187
- /** @borrows listMedia as this.listMedia */
188
- listMedia: typeof listMedia = listMedia.bind( this );
189
- /** @borrows uploadMedia as this.uploadMedia */
190
- uploadMedia: typeof uploadMedia = uploadMedia.bind( this );
191
- /** @borrows deleteMedia as this.deleteMedia */
192
- deleteMedia: typeof deleteMedia = deleteMedia.bind( this );
193
- /** @borrows deleteAllMedia as this.deleteAllMedia */
194
- deleteAllMedia: typeof deleteAllMedia = deleteAllMedia.bind( this );
195
- /** @borrows createUser as this.createUser */
196
- createUser: typeof createUser = createUser.bind( this );
197
- /** @borrows deleteAllUsers as this.deleteAllUsers */
198
- deleteAllUsers: typeof deleteAllUsers = deleteAllUsers.bind( this );
199
- /** @borrows getSiteSettings as this.getSiteSettings */
200
- getSiteSettings: typeof getSiteSettings = getSiteSettings.bind( this );
201
- /** @borrows updateSiteSettings as this.updateSiteSettings */
202
- updateSiteSettings: typeof updateSiteSettings =
203
- updateSiteSettings.bind( this );
204
- /** @borrows deleteAllPages as this.deleteAllPages */
205
- deleteAllPages: typeof deleteAllPages = deleteAllPages.bind( this );
206
- /** @borrows createPage as this.createPage */
207
- createPage: typeof createPage = createPage.bind( this );
208
- /** @borrows getCurrentThemeGlobalStylesPostId as this.getCurrentThemeGlobalStylesPostId */
209
- getCurrentThemeGlobalStylesPostId: typeof getCurrentThemeGlobalStylesPostId =
210
- getCurrentThemeGlobalStylesPostId.bind( this );
211
- /** @borrows getThemeGlobalStylesRevisions as this.getThemeGlobalStylesRevisions */
212
- getThemeGlobalStylesRevisions: typeof getThemeGlobalStylesRevisions =
213
- getThemeGlobalStylesRevisions.bind( this );
214
- /** @borrows deleteAllPatternCategories as this.deleteAllPatternCategories */
215
- deleteAllPatternCategories = deleteAllPatternCategories.bind( this );
216
- /** @borrows setGutenbergExperiments as this.setGutenbergExperiments */
217
- setGutenbergExperiments: typeof setGutenbergExperiments =
218
- setGutenbergExperiments.bind( this );
219
- }
220
-
221
- export type { StorageState };
222
- export { RequestUtils };
@@ -1,34 +0,0 @@
1
- /**
2
- * Internal dependencies
3
- */
4
- import type { RequestUtils } from './index';
5
-
6
- export interface User {
7
- username: string;
8
- password: string;
9
- }
10
-
11
- async function login( this: RequestUtils, user: User = this.user ) {
12
- // Login to admin using request context.
13
- let response = await this.request.post( 'wp-login.php', {
14
- failOnStatusCode: true,
15
- form: {
16
- log: user.username,
17
- pwd: user.password,
18
- },
19
- } );
20
- await response.dispose();
21
-
22
- // Get the nonce.
23
- response = await this.request.get(
24
- 'wp-admin/admin-ajax.php?action=rest-nonce',
25
- {
26
- failOnStatusCode: true,
27
- }
28
- );
29
- const nonce = await response.text();
30
-
31
- return nonce;
32
- }
33
-
34
- export { login };
@@ -1,102 +0,0 @@
1
- /**
2
- * External dependencies
3
- */
4
- import * as fs from 'fs';
5
-
6
- /**
7
- * Internal dependencies
8
- */
9
- import type { RequestUtils } from './index';
10
-
11
- export interface Media {
12
- id: number;
13
- title: {
14
- raw: string;
15
- rendered: string;
16
- };
17
- source_url: string;
18
- slug: string;
19
- alt_text: string;
20
- caption: { rendered: string };
21
- link: string;
22
- }
23
-
24
- /**
25
- * List all media files.
26
- *
27
- * @see https://developer.wordpress.org/rest-api/reference/media/#list-media
28
- * @param this
29
- */
30
- async function listMedia( this: RequestUtils ) {
31
- const response = await this.rest< Media[] >( {
32
- method: 'GET',
33
- path: '/wp/v2/media',
34
- params: {
35
- per_page: 100,
36
- },
37
- } );
38
-
39
- return response;
40
- }
41
-
42
- /**
43
- * Upload a media file.
44
- *
45
- * @see https://developer.wordpress.org/rest-api/reference/media/#create-a-media-item
46
- * @param this
47
- * @param filePathOrData The path or data of the file being uploaded.
48
- */
49
- async function uploadMedia(
50
- this: RequestUtils,
51
- filePathOrData: string | fs.ReadStream
52
- ) {
53
- const file =
54
- typeof filePathOrData === 'string'
55
- ? fs.createReadStream( filePathOrData )
56
- : filePathOrData;
57
-
58
- const response = await this.rest< Media >( {
59
- method: 'POST',
60
- path: '/wp/v2/media',
61
- multipart: {
62
- file,
63
- },
64
- } );
65
-
66
- return response;
67
- }
68
-
69
- /**
70
- * delete a media file.
71
- *
72
- * @see https://developer.wordpress.org/rest-api/reference/media/#delete-a-media-item
73
- * @param this
74
- * @param mediaId The ID of the media file.
75
- */
76
- async function deleteMedia( this: RequestUtils, mediaId: number ) {
77
- const response = await this.rest( {
78
- method: 'DELETE',
79
- path: `/wp/v2/media/${ mediaId }`,
80
- params: { force: true },
81
- } );
82
-
83
- return response;
84
- }
85
-
86
- /**
87
- * delete all media files.
88
- *
89
- * @param this
90
- */
91
- async function deleteAllMedia( this: RequestUtils ) {
92
- const files = await this.listMedia();
93
-
94
- // The media endpoint doesn't support batch request yet.
95
- const responses = await Promise.all(
96
- files.map( ( media ) => this.deleteMedia( media.id ) )
97
- );
98
-
99
- return responses;
100
- }
101
-
102
- export { listMedia, uploadMedia, deleteMedia, deleteAllMedia };
@@ -1,145 +0,0 @@
1
- /**
2
- * Internal dependencies
3
- */
4
- import type { RequestUtils } from './index';
5
-
6
- export interface MenuData {
7
- title: string;
8
- content: string;
9
- }
10
- export interface NavigationMenu {
11
- id: number;
12
- content: string;
13
- status: 'publish' | 'future' | 'draft' | 'pending' | 'private';
14
- }
15
-
16
- /**
17
- * Create a classic menu
18
- *
19
- * @param name Menu name.
20
- * @return Menu content.
21
- */
22
- export async function createClassicMenu( this: RequestUtils, name: string ) {
23
- const menuItems = [
24
- {
25
- title: 'Custom link',
26
- url: 'http://localhost:8889/',
27
- type: 'custom',
28
- menu_order: 1,
29
- },
30
- ];
31
-
32
- const menu = await this.rest< NavigationMenu >( {
33
- method: 'POST',
34
- path: `/wp/v2/menus/`,
35
- data: {
36
- name,
37
- },
38
- } );
39
-
40
- await this.batchRest(
41
- menuItems.map( ( menuItem ) => ( {
42
- method: 'POST',
43
- path: `/wp/v2/menu-items`,
44
- body: {
45
- menus: menu.id,
46
- object_id: undefined,
47
- ...menuItem,
48
- parent: undefined,
49
- },
50
- } ) )
51
- );
52
-
53
- return menu;
54
- }
55
-
56
- /**
57
- * Create a navigation menu
58
- *
59
- * @param menuData navigation menu post data.
60
- * @return Menu content.
61
- */
62
- export async function createNavigationMenu(
63
- this: RequestUtils,
64
- menuData: MenuData
65
- ) {
66
- return this.createRecord< NavigationMenu >( 'navigation', {
67
- status: 'publish',
68
- ...menuData,
69
- } );
70
- }
71
-
72
- /**
73
- * Delete all navigation and classic menus
74
- *
75
- */
76
- export async function deleteAllMenus( this: RequestUtils ) {
77
- const navMenus = await this.rest< NavigationMenu[] >( {
78
- path: `/wp/v2/navigation/`,
79
- data: {
80
- status: [
81
- 'publish',
82
- 'pending',
83
- 'draft',
84
- 'auto-draft',
85
- 'future',
86
- 'private',
87
- 'inherit',
88
- 'trash',
89
- ],
90
- },
91
- } );
92
-
93
- if ( navMenus.length ) {
94
- await this.batchRest(
95
- navMenus.map( ( menu ) => ( {
96
- method: 'DELETE',
97
- path: `/wp/v2/navigation/${ menu.id }?force=true`,
98
- } ) )
99
- );
100
- }
101
-
102
- const classicMenus = await this.rest< NavigationMenu[] >( {
103
- path: `/wp/v2/menus/`,
104
- data: {
105
- status: [
106
- 'publish',
107
- 'pending',
108
- 'draft',
109
- 'auto-draft',
110
- 'future',
111
- 'private',
112
- 'inherit',
113
- 'trash',
114
- ],
115
- },
116
- } );
117
-
118
- if ( classicMenus.length ) {
119
- await this.batchRest(
120
- classicMenus.map( ( menu ) => ( {
121
- method: 'DELETE',
122
- path: `/wp/v2/menus/${ menu.id }?force=true`,
123
- } ) )
124
- );
125
- }
126
- }
127
-
128
- /**
129
- * Get latest navigation menus
130
- *
131
- * @param args
132
- * @param args.status
133
- * @return {string} Menu content.
134
- */
135
- export async function getNavigationMenus(
136
- this: RequestUtils,
137
- args: { status: 'publish' }
138
- ) {
139
- const navigationMenus = await this.rest< NavigationMenu[] >( {
140
- method: 'GET',
141
- path: `/wp/v2/navigation/`,
142
- data: args,
143
- } );
144
- return navigationMenus;
145
- }