From ef363d097d934c73f22b3b7e57795c83898ffc3d Mon Sep 17 00:00:00 2001 From: Miguel Fonseca Date: Thu, 27 May 2021 13:25:48 +0100 Subject: [PATCH] Workflows: Performance: Honour `--wp-version` option ... by patching the temporary test environment's `.wp-env.json` config. WIP add wpVersion option finish perf.js --- bin/plugin/cli.js | 4 ++++ bin/plugin/commands/performance.js | 17 +++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/bin/plugin/cli.js b/bin/plugin/cli.js index e3a22ebd3d603c..5dbaac5d08e869 100755 --- a/bin/plugin/cli.js +++ b/bin/plugin/cli.js @@ -62,6 +62,10 @@ program '--tests-branch ', "Use this branch's performance test files" ) + .option( + '--wp-version ', + 'Specify a WordPress version on which to test all branches' + ) .description( 'Runs performance tests on two separate branches and outputs the result' ) diff --git a/bin/plugin/commands/performance.js b/bin/plugin/commands/performance.js index 1af84ef1208dec..dcf3706f32f27b 100644 --- a/bin/plugin/commands/performance.js +++ b/bin/plugin/commands/performance.js @@ -22,6 +22,7 @@ const config = require( '../config' ); * * @property {boolean=} ci Run on CI. * @property {string=} testsBranch The branch whose performance test files will be used for testing. + * @property {string=} wpVersion The WordPress version to be used as the base install for testing. */ /** @@ -260,6 +261,22 @@ async function runPerformanceTests( branches, options ) { ); log( '>> Starting the WordPress environment' ); + if ( options.wpVersion ) { + // Patch the environment's .wp-env.json config to use the specified WP version: + // + // { + // "core": "https://wordpress.org/wordpress-$VERSION", + // ... + // } + // + // Only use the major version, i.e. 5.7.2 becomes 5.7. + const major = options.wpVersion.split( '.' ).slice( 0, 2 ).join( '.' ); + const zipUrl = `https:\\/\\/wordpress.org\\/wordpress-${ major }.zip`; + log( `Using WordPress version ${ major }` ); + await runShellScript( + `sed -I '' -e '/"core":/s/WordPress\\/WordPress/${ zipUrl }/' "${ environmentDirectory }/.wp-env.json"` + ); + } await runShellScript( 'npm run wp-env start', environmentDirectory ); const testSuites = [ 'post-editor', 'site-editor' ];