Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Site editor: add pattern/template load performance test with TT4 #58734

Merged
merged 3 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .wp-env.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"wp-content/plugins/gutenberg-test-plugins": "./packages/e2e-tests/plugins",
"wp-content/themes/gutenberg-test-themes": "./test/gutenberg-test-themes",
"wp-content/themes/gutenberg-test-themes/twentytwentyone": "https://downloads.wordpress.org/theme/twentytwentyone.1.7.zip",
"wp-content/themes/gutenberg-test-themes/twentytwentythree": "https://downloads.wordpress.org/theme/twentytwentythree.1.0.zip"
"wp-content/themes/gutenberg-test-themes/twentytwentythree": "https://downloads.wordpress.org/theme/twentytwentythree.1.0.zip",
"wp-content/themes/gutenberg-test-themes/twentytwentyfour": "https://downloads.wordpress.org/theme/twentytwentyfour.1.0.zip"
}
}
}
Expand Down
78 changes: 78 additions & 0 deletions test/performance/specs/site-editor.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const results = {
inserterSearch: [],
listViewOpen: [],
navigate: [],
loadPatterns: [],
};

test.describe( 'Site Editor Performance', () => {
Expand Down Expand Up @@ -206,6 +207,83 @@ test.describe( 'Site Editor Performance', () => {
} );
}
} );

test.describe( 'Loading Patterns', () => {
test.beforeAll( async ( { requestUtils } ) => {
await requestUtils.activateTheme( 'twentytwentyfour' );
} );

test.afterAll( async ( { requestUtils } ) => {
await requestUtils.activateTheme( 'twentytwentyfour' );
} );

test( 'Run the test', async ( { page, admin, perfUtils, editor } ) => {
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( {
postId: 'twentytwentyfour//home',
postType: 'wp_template',
canvas: 'edit',
} );
await editor.openDocumentSettingsSidebar();
await page
.getByRole( 'button', {
name: 'Actions',
} )
.click();

// Wait for the browser to be idle before starting the monitoring.
// eslint-disable-next-line no-restricted-syntax
await page.waitForTimeout( BROWSER_IDLE_WAIT );

const startTime = performance.now();

await page
.getByRole( 'menuitem', { name: 'Replace template' } )
.click();

const patterns = [
'Blogging home template',
'Business home template',
'Portfolio home template with post featured images',
'Blogging index template',
];

await Promise.all(
patterns.map( async ( pattern ) => {
const canvas = await perfUtils.getCanvas(
page
.getByRole( 'option', {
name: pattern,
exact: true,
} )
.getByTitle( 'Editor canvas' )
);

// Wait until the first block is rendered AND all
// patterns are replaced.
await Promise.all( [
canvas.locator( '.wp-block' ).first().waitFor(),
page.waitForFunction(
() =>
document.querySelectorAll(
'[data-type="core/pattern"]'
).length === 0
),
] );
} )
);

const endTime = performance.now();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think relying on waiting and timers like that might not be very stable but we can see over time.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's what we're using for the other patterns load test as well, and also load in general I think


results.loadPatterns.push( endTime - startTime );

await page.keyboard.press( 'Escape' );
}
} );
} );
} );

/* eslint-enable playwright/no-conditional-in-test, playwright/expect-expect */
Loading