@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,110 +0,0 @@
1
- /**
2
- * Internal dependencies
3
- */
4
- import type { RequestUtils } from './index';
5
- import { WP_BASE_URL } from '../config';
6
-
7
- const THEMES_URL = new URL( 'wp-admin/themes.php', WP_BASE_URL ).href;
8
-
9
- async function activateTheme(
10
- this: RequestUtils,
11
- themeSlug: string
12
- ): Promise< void > {
13
- let response = await this.request.get( THEMES_URL );
14
- const html = await response.text();
15
- const optionalFolder = '([a-z0-9-]+%2F)?';
16
-
17
- // The `optionalFolder` regex part matches paths with a folder,
18
- // so it will return the first match, which might contain a folder.
19
- // First try to honor the included theme slug, that is, without a folder.
20
- let matchGroup = html.match(
21
- `action=activate&amp;stylesheet=${ encodeURIComponent(
22
- themeSlug
23
- ) }&amp;_wpnonce=[a-z0-9]+`
24
- );
25
-
26
- // If the theme is not found, try to match the theme slug with a folder.
27
- if ( ! matchGroup ) {
28
- matchGroup = html.match(
29
- `action=activate&amp;stylesheet=${ optionalFolder }${ encodeURIComponent(
30
- themeSlug
31
- ) }&amp;_wpnonce=[a-z0-9]+`
32
- );
33
- }
34
-
35
- if ( ! matchGroup ) {
36
- if ( html.includes( `data-slug="${ themeSlug }"` ) ) {
37
- // The theme is already activated.
38
- return;
39
- }
40
-
41
- throw new Error( `The theme "${ themeSlug }" is not installed` );
42
- }
43
-
44
- const [ activateQuery ] = matchGroup;
45
- const activateLink =
46
- THEMES_URL + `?${ activateQuery }`.replace( /&amp;/g, '&' );
47
-
48
- response = await this.request.get( activateLink );
49
-
50
- await response.dispose();
51
- }
52
-
53
- // https://developer.wordpress.org/rest-api/reference/themes/#definition
54
- async function getCurrentThemeGlobalStylesPostId( this: RequestUtils ) {
55
- type ThemeItem = {
56
- stylesheet: string;
57
- status: string;
58
- _links: { 'wp:user-global-styles': { href: string }[] };
59
- };
60
- const themes = await this.rest< ThemeItem[] >( {
61
- path: '/wp/v2/themes',
62
- } );
63
- let themeGlobalStylesId: string = '';
64
- if ( themes && themes.length ) {
65
- const currentTheme: ThemeItem | undefined = themes.find(
66
- ( { status } ) => status === 'active'
67
- );
68
-
69
- const globalStylesURL =
70
- currentTheme?._links?.[ 'wp:user-global-styles' ]?.[ 0 ]?.href;
71
- if ( globalStylesURL ) {
72
- // Extract the ID from the URL. The URL format depends on
73
- // the permalink structure:
74
- // - Plain: ?rest_route=/wp/v2/global-styles/123
75
- // - Pretty: /wp-json/wp/v2/global-styles/123
76
- const idMatch = globalStylesURL.match(
77
- /\/wp\/v2\/global-styles\/(\d+)/
78
- );
79
- if ( idMatch ) {
80
- themeGlobalStylesId = idMatch[ 1 ];
81
- }
82
- }
83
- }
84
- return themeGlobalStylesId;
85
- }
86
-
87
- /**
88
- * Deletes all post revisions using the REST API.
89
- *
90
- * @param {} this RequestUtils.
91
- * @param {string|number} parentId Post attributes.
92
- */
93
- async function getThemeGlobalStylesRevisions(
94
- this: RequestUtils,
95
- parentId: number | string
96
- ) {
97
- // Lists all global styles revisions.
98
- return await this.rest< Record< string, Object >[] >( {
99
- path: `/wp/v2/global-styles/${ parentId }/revisions`,
100
- params: {
101
- per_page: 100,
102
- },
103
- } );
104
- }
105
-
106
- export {
107
- activateTheme,
108
- getCurrentThemeGlobalStylesPostId,
109
- getThemeGlobalStylesRevisions,
110
- };
@@ -1,125 +0,0 @@
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 };
@@ -1,68 +0,0 @@
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 DELETED
@@ -1,204 +0,0 @@
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 DELETED
@@ -1,13 +0,0 @@
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 {};