Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Feb 27, 2023
1 parent e7e1088 commit 70c1f36
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 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,9 +27,9 @@ import {
getTypingEventDurations,
getClickEventDurations,
getHoverEventDurations,
getSelectionEventDurations,
getLoadingDurations,
sum,
getDiffBetweenEventStarts,
} from './utils';

jest.setTimeout( 1000000 );
Expand Down Expand Up @@ -242,9 +242,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
26 changes: 11 additions & 15 deletions packages/e2e-tests/specs/performance/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,31 @@ 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';
}

function isFocusEvent( item ) {
return isEvent( item ) && item.args.data.type === 'focus';
return isEvent( item, 'keydown' );
}

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 @@ -61,11 +58,10 @@ export function getTypingEventDurations( trace ) {
return [ getEventStartForType( trace, isKeyDownEvent ) ];
}

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 70c1f36

Please sign in to comment.