Skip to content

Commit

Permalink
Workflows: Performance: Honour --wp-version option
Browse files Browse the repository at this point in the history
... by patching the temporary test environment's `.wp-env.json` config.

WIP add wpVersion option

finish perf.js
  • Loading branch information
mcsf committed May 27, 2021
1 parent e02137d commit ef363d0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions bin/plugin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ program
'--tests-branch <branch>',
"Use this branch's performance test files"
)
.option(
'--wp-version <version>',
'Specify a WordPress version on which to test all branches'
)
.description(
'Runs performance tests on two separate branches and outputs the result'
)
Expand Down
17 changes: 17 additions & 0 deletions bin/plugin/commands/performance.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/

/**
Expand Down Expand Up @@ -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' ];
Expand Down

0 comments on commit ef363d0

Please sign in to comment.