@wordpress/e2e-tests 6.5.1 → 7.1.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.
@@ -1,8 +1,7 @@
1
1
  /**
2
2
  * External dependencies
3
3
  */
4
- import { basename, join } from 'path';
5
- import { writeFileSync } from 'fs';
4
+ import path from 'path';
6
5
 
7
6
  /**
8
7
  * WordPress dependencies
@@ -24,8 +23,11 @@ import {
24
23
  import {
25
24
  readFile,
26
25
  deleteFile,
26
+ saveResultsFile,
27
+ getTraceFilePath,
27
28
  getTypingEventDurations,
28
29
  getLoadingDurations,
30
+ sequence,
29
31
  } from './utils';
30
32
 
31
33
  jest.setTimeout( 1000000 );
@@ -46,7 +48,7 @@ const results = {
46
48
  listViewOpen: [],
47
49
  };
48
50
 
49
- let id;
51
+ let postId;
50
52
 
51
53
  describe( 'Site Editor Performance', () => {
52
54
  beforeAll( async () => {
@@ -55,10 +57,11 @@ describe( 'Site Editor Performance', () => {
55
57
  await deleteAllTemplates( 'wp_template_part' );
56
58
 
57
59
  const html = readFile(
58
- join( __dirname, '../../assets/large-post.html' )
60
+ path.join( __dirname, '../../assets/large-post.html' )
59
61
  );
60
62
 
61
63
  await createNewPost( { postType: 'page' } );
64
+
62
65
  await page.evaluate( ( _html ) => {
63
66
  const { parse } = window.wp.blocks;
64
67
  const { dispatch } = window.wp.data;
@@ -75,48 +78,42 @@ describe( 'Site Editor Performance', () => {
75
78
  }, html );
76
79
  await saveDraft();
77
80
 
78
- id = await page.evaluate( () =>
81
+ postId = await page.evaluate( () =>
79
82
  new URL( document.location ).searchParams.get( 'post' )
80
83
  );
81
84
  } );
82
85
 
83
86
  afterAll( async () => {
87
+ saveResultsFile( __filename, results );
84
88
  await deleteAllTemplates( 'wp_template' );
85
89
  await deleteAllTemplates( 'wp_template_part' );
86
90
  await activateTheme( 'twentytwentyone' );
87
91
  } );
88
92
 
89
- beforeEach( async () => {
90
- await visitSiteEditor( {
91
- postId: id,
92
- postType: 'page',
93
- } );
94
- } );
95
-
96
- it( 'Loading', async () => {
97
- const editorURL = await page.url();
98
-
99
- // Number of sample measurements to take.
100
- const samples = 3;
101
- // Number of throwaway measurements to perform before recording samples.
102
- // Having at least one helps ensure that caching quirks don't manifest in
103
- // the results.
104
- const throwaway = 1;
105
-
106
- let i = throwaway + samples;
107
-
108
- // Measuring loading time.
109
- while ( i-- ) {
110
- await page.close();
111
- page = await browser.newPage();
112
-
113
- await page.goto( editorURL );
114
- await page.waitForSelector( '.edit-site-visual-editor', {
115
- timeout: 120000,
93
+ // Number of loading measurements to take.
94
+ const loadingSamples = 3;
95
+ // Number of throwaway measurements to perform before recording samples.
96
+ // Having at least one helps ensure that caching quirks don't manifest
97
+ // in the results.
98
+ const loadingSamplesThrowaway = 1;
99
+ const loadingIterations = sequence(
100
+ 1,
101
+ loadingSamples + loadingSamplesThrowaway
102
+ );
103
+ it.each( loadingIterations )(
104
+ `Loading (%i of ${ loadingIterations.length })`,
105
+ async ( i ) => {
106
+ // Open the test page in Site Editor.
107
+ await visitSiteEditor( {
108
+ postId,
109
+ postType: 'page',
116
110
  } );
117
- await canvas().waitForSelector( '.wp-block', { timeout: 120000 } );
118
111
 
119
- if ( i < samples ) {
112
+ // Wait for the first block.
113
+ await canvas().waitForSelector( '.wp-block' );
114
+
115
+ // Save results.
116
+ if ( i > loadingSamplesThrowaway ) {
120
117
  const {
121
118
  serverResponse,
122
119
  firstPaint,
@@ -133,53 +130,54 @@ describe( 'Site Editor Performance', () => {
133
130
  results.firstContentfulPaint.push( firstContentfulPaint );
134
131
  results.firstBlock.push( firstBlock );
135
132
  }
133
+
134
+ expect( true ).toBe( true );
136
135
  }
137
- } );
136
+ );
138
137
 
139
138
  it( 'Typing', async () => {
140
- await page.waitForSelector( '.edit-site-visual-editor', {
141
- timeout: 120000,
139
+ // Open the test page in Site Editor.
140
+ await visitSiteEditor( {
141
+ postId,
142
+ postType: 'page',
142
143
  } );
143
- await canvas().waitForSelector( '.wp-block', { timeout: 120000 } );
144
144
 
145
- // Measuring typing performance inside the post content.
146
- await canvas().waitForSelector(
147
- '[data-type="core/post-content"] [data-type="core/paragraph"]'
145
+ // Wait for the first paragraph to be ready.
146
+ const firstParagraph = await canvas().waitForXPath(
147
+ '//p[contains(text(), "Lorem ipsum dolor sit amet")]'
148
148
  );
149
+
150
+ // Get inside the post content.
149
151
  await enterEditMode();
150
- await canvas().focus(
151
- '[data-type="core/post-content"] [data-type="core/paragraph"]'
152
- );
152
+
153
+ // Insert a new paragraph right under the first one.
154
+ await firstParagraph.focus();
153
155
  await insertBlock( 'Paragraph' );
154
- let i = 200;
155
- const traceFile = __dirname + '/trace.json';
156
+
157
+ // Start tracing.
158
+ const traceFilePath = getTraceFilePath();
156
159
  await page.tracing.start( {
157
- path: traceFile,
160
+ path: traceFilePath,
158
161
  screenshots: false,
159
162
  categories: [ 'devtools.timeline' ],
160
163
  } );
161
- while ( i-- ) {
162
- await page.keyboard.type( 'x' );
163
- }
164
+
165
+ // Type "x" 200 times.
166
+ await page.keyboard.type( new Array( 200 ).fill( 'x' ).join( '' ) );
167
+
168
+ // Stop tracing and save results.
164
169
  await page.tracing.stop();
165
- const traceResults = JSON.parse( readFile( traceFile ) );
170
+ const traceResults = JSON.parse( readFile( traceFilePath ) );
166
171
  const [ keyDownEvents, keyPressEvents, keyUpEvents ] =
167
172
  getTypingEventDurations( traceResults );
168
-
169
- for ( let j = 0; j < keyDownEvents.length; j++ ) {
173
+ for ( let i = 0; i < keyDownEvents.length; i++ ) {
170
174
  results.type.push(
171
- keyDownEvents[ j ] + keyPressEvents[ j ] + keyUpEvents[ j ]
175
+ keyDownEvents[ i ] + keyPressEvents[ i ] + keyUpEvents[ i ]
172
176
  );
173
177
  }
174
178
 
175
- const resultsFilename = basename( __filename, '.js' ) + '.results.json';
176
-
177
- writeFileSync(
178
- join( __dirname, resultsFilename ),
179
- JSON.stringify( results, null, 2 )
180
- );
181
-
182
- deleteFile( traceFile );
179
+ // Delete the original trace file.
180
+ deleteFile( traceFilePath );
183
181
 
184
182
  expect( true ).toBe( true );
185
183
  } );
@@ -1,7 +1,8 @@
1
1
  /**
2
2
  * External dependencies
3
3
  */
