From 6f702873386080f7177c3d4f2bd5840f1730f15f Mon Sep 17 00:00:00 2001 From: Sam Reid Date: Mon, 17 Oct 2022 15:31:13 -0600 Subject: [PATCH] Cache phet-io-api-comparison results on a repo-by-repo basis, see https://github.com/phetsims/chipper/issues/1325 --- js/scripts/hook-pre-commit.js | 36 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/js/scripts/hook-pre-commit.js b/js/scripts/hook-pre-commit.js index f88fd9b97..96a721270 100644 --- a/js/scripts/hook-pre-commit.js +++ b/js/scripts/hook-pre-commit.js @@ -166,39 +166,35 @@ const puppeteerQUnit = require( '../../../aqua/js/local/puppeteerQUnit' ); // const phetioAPIOK = await phetTimingLog.startAsync( 'phet-io-api-compare', async () => { + const getCacheKey = repo => `phet-io-api-compare#${repo}`; + // Test this repo and all phet-io sims that have it as a dependency. For instance, changing sun would test // every phet-io stable sim. const phetioAPIStable = getRepoList( 'phet-io-api-stable' ); - const reposToTest = phetioAPIStable.filter( phetioSimRepo => getPhetLibs( phetioSimRepo ).includes( repo ) ); + const reposToTest = phetioAPIStable + .filter( phetioSimRepo => getPhetLibs( phetioSimRepo ).includes( repo ) ) + + // Only worry about the ones that are not cached + .filter( repo => !CacheLayer.isCacheSafe( getCacheKey( repo ) ) ); if ( reposToTest.length > 0 ) { console.log( 'PhET-iO API testing: ' + reposToTest ); - const cacheKey = 'phet-io-api-testing_' + reposToTest.join( '_' ); - - if ( !CacheLayer.isCacheSafe( cacheKey ) ) { - - const proposedAPIs = await generatePhetioMacroAPI( reposToTest, { - showProgressBar: reposToTest.length > 1, - showMessagesFromSim: false - } ); + const proposedAPIs = await generatePhetioMacroAPI( reposToTest, { + showProgressBar: reposToTest.length > 1, + showMessagesFromSim: false + } ); - const phetioAPIComparisonSuccessful = await phetioCompareAPISets( reposToTest, proposedAPIs, {} ); + const phetioAPIComparisonSuccessful = await phetioCompareAPISets( reposToTest, proposedAPIs, {} ); - if ( phetioAPIComparisonSuccessful ) { - CacheLayer.onSuccess( cacheKey ); - } - - return phetioAPIComparisonSuccessful; + if ( phetioAPIComparisonSuccessful ) { + reposToTest.forEach( repo => CacheLayer.onSuccess( getCacheKey( repo ) ) ); } - else { - // Cached and cache is good - return true; - } + return phetioAPIComparisonSuccessful; } else { - console.log( 'PhET-iO API testing: no repos detected' ); + console.log( 'PhET-iO API testing: no repos to test' ); return true; } } );