Skip to content

Commit

Permalink
Reset the page between every performance test
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed Dec 19, 2022
1 parent a556b69 commit d7bb563
Showing 1 changed file with 24 additions and 29 deletions.
53 changes: 24 additions & 29 deletions packages/e2e-tests/specs/performance/post-editor.test.js
Expand Up @@ -49,6 +49,17 @@ async function loadHtmlIntoTheBlockEditor( html ) {
}, html );
}

async function load1000Paragraphs() {
await page.evaluate( () => {
const { createBlock } = window.wp.blocks;
const { dispatch } = window.wp.data;
const blocks = Array.from( { length: 1000 } ).map( () =>
createBlock( 'core/paragraph' )
);
dispatch( 'core/block-editor' ).resetBlocks( blocks );
} );
}

describe( 'Post Editor Performance', () => {
const results = {
serverResponse: [],
Expand All @@ -68,14 +79,6 @@ describe( 'Post Editor Performance', () => {
const traceFile = __dirname + '/trace.json';
let traceResults;

beforeAll( async () => {
await createNewPost();
await loadHtmlIntoTheBlockEditor(
readFile( join( __dirname, '../../assets/large-post.html' ) )
);
await saveDraft();
} );

afterAll( async () => {
const resultsFilename = basename( __filename, '.js' ) + '.results.json';
writeFileSync(
Expand All @@ -86,6 +89,7 @@ describe( 'Post Editor Performance', () => {
} );

beforeEach( async () => {
await createNewPost();
// Disable auto-save to avoid impacting the metrics.
await page.evaluate( () => {
window.wp.data.dispatch( 'core/editor' ).updateEditorSettings( {
Expand All @@ -96,7 +100,10 @@ describe( 'Post Editor Performance', () => {
} );

it( 'Loading', async () => {
// Measuring loading time.
await loadHtmlIntoTheBlockEditor(
readFile( join( __dirname, '../../assets/large-post.html' ) )
);
await saveDraft();
let i = 5;
while ( i-- ) {
await page.reload();
Expand All @@ -120,7 +127,9 @@ describe( 'Post Editor Performance', () => {
} );

it( 'Typing', async () => {
// Measuring typing performance.
await loadHtmlIntoTheBlockEditor(
readFile( join( __dirname, '../../assets/large-post.html' ) )
);
await insertBlock( 'Paragraph' );
let i = 20;
await page.tracing.start( {
Expand Down Expand Up @@ -155,8 +164,6 @@ describe( 'Post Editor Performance', () => {
} );

it( 'Typing within containers', async () => {
// Measuring block selection performance.
await createNewPost();
await loadHtmlIntoTheBlockEditor(
readFile(
join(
Expand Down Expand Up @@ -207,16 +214,7 @@ describe( 'Post Editor Performance', () => {
} );

it( 'Selecting blocks', async () => {
// Measuring block selection performance.
await createNewPost();
await page.evaluate( () => {
const { createBlock } = window.wp.blocks;
const { dispatch } = window.wp.data;
const blocks = Array.from( { length: 1000 } ).map( () =>
createBlock( 'core/paragraph' )
);
dispatch( 'core/block-editor' ).resetBlocks( blocks );
} );
await load1000Paragraphs();
const paragraphs = await page.$$( '.wp-block' );
await page.tracing.start( {
path: traceFile,
Expand All @@ -237,8 +235,7 @@ describe( 'Post Editor Performance', () => {
} );

it( 'Opening persistent list view', async () => {
// Measure time to open inserter.
await page.waitForSelector( '.edit-post-layout' );
await load1000Paragraphs();
for ( let j = 0; j < 10; j++ ) {
await page.tracing.start( {
path: traceFile,
Expand All @@ -257,8 +254,7 @@ describe( 'Post Editor Performance', () => {
} );

it( 'Opening the inserter', async () => {
// Measure time to open inserter.
await page.waitForSelector( '.edit-post-layout' );
await load1000Paragraphs();
for ( let j = 0; j < 10; j++ ) {
await page.tracing.start( {
path: traceFile,
Expand All @@ -280,8 +276,7 @@ describe( 'Post Editor Performance', () => {
function sum( arr ) {
return arr.reduce( ( a, b ) => a + b, 0 );
}

// Measure time to search the inserter and get results.
await load1000Paragraphs();
await openGlobalBlockInserter();
for ( let j = 0; j < 10; j++ ) {
// Wait for the browser to be idle before starting the monitoring.
Expand Down Expand Up @@ -313,7 +308,7 @@ describe( 'Post Editor Performance', () => {
} );

it( 'Hovering Inserter Items', async () => {
// Measure inserter hover performance.
await load1000Paragraphs();
const paragraphBlockItem =
'.block-editor-inserter__menu .editor-block-list-item-paragraph';
const headingBlockItem =
Expand Down

1 comment on commit d7bb563

@github-actions
Copy link

Choose a reason for hiding this comment

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

Flaky tests detected.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/3730270294
📝 Reported issues:

Please sign in to comment.