4
- import { existsSync, readFileSync, unlinkSync } from 'fs';
4
+ import path from 'path';
5
+ import { existsSync, readFileSync, unlinkSync, writeFileSync } from 'fs';
5
6
 
6
7
  export function readFile( filePath ) {
7
8
  return existsSync( filePath )
@@ -15,6 +16,21 @@ export function deleteFile( filePath ) {
15
16
  }
16
17
  }
17
18
 
19
+ export function getTraceFilePath() {
20
+ return path.join( process.env.WP_ARTIFACTS_PATH, '/trace.json' );
21
+ }
22
+
23
+ export function saveResultsFile( testFilename, results ) {
24
+ const resultsFilename =
25
+ process.env.RESULTS_FILENAME ||
26
+ path.basename( testFilename, '.js' ) + '.performance-results.json';
27
+
28
+ return writeFileSync(
29
+ path.join( process.env.WP_ARTIFACTS_PATH, resultsFilename ),
30
+ JSON.stringify( results, null, 2 )
31
+ );
32
+ }
33
+
18
34
  function isEvent( item ) {
19
35
  return (
20
36
  item.cat === 'devtools.timeline' &&
@@ -124,3 +140,7 @@ export async function getLoadingDurations() {
124
140
  export function sum( arr ) {
125
141
  return arr.reduce( ( a, b ) => a + b, 0 );
126
142
  }
143
+
144
+ export function sequence( start, length ) {
145
+ return Array.from( { length }, ( _, i ) => i + start );
146
+ }
@@ -75,11 +75,13 @@ describe( 'Settings sidebar', () => {
75
75
 
76
76
  expect( templateCardBeforeNavigation ).toMatchObject( {
77
77
  title: 'Index',
78
- description: 'Displays posts.',
78
+ description:
79
+ 'Used as a fallback template for all pages when a more specific template is not defined.',
79
80
  } );
80
81
  expect( templateCardAfterNavigation ).toMatchObject( {
81
82
  title: 'Singular',
82
- description: 'Displays a single post or page.',
83
+ description:
84
+ 'Displays any single entry, such as a post or a page. This template will serve as a fallback when a more specific template (e.g., Single Post, Page, or Attachment) cannot be found.',
83
85
  } );
84
86
  } );
85
87
  } );
@@ -24,7 +24,6 @@ import {
24
24
  */
25
25
  // eslint-disable-next-line no-restricted-imports
26
26
  import { find, findAll } from 'puppeteer-testing-library';
27
- import { groupBy, mapValues } from 'lodash';
28
27
 
29
28
  describe( 'Widgets screen', () => {
30
29
  beforeEach( async () => {
@@ -945,13 +944,20 @@ async function saveWidgets() {
945
944
  async function getSerializedWidgetAreas() {
946
945
  const widgets = await rest( { path: '/wp/v2/widgets' } );
947
946
 
948
- const serializedWidgetAreas = mapValues(
949
- groupBy( widgets, 'sidebar' ),
950
- ( sidebarWidgets ) =>
951
- sidebarWidgets
952
- .map( ( widget ) => widget.rendered )
953
- .filter( Boolean )
954
- .join( '\n' )
947
+ const serializedWidgetAreas = widgets.reduce(
948
+ ( acc, { sidebar, rendered } ) => {
949
+ const currentWidgets = acc[ sidebar ] || '';
950
+ let newWidgets = Boolean( rendered ) ? rendered : '';
951
+ if ( currentWidgets.length && newWidgets.length ) {
952
+ newWidgets = '\n' + newWidgets;
953
+ }
954
+
955
+ return {
956
+ ...acc,
957
+ [ sidebar ]: currentWidgets + newWidgets,
958
+ };
959
+ },
960
+ {}
955
961
  );
956
962
 
957
963
  return serializedWidgetAreas;
@@ -1,347 +0,0 @@
1
- // Jest Snapshot v1, https://goo.gl/fbAQLP
2
-
3
- exports[`Multi-block selection should allow selecting outer edge if there is no sibling block 1`] = `
4
- "<!-- wp:paragraph -->
5
- <p>2</p>
6
- <!-- /wp:paragraph -->"
7
- `;
8
-
9
- exports[`Multi-block selection should always expand single line selection 1`] = `
10
- "<!-- wp:paragraph -->
11
- <p>2</p>
12
- <!-- /wp:paragraph -->"
13
- `;
14
-
15
- exports[`Multi-block selection should clear selection when clicking next to blocks 1`] = `
16
- "<!-- wp:paragraph -->
17
- <p>1</p>
18
- <!-- /wp:paragraph -->
19
-
20
- <!-- wp:paragraph -->
21
- <p>2</p>
22
- <!-- /wp:paragraph -->"
23
- `;
24
-
25
- exports[`Multi-block selection should copy and paste 1`] = `
26
- "<!-- wp:paragraph -->
27
- <p>1</p>
28
- <!-- /wp:paragraph -->
29
-
30
- <!-- wp:paragraph -->
31
- <p>2</p>
32
- <!-- /wp:paragraph -->"
33
- `;
34
-
35
- exports[`Multi-block selection should copy and paste 2`] = `""`;
36
-
37
- exports[`Multi-block selection should copy and paste 3`] = `
38
- "<!-- wp:paragraph -->
39
- <p>1</p>
40
- <!-- /wp:paragraph -->
41
-
42
- <!-- wp:paragraph -->
43
- <p>2</p>
44
- <!-- /wp:paragraph -->"
45
- `;
46
-
47
- exports[`Multi-block selection should copy multiple blocks 1`] = `
48
- "<!-- wp:paragraph -->
49
- <p>1</p>
50
- <!-- /wp:paragraph -->
51
-
52
- <!-- wp:paragraph -->
53
- <p>2</p>
54
- <!-- /wp:paragraph -->
55
-
56
- <!-- wp:paragraph -->
57
- <p>1</p>
58
- <!-- /wp:paragraph -->
59
-
60
- <!-- wp:paragraph -->
61
- <p>2</p>
62
- <!-- /wp:paragraph -->"
63
- `;
64
-
65
- exports[`Multi-block selection should cut and paste 1`] = `""`;
66
-
67
- exports[`Multi-block selection should cut and paste 2`] = `
68
- "<!-- wp:paragraph -->
69
- <p>1</p>
70
- <!-- /wp:paragraph -->
71
-
72
- <!-- wp:paragraph -->
73
- <p>2</p>
74
- <!-- /wp:paragraph -->"
75
- `;
76
-
77
- exports[`Multi-block selection should forward delete across blocks 1`] = `
78
- "<!-- wp:paragraph -->
79
- <p>1[</p>
80
- <!-- /wp:paragraph -->
81
-
82
- <!-- wp:paragraph -->
83
- <p>.</p>
84
- <!-- /wp:paragraph -->
85
-
86
- <!-- wp:heading -->
87
- <h2 class="wp-block-heading">]2</h2>
88
- <!-- /wp:heading -->"
89
- `;
90
-
91
- exports[`Multi-block selection should forward delete across blocks 2`] = `
92
- "<!-- wp:heading -->
93
- <h2 class="wp-block-heading">1&amp;2</h2>
94
- <!-- /wp:heading -->"
95
- `;
96
-
97
- exports[`Multi-block selection should gradually multi-select 1`] = `
98
- "<!-- wp:columns -->
99
- <div class="wp-block-columns"><!-- wp:column -->
100
- <div class="wp-block-column"><!-- wp:paragraph -->
101
- <p>1</p>
102
- <!-- /wp:paragraph -->
103
-
104
- <!-- wp:paragraph -->
105
- <p>2</p>
106
- <!-- /wp:paragraph --></div>
107
- <!-- /wp:column -->
108
-
109
- <!-- wp:column -->
110
- <div class="wp-block-column"></div>
111
- <!-- /wp:column --></div>
112
- <!-- /wp:columns -->"
113
- `;
114
-
115
- exports[`Multi-block selection should gradually multi-select 2`] = `
116
- "<!-- wp:columns -->
117
- <div class="wp-block-columns"></div>
118
- <!-- /wp:columns -->"
119
- `;
120
-
121
- exports[`Multi-block selection should handle Enter across blocks 1`] = `
122
- "<!-- wp:paragraph -->
123
- <p>1[</p>
124
- <!-- /wp:paragraph -->
125
-
126
- <!-- wp:paragraph -->
127
- <p>.</p>
128
- <!-- /wp:paragraph -->
129
-
130
- <!-- wp:heading -->
131
- <h2 class="wp-block-heading">]2</h2>
132
- <!-- /wp:heading -->"
133
- `;
134
-
135
- exports[`Multi-block selection should handle Enter across blocks 2`] = `
136
- "<!-- wp:paragraph -->
137
- <p>1</p>
138
- <!-- /wp:paragraph -->
139
-
140
- <!-- wp:paragraph -->
141
- <p>&amp;</p>
142
- <!-- /wp:paragraph -->
143
-
144
- <!-- wp:heading -->
145
- <h2 class="wp-block-heading">2</h2>
146
- <!-- /wp:heading -->"
147
- `;
148
-
149
- exports[`Multi-block selection should multi-select from within the list block 1`] = `
150
- "<!-- wp:paragraph -->
151
- <p>1</p>
152
- <!-- /wp:paragraph -->
153
-
154
- <!-- wp:list -->
155
- <ul><!-- wp:list-item -->
156
- <li>1</li>
157
- <!-- /wp:list-item --></ul>
158
- <!-- /wp:list -->"
159
- `;
160
-
161
- exports[`Multi-block selection should not multi select single block 1`] = `
162
- "<!-- wp:paragraph -->
163
- <p></p>
164
- <!-- /wp:paragraph -->
165
-
166
- <!-- wp:paragraph -->
167
- <p></p>
168
- <!-- /wp:paragraph -->"
169
- `;
170
-
171
- exports[`Multi-block selection should only trigger multi-selection when at the end 1`] = `
172
- "<!-- wp:paragraph -->
173
- <p>1.</p>
174
- <!-- /wp:paragraph -->
175
-
176
- <!-- wp:paragraph -->
177
- <p></p>
178
- <!-- /wp:paragraph -->"
179
- `;
180
-
181
- exports[`Multi-block selection should partially select with shift + click 1`] = `
182
- "<!-- wp:paragraph -->
183
- <p><strong>1</strong>[</p>
184
- <!-- /wp:paragraph -->
185
-
186
- <!-- wp:paragraph -->
187
- <p>]2</p>
188
- <!-- /wp:paragraph -->"
189
- `;
190
-
191
- exports[`Multi-block selection should partially select with shift + click 2`] = `
192
- "<!-- wp:paragraph -->
193
- <p><strong>1</strong>&amp;2</p>
194
- <!-- /wp:paragraph -->"
195
- `;
196
-
197
- exports[`Multi-block selection should place the caret at the end of last pasted paragraph (paste mid-block) 1`] = `
198
- "<!-- wp:paragraph -->
199
- <p>first paragraph</p>
200
- <!-- /wp:paragraph -->
201
-
202
- <!-- wp:paragraph -->
203
- <p>second paragr</p>
204
- <!-- /wp:paragraph -->
205
-
206
- <!-- wp:paragraph -->
207
- <p>first paragraph</p>
208
- <!-- /wp:paragraph -->
209
-
210
- <!-- wp:paragraph -->
211
- <p>second paragrap</p>
212
- <!-- /wp:paragraph -->
213
-
214
- <!-- wp:paragraph -->
215
- <p>aph</p>
216
- <!-- /wp:paragraph -->"
217
- `;
218
-
219
- exports[`Multi-block selection should place the caret at the end of last pasted paragraph (paste to empty editor) 1`] = `
220
- "<!-- wp:paragraph -->
221
- <p>first paragraph</p>
222
- <!-- /wp:paragraph -->
223
-
224
- <!-- wp:paragraph -->
225
- <p>second paragrap</p>
226
- <!-- /wp:paragraph -->"
227
- `;
228
-
229
- exports[`Multi-block selection should place the caret at the end of last pasted paragraph (replace) 1`] = `
230
- "<!-- wp:paragraph -->
231
- <p>first paragraph</p>
232
- <!-- /wp:paragraph -->
233
-
234
- <!-- wp:paragraph -->
235
- <p>second paragrap</p>
236
- <!-- /wp:paragraph -->"
237
- `;
238
-
239
- exports[`Multi-block selection should preserve dragged selection on move 1`] = `
240
- "<!-- wp:paragraph -->
241
- <p>2</p>
242
- <!-- /wp:paragraph -->
243
-
244
- <!-- wp:paragraph -->
245
- <p>3</p>
246
- <!-- /wp:paragraph -->
247
-
248
- <!-- wp:paragraph -->
249
- <p>1</p>
250
- <!-- /wp:paragraph -->"
251
- `;
252
-
253
- exports[`Multi-block selection should properly select multiple blocks if selected nested blocks belong to different parent 1`] = `
254
- "<!-- wp:group {"layout":{"type":"constrained"}} -->
255
- <div class="wp-block-group"><!-- wp:paragraph -->
256
- <p>first</p>
257
- <!-- /wp:paragraph -->
258
-
259
- <!-- wp:paragraph -->
260
- <p>group</p>
261
- <!-- /wp:paragraph --></div>
262
- <!-- /wp:group -->
263
-
264
- <!-- wp:group {"layout":{"type":"constrained"}} -->
265
- <div class="wp-block-group"><!-- wp:paragraph -->
266
- <p>second</p>
267
- <!-- /wp:paragraph -->
268
-
269
- <!-- wp:paragraph -->
270
- <p>group</p>
271
- <!-- /wp:paragraph --></div>
272
- <!-- /wp:group -->"
273
- `;
274
-
275
- exports[`Multi-block selection should return original focus after failed multi selection attempt 1`] = `
276
- "<!-- wp:paragraph -->
277
- <p>2</p>
278
- <!-- /wp:paragraph -->"
279
- `;
280
-
281
- exports[`Multi-block selection should select all from empty selection 1`] = `
282
- "<!-- wp:paragraph -->
283
- <p>1</p>
284
- <!-- /wp:paragraph -->
285
-
286
- <!-- wp:paragraph -->
287
- <p>2</p>
288
- <!-- /wp:paragraph -->"
289
- `;
290
-
291
- exports[`Multi-block selection should select all from empty selection 2`] = `""`;
292
-
293
- exports[`Multi-block selection should select separator (single element block) 1`] = `
294
- "<!-- wp:paragraph -->
295
- <p>a</p>
296
- <!-- /wp:paragraph -->
297
-
298
- <!-- wp:paragraph -->
299
- <p></p>
300
- <!-- /wp:paragraph -->
301
-
302
- <!-- wp:separator -->
303
- <hr class="wp-block-separator has-alpha-channel-opacity"/>
304
- <!-- /wp:separator -->"
305
- `;
306
-
307
- exports[`Multi-block selection should select separator (single element block) 2`] = `
308
- "<!-- wp:paragraph -->
309
- <p>&amp;</p>
310
- <!-- /wp:paragraph -->"
311
- `;
312
-
313
- exports[`Multi-block selection should set attributes for multiple paragraphs 1`] = `
314
- "<!-- wp:paragraph {"align":"center"} -->
315
- <p class="has-text-align-center">1</p>
316
- <!-- /wp:paragraph -->
317
-
318
- <!-- wp:paragraph {"align":"center"} -->
319
- <p class="has-text-align-center">2</p>
320
- <!-- /wp:paragraph -->"
321
- `;
322
-
323
- exports[`Multi-block selection should use selection direction to determine vertical edge 1`] = `
324
- "<!-- wp:paragraph -->
325
- <p>1<br>2.</p>
326
- <!-- /wp:paragraph -->
327
-
328
- <!-- wp:paragraph -->
329
- <p>3</p>
330
- <!-- /wp:paragraph -->"
331
- `;
332
-
333
- exports[`Multi-block selection should write over selection 1`] = `
334
- "<!-- wp:paragraph -->
335
- <p>1[</p>
336
- <!-- /wp:paragraph -->
337
-
338
- <!-- wp:paragraph -->
339
- <p>]2</p>
340
- <!-- /wp:paragraph -->"
341
- `;
342
-
343
- exports[`Multi-block selection should write over selection 2`] = `
344
- "<!-- wp:paragraph -->
345
- <p>1...2</p>
346
- <!-- /wp:paragraph -->"
347
- `;