wordpress-develop/tests/performance/utils.js
Pascal Birchler 5a838d1bb7 Build/Test Tools: Migrate Puppeteer tests to Playwright.
As per the migration plan shared last year, this migrates all browser-based tests in WordPress core to use Playwright.
This includes end-to-end, performance, and visual regression tests.

Props swissspidy, mamaduka, kevin940726, bartkalisz, desrosj, adamsilverstein.
Fixes #59517.

git-svn-id: https://develop.svn.wordpress.org/trunk@56926 602fd350-edb4-49c9-b593-d223f7449a82
2023-10-13 08:11:41 +00:00

40 lines
887 B
JavaScript

/**
* Computes the median number from an array numbers.
*
* @param {number[]} array
*
* @return {number} Median.
*/
function median( array ) {
const mid = Math.floor( array.length / 2 );
const numbers = [ ...array ].sort( ( a, b ) => a - b );
return array.length % 2 !== 0
? numbers[ mid ]
: ( numbers[ mid - 1 ] + numbers[ mid ] ) / 2;
}
/**
* Gets the result file name.
*
* @param {string} fileName File name.
*
* @return {string} Result file name.
*/
function getResultsFilename( fileName ) {
const prefix = process.env.TEST_RESULTS_PREFIX;
const fileNamePrefix = prefix ? `${ prefix.split( '=' )[ 1 ] }-` : '';
return `${fileNamePrefix + fileName}.results.json`;
}
function camelCaseDashes( str ) {
return str.replace( /-([a-z])/g, function( g ) {
return g[ 1 ].toUpperCase();
} );
}
module.exports = {
median,
getResultsFilename,
camelCaseDashes,
};