Skip to content

Commit

Permalink
Improve calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Feb 23, 2023
1 parent c08e5d3 commit 6d762f2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
30 changes: 12 additions & 18 deletions packages/e2e-tests/specs/performance/post-editor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
getHoverEventDurations,
getSelectionEventDurations,
getLoadingDurations,
sum,
} from './utils';

jest.setTimeout( 1000000 );
Expand Down Expand Up @@ -235,28 +236,24 @@ describe( 'Post Editor Performance', () => {
it( 'Selecting blocks', async () => {
await load1000Paragraphs();
const paragraphs = await canvas().$$( '.wp-block' );
await page.tracing.start( {
path: traceFile,
screenshots: false,
categories: [ 'devtools.timeline' ],
} );
await paragraphs[ 0 ].click();
for ( let j = 1; j <= 10; j++ ) {
// Wait for the browser to be idle before starting the monitoring.
// eslint-disable-next-line no-restricted-syntax
await page.waitForTimeout( 1000 );
await page.tracing.start( {
path: traceFile,
screenshots: false,
categories: [ 'devtools.timeline' ],
} );
await paragraphs[ j ].click();
}
await page.tracing.stop();
traceResults = JSON.parse( readFile( traceFile ) );
const [ focusEvents, focusInEvents, selectionChangeEvents ] =
getSelectionEventDurations( traceResults );

for ( let j = 0; j < focusEvents.length; j++ ) {
await page.tracing.stop();
traceResults = JSON.parse( readFile( traceFile ) );
const allDurations = getSelectionEventDurations( traceResults );
results.focus.push(
focusEvents[ j ] +
focusInEvents[ j ] +
selectionChangeEvents[ j ]
allDurations.reduce( ( acc, eventDurations ) => {
return acc + sum( eventDurations );
}, 0 )
);
}
} );
Expand Down Expand Up @@ -300,9 +297,6 @@ describe( 'Post Editor Performance', () => {
} );

it( 'Searching the inserter', async () => {
function sum( arr ) {
return arr.reduce( ( a, b ) => a + b, 0 );
}
await load1000Paragraphs();
await openGlobalBlockInserter();
for ( let j = 0; j < 10; j++ ) {
Expand Down
4 changes: 4 additions & 0 deletions packages/e2e-tests/specs/performance/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,7 @@ export async function getLoadingDurations() {
};
} );
}

export function sum( arr ) {
return arr.reduce( ( a, b ) => a + b, 0 );
}

0 comments on commit 6d762f2

Please sign in to comment.