Skip to content

Commit

Permalink
Pass envs to child process instead creating new runner options
Browse files Browse the repository at this point in the history
  • Loading branch information
WunderBart committed Mar 15, 2023
1 parent 23b445c commit a53065b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 21 deletions.
28 changes: 14 additions & 14 deletions bin/plugin/commands/performance.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ const {
} = require( '../lib/utils' );
const config = require( '../config' );

const ARTIFACTS_PATH =
process.env.WP_ARTIFACTS_PATH || path.join( process.cwd(), 'artifacts' );

/**
* @typedef WPPerformanceCommandOptions
*
Expand Down Expand Up @@ -189,26 +192,25 @@ function curateResults( testSuite, results ) {
* @param {string} testSuite Name of the tests set.
* @param {string} performanceTestDirectory Path to the performance tests' clone.
* @param {string} runKey Unique identifier for the test run, e.g. `branch-name_post-editor_run-3`.
* @param {string} artifactsPath Path to save the test artifacts at.
*
* @return {Promise<WPPerformanceResults>} Performance results for the branch.
*/
async function runTestSuite(
testSuite,
performanceTestDirectory,
runKey,
artifactsPath
) {
async function runTestSuite( testSuite, performanceTestDirectory, runKey ) {
const resultsFilename = `${ runKey }.performance-results.json`;

await runShellScript(
`npm run test:performance -- ${ testSuite } --wordpress-artifacts-path=${ artifactsPath } --results-filename=${ resultsFilename }`,
performanceTestDirectory
`npm run test:performance -- ${ testSuite }`,
performanceTestDirectory,
{
...process.env,
WP_ARTIFACTS_PATH: ARTIFACTS_PATH,
RESULTS_FILENAME: resultsFilename,
}
);

return curateResults(
testSuite,
await readJSONFile( path.join( artifactsPath, resultsFilename ) )
await readJSONFile( path.join( ARTIFACTS_PATH, resultsFilename ) )
);
}

Expand All @@ -221,7 +223,6 @@ async function runTestSuite(
async function runPerformanceTests( branches, options ) {
const runningInCI = !! process.env.CI || !! options.ci;
const TEST_ROUNDS = options.rounds || 1;
const artifactsPath = process.env.WP_ARTIFACTS_PATH || '';

// The default value doesn't work because commander provides an array.
if ( branches.length === 0 ) {
Expand Down Expand Up @@ -444,8 +445,7 @@ async function runPerformanceTests( branches, options ) {
rawResults[ i ][ branch ] = await runTestSuite(
testSuite,
performanceTestDirectory,
runKey,
artifactsPath
runKey
);
log( ' >> Stopping the environment' );
await runShellScript(
Expand Down Expand Up @@ -514,7 +514,7 @@ async function runPerformanceTests( branches, options ) {

const resultsFilename = testSuite + '.performance-results.json';
fs.writeFileSync(
path.join( artifactsPath, resultsFilename ),
path.join( ARTIFACTS_PATH, resultsFilename ),
JSON.stringify( results[ testSuite ], null, 2 )
);
}
Expand Down
12 changes: 5 additions & 7 deletions packages/scripts/scripts/test-e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,10 @@ if ( hasArgInCLI( '--puppeteer-devtools' ) ) {
process.env.PUPPETEER_DEVTOOLS = 'true';
}

if ( hasArgInCLI( '--results-filename' ) ) {
process.env.RESULTS_FILENAME = getArgFromCLI( '--results-filename' );
}

const configsMapping = {
WP_BASE_URL: '--wordpress-base-url',
WP_USERNAME: '--wordpress-username',
WP_PASSWORD: '--wordpress-password',
WP_ARTIFACTS_PATH: '--wordpress-artifacts-path',
};

Object.entries( configsMapping ).forEach( ( [ envKey, argName ] ) => {
Expand All @@ -83,9 +78,12 @@ Object.entries( configsMapping ).forEach( ( [ envKey, argName ] ) => {
}
} );

// Set default artifacts path.
// Set the default artifacts path.
if ( ! process.env.WP_ARTIFACTS_PATH ) {
process.env.WP_ARTIFACTS_PATH = path.resolve( process.cwd(), 'artifacts' );
process.env.WP_ARTIFACTS_PATH = path.resolve(
process.env.GITHUB_WORKSPACE || process.cwd(),
'artifacts'
);
}

const cleanUpPrefixes = [ '--puppeteer-', '--wordpress-' ];
Expand Down

0 comments on commit a53065b

Please sign in to comment.