Skip to content

Commit

Permalink
Add skeleton for front-end tests
Browse files Browse the repository at this point in the history
  • Loading branch information
oandregal committed Jan 10, 2023
1 parent 169dc1b commit 1e28776
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions packages/e2e-tests/specs/performance/front-end.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* External dependencies
*/
import { basename, join } from 'path';
import { writeFileSync } from 'fs';

/**
* WordPress dependencies
*/
import { createURL } from '@wordpress/e2e-test-utils';

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

afterAll( async () => {
const resultsFilename = basename( __filename, '.js' ) + '.results.json';
writeFileSync(
join( __dirname, resultsFilename ),
JSON.stringify( results, null, 2 )
);
} );

it( '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(
navigationTiming.responseStart - navigationTiming.requestStart
);
}
} );
} );

0 comments on commit 1e28776

Please sign in to comment.