Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix running performance tests locally via CLI #49068

Merged
merged 2 commits into from
Mar 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions bin/plugin/commands/performance.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
const fs = require( 'fs' );
const path = require( 'path' );
const { mapValues, kebabCase } = require( 'lodash' );
const { mapValues } = require( 'lodash' );
const SimpleGit = require( 'simple-git' );

/**
Expand Down Expand Up @@ -83,6 +83,17 @@ const config = require( '../config' );
* @property {number=} maxListViewOpen Max time to open list view.
*/

/**
* Sanitizes branch name to be used in a path or a filename.
*
* @param {string} branch
*
* @return {string} Sanitized branch name.
*/
function sanitizeBranchName( branch ) {
return branch.replace( /[^a-zA-Z0-9-]/g, '-' );
}

/**
* Computes the average number from an array numbers.
*
Expand Down Expand Up @@ -299,8 +310,8 @@ async function runPerformanceTests( branches, options ) {
const branchDirectories = {};
for ( const branch of branches ) {
log( ` >> Branch: ${ branch }` );
const environmentDirectory =
rootDirectory + '/envs/' + kebabCase( branch );
const sanitizedBranch = sanitizeBranchName( branch );
const environmentDirectory = rootDirectory + '/envs/' + sanitizedBranch;
// @ts-ignore
branchDirectories[ branch ] = environmentDirectory;
const buildPath = `${ environmentDirectory }/plugin`;
Expand Down Expand Up @@ -401,7 +412,8 @@ async function runPerformanceTests( branches, options ) {
for ( let i = 0; i < TEST_ROUNDS; i++ ) {
rawResults[ i ] = {};
for ( const branch of branches ) {
const runKey = `${ branch }_${ testSuite }_run-${ i }`;
const sanitizedBranch = sanitizeBranchName( branch );
const runKey = `${ sanitizedBranch }_${ testSuite }_run-${ i }`;
// @ts-ignore
const environmentDirectory = branchDirectories[ branch ];
log( ` >> Branch: ${ branch }, Suite: ${ testSuite }` );
Expand Down
1 change: 1 addition & 0 deletions bin/plugin/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ function runShellScript( script, cwd, env = {} ) {
NO_CHECKS: 'true',
PATH: process.env.PATH,
HOME: process.env.HOME,
USER: process.env.USER,
...env,
},
},
Expand Down