mirror of
git://develop.git.wordpress.org/
synced 2025-02-24 16:43:06 +01:00
56 lines
1.4 KiB
JavaScript
56 lines
1.4 KiB
JavaScript
|
/**
|
||
|
* External dependencies.
|
||
|
*/
|
||
|
const { basename, join } = require( 'path' );
|
||
|
const { writeFileSync } = require( 'fs' );
|
||
|
const { exec } = require( 'child_process' );
|
||
|
const { getResultsFilename } = require( './../utils' );
|
||
|
|
||
|
/**
|
||
|
* WordPress dependencies.
|
||
|
*/
|
||
|
import { activateTheme, createURL } from '@wordpress/e2e-test-utils';
|
||
|
|
||
|
describe( 'Server Timing - Twenty Twenty One', () => {
|
||
|
const results = {
|
||
|
wpBeforeTemplate: [],
|
||
|
wpTemplate: [],
|
||
|
wpTotal: [],
|
||
|
};
|
||
|
|
||
|
beforeAll( async () => {
|
||
|
await activateTheme( 'twentytwentyone' );
|
||
|
await exec( 'npm run env:cli -- menu location assign all-pages primary' );
|
||
|
} );
|
||
|
|
||
|
afterAll( async () => {
|
||
|
const resultsFilename = getResultsFilename( basename( __filename, '.js' ) );
|
||
|
writeFileSync(
|
||
|
join( __dirname, resultsFilename ),
|
||
|
JSON.stringify( results, null, 2 )
|
||
|
);
|
||
|
} );
|
||
|
|
||
|
it( 'Server Timing Metrics', async () => {
|
||
|
let i = TEST_RUNS;
|
||
|
while ( i-- ) {
|
||
|
await page.goto( createURL( '/' ) );
|
||
|
const navigationTimingJson = await page.evaluate( () =>
|
||
|
JSON.stringify( performance.getEntriesByType( 'navigation' ) )
|
||
|
);
|
||
|
|
||
|
const [ navigationTiming ] = JSON.parse( navigationTimingJson );
|
||
|
|
||
|
results.wpBeforeTemplate.push(
|
||
|
navigationTiming.serverTiming[0].duration
|
||
|
);
|
||
|
results.wpTemplate.push(
|
||
|
navigationTiming.serverTiming[1].duration
|
||
|
);
|
||
|
results.wpTotal.push(
|
||
|
navigationTiming.serverTiming[2].duration
|
||
|
);
|
||
|
}
|
||
|
} );
|
||
|
} );
|