-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Performance suite: track TimeToFirstByte in front-end (#47037)
Co-authored-by: Sarah Norris <[email protected]>
- Loading branch information
Showing
7 changed files
with
210 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import { createURL } from './create-url'; | ||
import { isCurrentURL } from './is-current-url'; | ||
|
||
/** | ||
* Performs log out. | ||
* | ||
*/ | ||
export async function logout() { | ||
// If it is logged and in a page different than the dashboard, | ||
// move to the dashboard. Some pages may be in full-screen mode, | ||
// so they won't have the log-out button available. | ||
if ( ! isCurrentURL( 'wp-login.php' ) && ! isCurrentURL( 'wp-admin' ) ) { | ||
await page.goto( createURL( 'wp-admin' ) ); | ||
} | ||
|
||
await Promise.all( [ | ||
page.hover( '#wp-admin-bar-my-account' ), | ||
page.waitForSelector( '#wp-admin-bar-logout', { visible: true } ), | ||
] ); | ||
|
||
await page.click( '#wp-admin-bar-logout' ); | ||
} |
47 changes: 47 additions & 0 deletions
47
packages/e2e-tests/specs/performance/front-end-block-theme.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { basename, join } from 'path'; | ||
import { writeFileSync } from 'fs'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { activateTheme, createURL, logout } from '@wordpress/e2e-test-utils'; | ||
|
||
describe( 'Front End Performance', () => { | ||
const results = { | ||
timeToFirstByte: [], | ||
}; | ||
|
||
beforeAll( async () => { | ||
await activateTheme( 'twentytwentythree' ); | ||
await logout(); | ||
} ); | ||
|
||
afterAll( async () => { | ||
await activateTheme( 'twentytwentyone' ); | ||
const resultsFilename = basename( __filename, '.js' ) + '.results.json'; | ||
writeFileSync( | ||
join( __dirname, resultsFilename ), | ||
JSON.stringify( results, null, 2 ) | ||
); | ||
} ); | ||
|
||
it( 'Time To First Byte (TTFB)', async () => { | ||
// We derive the 75th percentile of the TTFB based on these results. | ||
// By running it 16 times, the percentile value would be (75/100)*16=12, | ||
// meaning that we discard the worst 4 values. | ||
let i = 16; | ||
while ( i-- ) { | ||
await page.goto( createURL( '/' ) ); | ||
const navigationTimingJson = await page.evaluate( () => | ||
JSON.stringify( performance.getEntriesByType( 'navigation' ) ) | ||
); | ||
const [ navigationTiming ] = JSON.parse( navigationTimingJson ); | ||
results.timeToFirstByte.push( | ||
navigationTiming.responseStart - navigationTiming.startTime | ||
); | ||
} | ||
} ); | ||
} ); |
45 changes: 45 additions & 0 deletions
45
packages/e2e-tests/specs/performance/front-end-classic-theme.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { basename, join } from 'path'; | ||
import { writeFileSync } from 'fs'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { createURL, logout } from '@wordpress/e2e-test-utils'; | ||
|
||
describe( 'Front End Performance', () => { | ||
const results = { | ||
timeToFirstByte: [], | ||
}; | ||
|
||
beforeAll( async () => { | ||
await logout(); | ||
} ); | ||
|
||
afterAll( async () => { | ||
const resultsFilename = basename( __filename, '.js' ) + '.results.json'; | ||
writeFileSync( | ||
join( __dirname, resultsFilename ), | ||
JSON.stringify( results, null, 2 ) | ||
); | ||
} ); | ||
|
||
it( 'Time To First Byte (TTFB)', async () => { | ||
// We derive the 75th percentile of the TTFB based on these results. | ||
// By running it 16 times, the percentile value would be (75/100)*16=12, | ||
// meaning that we discard the worst 4 values. | ||
let i = 16; | ||
while ( i-- ) { | ||
await page.goto( createURL( '/' ) ); | ||
const navigationTimingJson = await page.evaluate( () => | ||
JSON.stringify( performance.getEntriesByType( 'navigation' ) ) | ||
); | ||
const [ navigationTiming ] = JSON.parse( navigationTimingJson ); | ||
results.timeToFirstByte.push( | ||
navigationTiming.responseStart - navigationTiming.startTime | ||
); | ||
} | ||
} ); | ||
} ); |