diff --git a/packages/e2e-tests/specs/performance/post-editor.test.js b/packages/e2e-tests/specs/performance/post-editor.test.js index 969aa28c820b37..769b36817052f8 100644 --- a/packages/e2e-tests/specs/performance/post-editor.test.js +++ b/packages/e2e-tests/specs/performance/post-editor.test.js @@ -27,8 +27,8 @@ import { getTypingEventDurations, getClickEventDurations, getHoverEventDurations, - getSelectionEventDurations, getLoadingDurations, + getDiffBetweenEventStarts, } from './utils'; jest.setTimeout( 1000000 ); @@ -249,9 +249,13 @@ describe( 'Post Editor Performance', () => { await page.keyboard.type( 'a' ); await page.tracing.stop(); traceResults = JSON.parse( readFile( traceFile ) ); - const [ focusEvents, keyDownEvents ] = - getSelectionEventDurations( traceResults ); - results.focus.push( keyDownEvents[ 0 ] - focusEvents[ 0 ] ); + results.focus.push( + getDiffBetweenEventStarts( + traceResults, + 'pointerdown', + 'keydown' + ) + ); } } ); diff --git a/packages/e2e-tests/specs/performance/utils.js b/packages/e2e-tests/specs/performance/utils.js index b52c33796e2519..0725df64eb0961 100644 --- a/packages/e2e-tests/specs/performance/utils.js +++ b/packages/e2e-tests/specs/performance/utils.js @@ -15,42 +15,39 @@ export function deleteFile( filePath ) { } } -function isEvent( item ) { +function isEvent( item, type ) { return ( item.cat === 'devtools.timeline' && item.name === 'EventDispatch' && item.dur && item.args && - item.args.data + item.args.data && + item.args.data.type === type ); } function isKeyDownEvent( item ) { - return isEvent( item ) && item.args.data.type === 'keydown'; + return isEvent( item, 'keydown' ); } function isKeyPressEvent( item ) { - return isEvent( item ) && item.args.data.type === 'keypress'; + return isEvent( item, 'keypress' ); } function isKeyUpEvent( item ) { - return isEvent( item ) && item.args.data.type === 'keyup'; -} - -function isFocusEvent( item ) { - return isEvent( item ) && item.args.data.type === 'focus'; + return isEvent( item, 'keyup' ); } function isClickEvent( item ) { - return isEvent( item ) && item.args.data.type === 'click'; + return isEvent( item, 'click' ); } function isMouseOverEvent( item ) { - return isEvent( item ) && item.args.data.type === 'mouseover'; + return isEvent( item, 'mouseover' ); } function isMouseOutEvent( item ) { - return isEvent( item ) && item.args.data.type === 'mouseout'; + return isEvent( item, 'mouseout' ); } function getEventDurationsForType( trace, filterFunction ) { @@ -59,12 +56,6 @@ function getEventDurationsForType( trace, filterFunction ) { .map( ( item ) => item.dur / 1000 ); } -function getEventStartForType( trace, filterFunction ) { - return trace.traceEvents - .filter( filterFunction ) - .map( ( item ) => item.ts / 1000 ); -} - export function getTypingEventDurations( trace ) { return [ getEventDurationsForType( trace, isKeyDownEvent ), @@ -73,11 +64,10 @@ export function getTypingEventDurations( trace ) { ]; } -export function getSelectionEventDurations( trace ) { - return [ - getEventStartForType( trace, isFocusEvent ), - getEventStartForType( trace, isKeyDownEvent ), - ]; +export function getDiffBetweenEventStarts( trace, aType, bType ) { + const aEvent = trace.traceEvents.find( ( item ) => isEvent( item, aType ) ); + const bEvent = trace.traceEvents.find( ( item ) => isEvent( item, bType ) ); + return ( bEvent.ts - aEvent.ts ) / 1000; } export function getClickEventDurations( trace ) {