/* eslint-disable playwright/expect-expect */ import { test, expect, Metrics } from '@wordpress/e2e-test-utils-playwright'; import { PerfUtils } from '../fixtures'; import { sum } from '../utils.js'; // See https://github.com/WordPress/gutenberg/issues/51383#issuecomment-1613460429 const BROWSER_IDLE_WAIT = 1000; const kebabCase = ( s ) => s.replace( /([A-Z])/g, '-$1' ).toLowerCase(); const results = { serverResponse: [], firstPaint: [], domContentLoaded: [], loaded: [], firstContentfulPaint: [], firstBlock: [], type: [], typeWithoutInspector: [], typeWithTopToolbar: [], typeContainer: [], focus: [], firstFocus: [], selectAll: [], undo: [], listViewOpen: [], inserterOpen: [], inserterHover: [], inserterSearch: [], loadPatterns: [], }; test.describe( 'Post Editor Performance', () => { test.use( { perfUtils: async ( { page }, use ) => { await use( new PerfUtils( { page } ) ); }, metrics: async ( { page }, use ) => { await use( new Metrics( { page } ) ); }, } ); test.afterAll( async ( {}, testInfo ) => { await testInfo.attach( 'results', { body: JSON.stringify( results, null, 2 ), contentType: 'application/json', } ); } ); test.describe( 'Loading', () => { let draftId = null; test( 'Setup the test post', async ( { admin, requestUtils, perfUtils, } ) => { await admin.createNewPost(); await perfUtils.loadBlocksForLargePost(); draftId = await perfUtils.saveDraft(); // Set preferences via REST so that welcomeGuide and fullscreenMode // are reliably persisted before the timed iterations start. await requestUtils.setPreferences( 'core/edit-post', { welcomeGuide: false, fullscreenMode: false, } ); } ); const samples = 10; const throwaway = 1; // One more load is traced and not counted, as tracing slows it down. const iterations = samples + throwaway + 1; for ( let i = 1; i <= iterations; i++ ) { test( `Run the test (${ i } of ${ iterations })`, async ( { admin, perfUtils, metrics, } ) => { const isTraced = i === iterations; // Start tracing before navigating so the page load is captured. if ( isTraced ) { await metrics.startTracing(); } // Open the test draft. await admin.page.goto( 'wp-admin/post.php?post=' + draftId + '&action=edit' ); // Wait for the first block. const canvas = await perfUtils.getCanvas(); await canvas.locator( '.wp-block' ).first().waitFor(); // Capture timing metrics before `stopTracing()`, which // blocks for the trace download/parse and would otherwise // inflate `timeSinceResponseEnd` by seconds. const loadingDurations = await metrics.getLoadingDurations(); if ( isTraced ) { await metrics.stopTracing( 'post-editor-first-block' ); } // Save the results. if ( i > throwaway && ! isTraced ) { Object.entries( loadingDurations ).forEach( ( [ metric, duration ] ) => { if ( metric === 'timeSinceResponseEnd' ) { results.firstBlock.push( duration ); } else { results[ metric ].push( duration ); } } ); const serverTiming = await metrics.getServerTiming(); for ( const [ key, value ] of Object.entries( serverTiming ) ) { results[ key ] ??= []; results[ key ].push( value ); } } } ); } } ); async function type( target, metrics, key ) { // The first character typed triggers a longer time (isTyping change). // It can impact the stability of the metric, so we exclude it. It // probably deserves a dedicated metric itself, though. const samples = 10; const throwaway = 1; const iterations = samples + throwaway; // Start tracing. await metrics.startTracing(); // Type the testing sequence into the empty paragraph. await target.type( 'x'.repeat( iterations ), { delay: BROWSER_IDLE_WAIT, // The extended timeout is needed because the typing is very slow // and the `delay` value itself does not extend it. timeout: iterations * BROWSER_IDLE_WAIT * 2, // 2x the total time to be safe. } ); // Stop tracing. await metrics.stopTracing( `post-editor-${ kebabCase( key ) }` ); // Get the durations. const [ keyDownEvents, keyPressEvents, keyUpEvents ] = metrics.getTypingEventDurations(); // Save the results. for ( let i = throwaway; i < iterations; i++ ) { results[ key ].push( keyDownEvents[ i ] + keyPressEvents[ i ] + keyUpEvents[ i ] ); } } test.describe( 'Typing', () => { let draftId = null; test( 'Setup the test post', async ( { admin, perfUtils, editor } ) => { await admin.createNewPost(); await perfUtils.loadBlocksForLargePost(); await editor.insertBlock( { name: 'core/paragraph' } ); draftId = await perfUtils.saveDraft(); } ); test( 'Run the test', async ( { admin, perfUtils, metrics } ) => { await admin.editPost( draftId ); await perfUtils.disableAutosave(); const canvas = await perfUtils.getCanvas(); const paragraph = canvas.getByRole( 'document', { name: /Empty block/i, } ); await type( paragraph, metrics, 'type' ); } ); } ); test.describe( 'Typing (without inspector)', () => { let draftId = null; test( 'Setup the test post', async ( { admin, perfUtils, editor } ) => { await admin.createNewPost(); await perfUtils.loadBlocksForLargePost(); await editor.insertBlock( { name: 'core/paragraph' } ); draftId = await perfUtils.saveDraft(); } ); test( 'Run the test', async ( { admin, perfUtils, metrics, page, editor, } ) => { await admin.editPost( draftId ); await perfUtils.disableAutosave(); const toggleButton = page .getByRole( 'region', { name: 'Editor settings' } ) .getByRole( 'button', { name: 'Close Settings' } ); await toggleButton.click(); const canvas = await perfUtils.getCanvas(); const paragraph = canvas.getByRole( 'document', { name: /Empty block/i, } ); await type( paragraph, metrics, 'typeWithoutInspector' ); // Open the inspector again. await editor.openDocumentSettingsSidebar(); } ); } ); test.describe( 'Typing (with top toolbar)', () => { let draftId = null; test( 'Setup the test post', async ( { admin, perfUtils, editor } ) => { await admin.createNewPost(); await perfUtils.loadBlocksForLargePost(); await editor.insertBlock( { name: 'core/paragraph' } ); draftId = await perfUtils.saveDraft(); } ); test( 'Run the test', async ( { admin, perfUtils, metrics, editor, } ) => { await admin.editPost( draftId ); await perfUtils.disableAutosave(); // Enable fixed toolbar. await editor.setIsFixedToolbar( true ); const canvas = await perfUtils.getCanvas(); const paragraph = canvas.getByRole( 'document', { name: /Empty block/i, } ); await type( paragraph, metrics, 'typeWithTopToolbar' ); // Disabled fixed toolbar. Default state. await editor.setIsFixedToolbar( false ); } ); } ); test.describe( 'Typing within containers', () => { let draftId = null; test( 'Set up the test post', async ( { admin, perfUtils } ) => { await admin.createNewPost(); await perfUtils.loadBlocksForSmallPostWithContainers(); draftId = await perfUtils.saveDraft(); } ); test( 'Run the test', async ( { admin, perfUtils, metrics } ) => { await admin.editPost( draftId ); await perfUtils.disableAutosave(); const canvas = await perfUtils.getCanvas(); // Select the block where we type in. const firstParagraph = canvas .getByRole( 'document', { name: /Paragraph block|Block: Paragraph/, } ) .first(); await firstParagraph.click(); await type( firstParagraph, metrics, 'typeContainer' ); } ); } ); test.describe( 'Selecting blocks', () => { let draftId = null; test( 'Set up the test post', async ( { admin, perfUtils } ) => { await admin.createNewPost(); await perfUtils.load1000Paragraphs(); draftId = await perfUtils.saveDraft(); } ); test( 'Run the test', async ( { admin, page, perfUtils, metrics } ) => { await admin.editPost( draftId ); await perfUtils.disableAutosave(); const canvas = await perfUtils.getCanvas(); const paragraphs = canvas.getByRole( 'document', { name: /Block: Paragraph/i, } ); // The first click also mounts the block inspector, so it costs // about twice a later one and gets its own metric. const samples = 10; const iterations = samples + 1; for ( let i = 1; i <= iterations; i++ ) { const paragraph = paragraphs.nth( i ); // Scroll first, so Playwright's auto-scroll on click stays // out of the trace. await paragraph.scrollIntoViewIfNeeded(); // Wait for the browser to be idle before starting the monitoring. // eslint-disable-next-line no-restricted-syntax, playwright/no-wait-for-timeout await page.waitForTimeout( BROWSER_IDLE_WAIT ); // Start tracing. await metrics.startTracing(); // Click the next paragraph. await paragraph.click(); // Stop tracing. Save just one representative sample. await metrics.stopTracing( i === Math.floor( iterations / 2 ) && 'post-editor-focus' ); // Get the durations. const allDurations = metrics.getSelectionEventDurations(); const duration = allDurations.reduce( ( acc, eventDurations ) => acc + sum( eventDurations ), 0 ); // Save the results. if ( i === 1 ) { results.firstFocus.push( duration ); } else { results.focus.push( duration ); } } } ); } ); test.describe( 'Selecting all blocks', () => { let draftId = null; test( 'Set up the test post', async ( { admin, perfUtils } ) => { await admin.createNewPost(); await perfUtils.load1000Paragraphs(); draftId = await perfUtils.saveDraft(); } ); test( 'Run the test', async ( { admin, page, perfUtils, metrics } ) => { await admin.editPost( draftId ); await perfUtils.disableAutosave(); const canvas = await perfUtils.getCanvas(); const paragraphs = canvas.getByRole( 'document', { name: /Block: Paragraph/i, } ); // Fewer samples than the other metrics take. The comparison runs // this spec against builds that predate the selection fix, where a // single iteration costs seconds, and ten of them exceed the test // timeout. const samples = 3; const throwaway = 1; const iterations = samples + throwaway; for ( let i = 1; i <= iterations; i++ ) { // Put the caret in a paragraph, so the selection is a single // block with a collapsed caret again. await paragraphs.nth( i ).click(); // The first press selects the contents of the block; only the // second one multi-selects every block. await page.keyboard.press( 'ControlOrMeta+a' ); // Wait for the browser to be idle before starting the monitoring. // eslint-disable-next-line no-restricted-syntax, playwright/no-wait-for-timeout await page.waitForTimeout( BROWSER_IDLE_WAIT ); // Start tracing. await metrics.startTracing(); // Select all blocks. await page.keyboard.press( 'ControlOrMeta+a' ); // Stop tracing. Save just one representative sample. await metrics.stopTracing( i === Math.floor( iterations / 2 ) && 'post-editor-select-all' ); // Get the durations. const [ keyDownEvents ] = metrics.getTypingEventDurations(); // Save the results. if ( i > throwaway ) { results.selectAll.push( sum( keyDownEvents ) ); } } } ); } ); test.describe( 'Undoing and redoing block changes', () => { let draftId = null; test( 'Set up the test post', async ( { admin, perfUtils } ) => { await admin.createNewPost(); await perfUtils.load1000Paragraphs(); draftId = await perfUtils.saveDraft(); } ); test( 'Run the test', async ( { admin, page, perfUtils } ) => { await admin.editPost( draftId ); await perfUtils.disableAutosave(); const canvas = await perfUtils.getCanvas(); // Focus the canvas so the undo shortcuts reach the editor. await canvas .getByRole( 'document', { name: /Block: Paragraph/i } ) .first() .click(); // Undo re-renders off-screen blocks in later tasks, after the key // events, so this measures all main thread work until idle. const session = await page.context().newCDPSession( page ); await session.send( 'Performance.enable' ); const getTaskDuration = async () => { const { metrics } = await session.send( 'Performance.getMetrics' ); return ( metrics.find( ( { name } ) => name === 'TaskDuration' ) .value * 1000 ); }; // Idle once three idle periods in a row have time left, so no work // is left, such as blocks updating in idle time. With the caret in // the canvas, the browser draws every frame, so periods are short. const waitForIdle = () => page.evaluate( () => new Promise( ( resolve ) => { let idlePeriods = 0; const check = ( deadline ) => { idlePeriods = deadline.timeRemaining() > 10 ? idlePeriods + 1 : 0; if ( idlePeriods === 3 ) { resolve(); } else { window.requestIdleCallback( check ); } }; window.requestIdleCallback( check ); } ) ); // Which of the two edited paragraphs have a drop cap. const getDropCaps = ( clientIds ) => page.evaluate( ( ids ) => ids.map( ( id ) => !! window.wp.data .select( 'core/block-editor' ) .getBlockAttributes( id ).dropCap ), clientIds ); // Each step and which paragraphs have a drop cap after it. const steps = [ [ 'ControlOrMeta+z', [ true, false ] ], [ 'ControlOrMeta+z', [ false, false ] ], [ 'ControlOrMeta+Shift+z', [ true, false ] ], ]; const throwaway = 1; const iterations = 4 + throwaway; for ( let i = 1; i <= iterations; i++ ) { // Two undo levels: a drop cap on one paragraph, then another. const clientIds = await page.evaluate( ( index ) => { const { select, dispatch } = window.wp.data; const ids = select( 'core/block-editor' ) .getBlockOrder() .slice( index, index + 2 ); for ( const id of ids ) { dispatch( 'core/block-editor' ).updateBlockAttributes( id, { dropCap: true } ); } return ids; }, i * 2 ); expect( await getDropCaps( clientIds ) ).toEqual( [ true, true, ] ); expect( await page.evaluate( () => window.wp.data.select( 'core' ).hasUndo() ) ).toBe( true ); for ( const [ key, dropCaps ] of steps ) { await waitForIdle(); const start = await getTaskDuration(); await page.keyboard.press( key ); await waitForIdle(); const duration = ( await getTaskDuration() ) - start; expect( await getDropCaps( clientIds ) ).toEqual( dropCaps ); // Save the results. if ( i > throwaway ) { results.undo.push( duration ); } } } } ); } ); test.describe( 'Opening persistent List View', () => { let draftId = null; test( 'Set up the test page', async ( { admin, perfUtils } ) => { await admin.createNewPost(); await perfUtils.load1000Paragraphs(); draftId = await perfUtils.saveDraft(); } ); test( 'Run the test', async ( { page, admin, perfUtils, metrics } ) => { await admin.editPost( draftId ); await perfUtils.disableAutosave(); const listViewToggle = page.getByRole( 'button', { name: 'Document Overview', } ); const samples = 10; const throwaway = 1; const iterations = samples + throwaway; for ( let i = 1; i <= iterations; i++ ) { // Wait for the browser to be idle before starting the monitoring. // eslint-disable-next-line no-restricted-syntax, playwright/no-wait-for-timeout await page.waitForTimeout( BROWSER_IDLE_WAIT ); // Start tracing. await metrics.startTracing(); // Open List View. await listViewToggle.click(); await perfUtils.expectExpandedState( listViewToggle, 'true' ); // Stop tracing. Save just one representative sample. await metrics.stopTracing( i === Math.floor( iterations / 2 ) && 'post-editor-list-view-open' ); // Get the durations. const [ mouseClickEvents ] = metrics.getClickEventDurations(); // Save the results. if ( i > throwaway ) { results.listViewOpen.push( mouseClickEvents[ 0 ] ); } // Close List View await listViewToggle.click(); await perfUtils.expectExpandedState( listViewToggle, 'false' ); } } ); } ); test.describe( 'Opening Inserter', () => { let draftId = null; test( 'Set up the test page', async ( { admin, perfUtils } ) => { await admin.createNewPost(); await perfUtils.load1000Paragraphs(); draftId = await perfUtils.saveDraft(); } ); test( 'Run the test', async ( { page, admin, perfUtils, metrics } ) => { // Go to the test page. await admin.editPost( draftId ); await perfUtils.disableAutosave(); const globalInserterToggle = page .getByRole( 'region', { name: 'Editor top bar' } ) .getByRole( 'button', { name: 'Block Inserter', } ); const samples = 10; const throwaway = 1; const iterations = samples + throwaway; for ( let i = 1; i <= iterations; i++ ) { // Wait for the browser to be idle before starting the monitoring. // eslint-disable-next-line no-restricted-syntax, playwright/no-wait-for-timeout await page.waitForTimeout( BROWSER_IDLE_WAIT ); // Start tracing. await metrics.startTracing(); // Open Inserter. await globalInserterToggle.click(); await perfUtils.expectExpandedState( globalInserterToggle, 'true' ); // Stop tracing. Save just one representative sample. await metrics.stopTracing( i === Math.floor( iterations / 2 ) && 'post-editor-inserter-open' ); // Get the durations. const [ mouseClickEvents ] = metrics.getClickEventDurations(); // Save the results. if ( i > throwaway ) { results.inserterOpen.push( mouseClickEvents[ 0 ] ); } // Close Inserter. await globalInserterToggle.click(); await perfUtils.expectExpandedState( globalInserterToggle, 'false' ); } } ); } ); test.describe( 'Searching Inserter', () => { let draftId = null; test( 'Set up the test page', async ( { admin, perfUtils } ) => { await admin.createNewPost(); await perfUtils.load1000Paragraphs(); draftId = await perfUtils.saveDraft(); } ); test( 'Run the test', async ( { page, admin, perfUtils, metrics } ) => { // Go to the test page. await admin.editPost( draftId ); await perfUtils.disableAutosave(); const globalInserterToggle = page .getByRole( 'region', { name: 'Editor top bar' } ) .getByRole( 'button', { name: 'Block Inserter', } ); // Open Inserter. await globalInserterToggle.click(); await page.getByRole( 'searchbox' ).click(); await perfUtils.expectExpandedState( globalInserterToggle, 'true' ); const samples = 10; const throwaway = 1; const iterations = samples + throwaway; for ( let i = 1; i <= iterations; i++ ) { // Wait for the browser to be idle before starting the monitoring. // eslint-disable-next-line no-restricted-syntax, playwright/no-wait-for-timeout await page.waitForTimeout( BROWSER_IDLE_WAIT ); // Start tracing. await metrics.startTracing(); // Type to trigger search. await page.keyboard.type( 'p' ); // Stop tracing. Save just one representative sample. await metrics.stopTracing( i === Math.floor( iterations / 2 ) && 'post-editor-inserter-search' ); // Get the durations. const [ keyDownEvents, keyPressEvents, keyUpEvents ] = metrics.getTypingEventDurations(); // Save the results. if ( i > throwaway ) { results.inserterSearch.push( keyDownEvents[ 0 ] + keyPressEvents[ 0 ] + keyUpEvents[ 0 ] ); } await page.keyboard.press( 'Backspace' ); } } ); } ); test.describe( 'Hovering Inserter items', () => { let draftId = null; test( 'Set up the test page', async ( { admin, perfUtils } ) => { await admin.createNewPost(); await perfUtils.load1000Paragraphs(); draftId = await perfUtils.saveDraft(); } ); test( 'Run the test', async ( { page, admin, perfUtils, metrics } ) => { // Go to the test page. await admin.editPost( draftId ); await perfUtils.disableAutosave(); const globalInserterToggle = page .getByRole( 'region', { name: 'Editor top bar' } ) .getByRole( 'button', { name: 'Block Inserter', } ); const paragraphBlockItem = page.getByRole( 'option', { name: 'Paragraph', exact: true, } ); const headingBlockItem = page.getByRole( 'option', { name: 'Heading', exact: true, } ); // Open Inserter. await globalInserterToggle.click(); await perfUtils.expectExpandedState( globalInserterToggle, 'true' ); const samples = 10; const throwaway = 1; const iterations = samples + throwaway; for ( let i = 1; i <= iterations; i++ ) { // Wait for the browser to be idle before starting the monitoring. // eslint-disable-next-line no-restricted-syntax, playwright/no-wait-for-timeout await page.waitForTimeout( BROWSER_IDLE_WAIT ); // Start tracing. await metrics.startTracing(); // Hover Inserter items. await paragraphBlockItem.hover(); await headingBlockItem.hover(); // Stop tracing. Save just one representative sample. await metrics.stopTracing( i === Math.floor( iterations / 2 ) && 'post-editor-inserter-hover' ); // Get the durations. const [ mouseOverEvents, mouseOutEvents ] = metrics.getHoverEventDurations(); // Save the results. if ( i > throwaway ) { for ( let k = 0; k < mouseOverEvents.length; k++ ) { results.inserterHover.push( mouseOverEvents[ k ] + mouseOutEvents[ k ] ); } } } } ); } ); test.describe( 'Loading Patterns', () => { test( 'Run the test', async ( { page, admin, perfUtils } ) => { await admin.createNewPost(); await perfUtils.disableAutosave(); const globalInserterToggle = page .getByRole( 'region', { name: 'Editor top bar' } ) .getByRole( 'button', { name: 'Block Inserter', } ); const testPatterns = [ { name: 'core/query-standard-posts', title: 'Standard', content: '\n\t\t\t\t\t
\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t
\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t
\n\t\t\t\t\t', categories: [ 'test' ], blockTypes: [ 'core/query' ], source: 'core', }, { name: 'core/query-medium-posts', title: 'Image at left', content: '\n\t\t\t\t\t
\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t
\n\t\t\t\t\t
\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t
\n\t\t\t\t\t
\n\t\t\t\t\t
\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t
\n\t\t\t\t\t', categories: [ 'test' ], blockTypes: [ 'core/query' ], source: 'core', }, { name: 'core/query-small-posts', title: 'Small image and title', content: '\n\t\t\t\t\t
\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t
\n\t\t\t\t\t
\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t
\n\t\t\t\t\t
\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t
\n\t\t\t\t\t', categories: [ 'test' ], blockTypes: [ 'core/query' ], source: 'core', }, { name: 'core/query-grid-posts', title: 'Grid', content: '\n\t\t\t\t\t
\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t
\n\t\t\t\t\t\n\t\t\t\t\t
\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t
\n\t\t\t\t\t', categories: [ 'test' ], blockTypes: [ 'core/query' ], source: 'core', }, { name: 'core/query-large-title-posts', title: 'Large title', content: '\n\t\t\t\t\t
\n\t\t\t\t\t
\n\t\t\t\t\t\n\t\t\t\t\t
\n\t\t\t\t\t\n\n\t\t\t\t\t\n\t\t\t\t\t
\n\t\t\t\t\t
\n\t\t\t\t\t\n\n\t\t\t\t\t\n\t\t\t\t\t
\n\t\t\t\t\t
\n\t\t\t\t\t\n\t\t\t\t\t
\n\t\t\t\t\t
\n\t\t\t\t\t', categories: [ 'test' ], blockTypes: [ 'core/query' ], source: 'core', }, { name: 'core/query-offset-posts', title: 'Offset', content: '\n\t\t\t\t\t
\n\t\t\t\t\t
\n\t\t\t\t\t
\n\t\t\t\t\t
\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t
\n\t\t\t\t\t
\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t
\n\t\t\t\t\t
\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t
\n\t\t\t\t\t
\n\t\t\t\t\t
\n\t\t\t\t\t
\n\t\t\t\t\t', categories: [ 'test' ], blockTypes: [ 'core/query' ], source: 'core', }, { name: 'core/social-links-shared-background-color', title: 'Social links with a shared background color', content: '\n\t\t\t\t\t\t\n\t\t\t\t\t\t', viewportWidth: 500, categories: [ 'test' ], blockTypes: [ 'core/social-links' ], source: 'core', }, { name: 'core/query-large-title-posts-2', title: 'Large title 2', content: '\n\t\t\t\t\t
\n\t\t\t\t\t
\n\t\t\t\t\t\n\t\t\t\t\t
\n\t\t\t\t\t\n\n\t\t\t\t\t\n\t\t\t\t\t
\n\t\t\t\t\t
\n\t\t\t\t\t\n\n\t\t\t\t\t\n\t\t\t\t\t
\n\t\t\t\t\t
\n\t\t\t\t\t\n\t\t\t\t\t
\n\t\t\t\t\t
\n\t\t\t\t\t', categories: [ 'test' ], blockTypes: [ 'core/query' ], source: 'core', }, { name: 'core/query-offset-posts-2', title: 'Offset 2', content: '\n\t\t\t\t\t
\n\t\t\t\t\t
\n\t\t\t\t\t
\n\t\t\t\t\t
\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t
\n\t\t\t\t\t
\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t
\n\t\t\t\t\t
\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t
\n\t\t\t\t\t
\n\t\t\t\t\t
\n\t\t\t\t\t
\n\t\t\t\t\t', categories: [ 'test' ], blockTypes: [ 'core/query' ], source: 'core', }, { name: 'core/social-links-shared-background-color-2', title: 'Social links with a shared background color 2', content: '\n\t\t\t\t\t\t\n\t\t\t\t\t\t', viewportWidth: 500, categories: [ 'test' ], blockTypes: [ 'core/social-links' ], source: 'core', }, ]; await page.evaluate( ( _testPatterns ) => { const settings = window.wp.data .select( 'core/editor' ) .getEditorSettings(); window.wp.data.dispatch( 'core/editor' ).updateEditorSettings( { ...settings, __experimentalAdditionalBlockPatternCategories: [ ...settings.__experimentalAdditionalBlockPatternCategories, { name: 'test', label: 'Test' }, ], __experimentalAdditionalBlockPatterns: [ ...settings.__experimentalAdditionalBlockPatterns, ..._testPatterns, ], } ); }, testPatterns ); const samples = 10; const throwaway = 1; const iterations = samples + throwaway; for ( let i = 1; i <= iterations; i++ ) { // Wait for the browser to be idle before starting the monitoring. // eslint-disable-next-line no-restricted-syntax, playwright/no-wait-for-timeout await page.waitForTimeout( BROWSER_IDLE_WAIT ); await globalInserterToggle.click(); await perfUtils.expectExpandedState( globalInserterToggle, 'true' ); await page.getByRole( 'tab', { name: 'Patterns' } ).click(); const startTime = performance.now(); // This is the WP v6.5 and older locator. const oldLocator = page.getByRole( 'button', { name: 'Test' } ); // This is the WP v6.6 and newer locator. const newLocator = page.getByRole( 'tab', { name: 'Test' } ); await oldLocator.or( newLocator ).click(); await Promise.all( testPatterns.map( async ( pattern ) => { const canvas = await perfUtils.getCanvas( page .getByRole( 'option', { name: pattern.title, exact: true, } ) .getByTitle( 'Editor canvas' ) ); // Wait for the first block. await canvas.locator( '.wp-block' ).first().waitFor(); } ) ); const endTime = performance.now(); // Save the results. if ( i > throwaway ) { results.loadPatterns.push( endTime - startTime ); } // Close Inserter. await globalInserterToggle.click(); await perfUtils.expectExpandedState( globalInserterToggle, 'false' ); } } ); } ); } ); /* eslint-enable playwright/expect-expect */