From a3dc53148c2a0edafffefb0710e85f5c4e5b0bf2 Mon Sep 17 00:00:00 2001 From: Ella Date: Fri, 5 Jul 2024 11:06:47 +0300 Subject: [PATCH 1/2] DataViews: add performance test for pages --- .../config/performance-reporter.ts | 3 + test/performance/specs/site-editor.spec.js | 58 +++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/test/performance/config/performance-reporter.ts b/test/performance/config/performance-reporter.ts index 6360b78636a2ac..403f1a253ae8f1 100644 --- a/test/performance/config/performance-reporter.ts +++ b/test/performance/config/performance-reporter.ts @@ -34,6 +34,7 @@ export interface WPRawPerformanceResults { inserterSearch: number[]; inserterHover: number[]; loadPatterns: number[]; + loadPages: number[]; listViewOpen: number[]; navigate: number[]; wpBeforeTemplate: number[]; @@ -69,6 +70,7 @@ export interface WPPerformanceResults { inserterSearch?: PerformanceStats; inserterHover?: PerformanceStats; loadPatterns?: PerformanceStats; + loadPages?: PerformanceStats; listViewOpen?: PerformanceStats; navigate?: PerformanceStats; wpBeforeTemplate?: PerformanceStats; @@ -106,6 +108,7 @@ export function curateResults( inserterSearch: stats( results.inserterSearch ), inserterHover: stats( results.inserterHover ), loadPatterns: stats( results.loadPatterns ), + loadPages: stats( results.loadPages ), listViewOpen: stats( results.listViewOpen ), navigate: stats( results.navigate ), wpBeforeTemplate: stats( results.wpBeforeTemplate ), diff --git a/test/performance/specs/site-editor.spec.js b/test/performance/specs/site-editor.spec.js index 9d16f2dff19d49..d23c3fad3e51d3 100644 --- a/test/performance/specs/site-editor.spec.js +++ b/test/performance/specs/site-editor.spec.js @@ -29,6 +29,7 @@ const results = { listViewOpen: [], navigate: [], loadPatterns: [], + loadPages: [], }; test.describe( 'Site Editor Performance', () => { @@ -384,6 +385,63 @@ test.describe( 'Site Editor Performance', () => { } } ); } ); + + test.describe( 'Loading Pages', () => { + test.beforeAll( async ( { requestUtils } ) => { + await requestUtils.activateTheme( 'twentytwentyfour' ); + } ); + + test.afterAll( async ( { requestUtils } ) => { + await requestUtils.activateTheme( 'twentytwentyfour' ); + } ); + + const perPage = 20; + + test( 'Run the test', async ( { page, admin, requestUtils } ) => { + await Promise.all( + Array.from( { length: perPage }, async ( el, index ) => { + const { id } = await requestUtils.createPage( { + status: 'publish', + title: `Page (${ index })`, + content: ` + +

Hello

+ + +

Post content

+`, + } ); + + return id; + } ) + ); + + const samples = 10; + for ( let i = 1; i <= samples; i++ ) { + // We want to start from a fresh state each time, without + // queries or patterns already cached. + await admin.visitSiteEditor(); + + const startTime = performance.now(); + + await page.getByRole( 'button', { name: 'Pages' } ).click(); + + await Promise.all( + Array.from( { length: perPage }, async ( el, index ) => { + return await page + .getByRole( 'button', { + name: `Page (${ index })`, + } ) + .waitFor( { state: 'attached' } ); + } ) + ); + + const endTime = performance.now(); + + results.loadPages.push( endTime - startTime ); + } + } ); + } ); } ); /* eslint-enable playwright/no-conditional-in-test, playwright/expect-expect */ From 24f588cd602d6beadf73d49db9d7a02d5167433a Mon Sep 17 00:00:00 2001 From: Ella Date: Fri, 5 Jul 2024 15:53:40 +0300 Subject: [PATCH 2/2] Address feedback --- test/performance/specs/site-editor.spec.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/test/performance/specs/site-editor.spec.js b/test/performance/specs/site-editor.spec.js index d23c3fad3e51d3..7b890a4c067756 100644 --- a/test/performance/specs/site-editor.spec.js +++ b/test/performance/specs/site-editor.spec.js @@ -418,18 +418,23 @@ test.describe( 'Site Editor Performance', () => { const samples = 10; for ( let i = 1; i <= samples; i++ ) { - // We want to start from a fresh state each time, without - // queries or patterns already cached. - await admin.visitSiteEditor(); + // Start from the trash view, then navigate to all pages, so we + // test item loading rather than site editor load as a whole. + // For some reason `visiSiteEditor` does not work with these + // parameters. + await admin.visitAdminPage( + 'site-editor.php?postType=page&layout=table&activeView=trash' + ); const startTime = performance.now(); - await page.getByRole( 'button', { name: 'Pages' } ).click(); + await page.getByRole( 'button', { name: 'All Pages' } ).click(); + // Wait for all pages to be rendered. await Promise.all( Array.from( { length: perPage }, async ( el, index ) => { return await page - .getByRole( 'button', { + .getByRole( 'link', { name: `Page (${ index })`, } ) .waitFor( { state: 'attached' } );