Skip to content

Commit

Permalink
Curate results for front-end suite
Browse files Browse the repository at this point in the history
  • Loading branch information
oandregal committed Jan 11, 2023
1 parent 859e453 commit c647035
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
13 changes: 11 additions & 2 deletions bin/plugin/commands/performance.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const config = require( '../config' );
/**
* @typedef WPRawPerformanceResults
*
* @property {number[]} timeToFirstByte Represents the time since the browser started the request until it received a response.
* @property {number[]} serverResponse Represents the time the server takes to respond.
* @property {number[]} firstPaint Represents the time when the user agent first rendered after navigation.
* @property {number[]} domContentLoaded Represents the time immediately after the document's DOMContentLoaded event completes.
Expand All @@ -48,6 +49,7 @@ const config = require( '../config' );
/**
* @typedef WPPerformanceResults
*
* @property {number=} timeToFirstByte Represents the time since the browser started the request until it received a response.
* @property {number=} serverResponse Represents the time the server takes to respond.
* @property {number=} firstPaint Represents the time when the user agent first rendered after navigation.
* @property {number=} domContentLoaded Represents the time immediately after the document's DOMContentLoaded event completes.
Expand Down Expand Up @@ -118,11 +120,18 @@ function formatTime( number ) {
/**
* Curate the raw performance results.
*
* @param {string} testSuite
* @param {WPRawPerformanceResults} results
*
* @return {WPPerformanceResults} Curated Performance results.
*/
function curateResults( results ) {
function curateResults( testSuite, results ) {
if ( testSuite === 'front-end' ) {
return {
timeToFirstByte: average( results.timeToFirstByte ),
};
}

return {
serverResponse: average( results.serverResponse ),
firstPaint: average( results.firstPaint ),
Expand Down Expand Up @@ -173,7 +182,7 @@ async function runTestSuite( testSuite, performanceTestDirectory ) {
`packages/e2e-tests/specs/performance/${ testSuite }.test.results.json`
)
);
return curateResults( rawResults );
return curateResults( testSuite, rawResults );
}

/**
Expand Down
6 changes: 3 additions & 3 deletions packages/e2e-tests/specs/performance/front-end.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { createURL } from '@wordpress/e2e-test-utils';

describe( 'Front End Performance', () => {
const results = {
TTFB: [],
timeToFirstByte: [],
};

afterAll( async () => {
Expand All @@ -22,15 +22,15 @@ describe( 'Front End Performance', () => {
);
} );

it( 'TTFB', async () => {
it( 'Time To First Byte (TTFB)', async () => {
let i = 5;
while ( i-- ) {
await page.goto( createURL( '/' ) );
const navigationTimingJson = await page.evaluate( () =>
JSON.stringify( performance.getEntriesByType( 'navigation' ) )
);
const [ navigationTiming ] = JSON.parse( navigationTimingJson );
results.TTFB.push(
results.timeToFirstByte.push(
navigationTiming.responseStart - navigationTiming.requestStart
);
}
Expand Down

0 comments on commit c647035

Please sign in to comment.