From d760f6dd8a638e92b2ab664edc9bc70e77931ac0 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Wed, 22 Jul 2020 17:55:16 +0200 Subject: [PATCH 1/3] Perf Test: Change nesting of loops --- bin/plugin/commands/performance.js | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/bin/plugin/commands/performance.js b/bin/plugin/commands/performance.js index 421989173f44e6..e3bbb13046848a 100644 --- a/bin/plugin/commands/performance.js +++ b/bin/plugin/commands/performance.js @@ -246,18 +246,21 @@ async function runPerformanceTests( branches, options ) { const testSuites = [ 'post-editor', 'site-editor' ]; /** @type {Record>} */ - const results = {}; - for ( const testSuite of testSuites ) { - results[ testSuite ] = {}; - for ( const branch of branches ) { - results[ testSuite ][ - branch - ] = await getPerformanceResultsForBranch( - performanceTestDirectory, - environmentDirectory, - testSuite, - branch - ); + let results = {}; + for ( const branch of branches ) { + for ( const testSuite of testSuites ) { + results = { + ...results, + [ testSuite ]: { + ...results[ testSuite ], + [ branch ]: await getPerformanceResultsForBranch( + performanceTestDirectory, + environmentDirectory, + testSuite, + branch + ), + }, + }; } } From 1d60a0fce9a931d9b8b0bffcc15444de42dc6f56 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Wed, 22 Jul 2020 18:07:53 +0200 Subject: [PATCH 2/3] Split into two functions --- bin/plugin/commands/performance.js | 41 ++++++++++++++++-------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/bin/plugin/commands/performance.js b/bin/plugin/commands/performance.js index e3bbb13046848a..eaebbbcf86aeb6 100644 --- a/bin/plugin/commands/performance.js +++ b/bin/plugin/commands/performance.js @@ -117,21 +117,12 @@ function curateResults( results ) { } /** - * Runs the performance tests on a given branch. + * Set up the given branch for testing. * - * @param {string} performanceTestDirectory Path to the performance tests' clone. - * @param {string} environmentDirectory Path to the plugin environment's clone. - * @param {string} testSuite Name of the tests set. * @param {string} branch Branch name. - * - * @return {Promise} Performance results for the branch. + * @param {string} environmentDirectory Path to the plugin environment's clone. */ -async function getPerformanceResultsForBranch( - performanceTestDirectory, - environmentDirectory, - testSuite, - branch -) { +async function setUpGitBranch( branch, environmentDirectory ) { // Restore clean working directory (e.g. if `package-lock.json` has local // changes after install). await git.discardLocalChanges( environmentDirectory ); @@ -144,10 +135,17 @@ async function getPerformanceResultsForBranch( 'rm -rf node_modules && npm install && npm run build', environmentDirectory ); +} - log( - '>> Running the test on the ' + formats.success( branch ) + ' branch' - ); +/** + * Runs the performance tests on the current branch. + * + * @param {string} testSuite Name of the tests set. + * @param {string} performanceTestDirectory Path to the performance tests' clone. + * + * @return {Promise} Performance results for the branch. + */ +async function runTestSuite( testSuite, performanceTestDirectory ) { const results = []; for ( let i = 0; i < 3; i++ ) { await runShellScript( @@ -249,15 +247,20 @@ async function runPerformanceTests( branches, options ) { let results = {}; for ( const branch of branches ) { for ( const testSuite of testSuites ) { + await setUpGitBranch( branch, environmentDirectory ); + log( + '>> Running the test on the ' + + formats.success( branch ) + + ' branch' + ); + results = { ...results, [ testSuite ]: { ...results[ testSuite ], - [ branch ]: await getPerformanceResultsForBranch( - performanceTestDirectory, - environmentDirectory, + [ branch ]: await runTestSuite( testSuite, - branch + performanceTestDirectory ), }, }; From 01c9347df9e8f53cd7e51abf7587b1e4f3f11270 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Wed, 22 Jul 2020 18:08:44 +0200 Subject: [PATCH 3/3] Set up branch only once for each test suite --- bin/plugin/commands/performance.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/bin/plugin/commands/performance.js b/bin/plugin/commands/performance.js index eaebbbcf86aeb6..213341db0d08ac 100644 --- a/bin/plugin/commands/performance.js +++ b/bin/plugin/commands/performance.js @@ -246,14 +246,14 @@ async function runPerformanceTests( branches, options ) { /** @type {Record>} */ let results = {}; for ( const branch of branches ) { - for ( const testSuite of testSuites ) { - await setUpGitBranch( branch, environmentDirectory ); - log( - '>> Running the test on the ' + - formats.success( branch ) + - ' branch' - ); + await setUpGitBranch( branch, environmentDirectory ); + log( + '>> Running the test on the ' + + formats.success( branch ) + + ' branch' + ); + for ( const testSuite of testSuites ) { results = { ...results, [ testSuite ]: {