Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Feb 23, 2023
1 parent b848d1d commit 3ac3602
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 27 deletions.
12 changes: 8 additions & 4 deletions packages/e2e-tests/specs/performance/post-editor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import {
getTypingEventDurations,
getClickEventDurations,
getHoverEventDurations,
getSelectionEventDurations,
getLoadingDurations,
getDiffBetweenEventStarts,
} from './utils';

jest.setTimeout( 1000000 );
Expand Down Expand Up @@ -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'
)
);
}
} );

Expand Down
36 changes: 13 additions & 23 deletions packages/e2e-tests/specs/performance/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand All @@ -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 ),
Expand All @@ -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 ) {
Expand Down

0 comments on commit 3ac3602

Please sign in to comment.