-
Notifications
You must be signed in to change notification settings - Fork 5
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
npm run test during precommit hooks #412
Comments
How about an optional fuzz test too? (maybe separate issue) |
This patch works well on mac: Subject: [PATCH] Rename tsc => check, see https://github.com/phetsims/perennial/issues/404
---
Index: js/common/pre-commit-main.ts
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/js/common/pre-commit-main.ts b/js/common/pre-commit-main.ts
--- a/js/common/pre-commit-main.ts (revision 87c763b7fa9ed79642f67e1a4e6305dcb43ca96f)
+++ b/js/common/pre-commit-main.ts (date 1733271353882)
@@ -7,6 +7,7 @@
* @author Michael Kauzmann (PhET Interactive Simulations)
*/
+import { spawnSync } from 'child_process';
import fs from 'fs';
import CacheLayer from '../../../chipper/js/common/CacheLayer.js';
import reportMedia from '../../../chipper/js/grunt/reportMedia.js';
@@ -20,6 +21,7 @@
import getPhetLibs from '../grunt/getPhetLibs.js';
import generatePhetioMacroAPI from '../phet-io/generatePhetioMacroAPI.js';
import phetioCompareAPISets from '../phet-io/phetioCompareAPISets.js';
+import npmCommand from '../../../perennial-alias/js/common/npmCommand.js';
type Repo = string;
@@ -189,4 +191,16 @@
process.exit( phetioAPIOK ? 0 : 1 );
}
+ else if ( command === 'npm-run-test' ) {
+
+ const result = spawnSync( npmCommand, [ 'run', 'test' ], {
+ cwd: `../${repo}`,
+ stdio: 'inherit'
+ } );
+
+ process.exit( result.status );
+ }
+ else {
+ throw new Error( `Unknown command: ${command}` );
+ }
} )();
\ No newline at end of file
Index: js/grunt/tasks/pre-commit.ts
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/js/grunt/tasks/pre-commit.ts b/js/grunt/tasks/pre-commit.ts
--- a/js/grunt/tasks/pre-commit.ts (revision 87c763b7fa9ed79642f67e1a4e6305dcb43ca96f)
+++ b/js/grunt/tasks/pre-commit.ts (date 1733270915618)
@@ -33,12 +33,13 @@
*/
import assert from 'assert';
+import fs from 'fs';
import path from 'path';
+import { Repo } from '../../../../perennial-alias/js/browser-and-node/PerennialTypes.js';
import buildLocal from '../../../../perennial-alias/js/common/buildLocal.js';
import dirname from '../../../../perennial-alias/js/common/dirname.js';
import execute from '../../../../perennial-alias/js/common/execute.js';
import getActiveRepos from '../../../../perennial-alias/js/common/getActiveRepos.js';
-import { Repo } from '../../../../perennial-alias/js/browser-and-node/PerennialTypes.js';
import phetTimingLog from '../../../../perennial-alias/js/common/phetTimingLog.js';
import tsxCommand from '../../../../perennial-alias/js/common/tsxCommand.js';
import getOption, { isOptionKeyProvided } from '../../../../perennial-alias/js/grunt/tasks/util/getOption.js';
@@ -82,6 +83,17 @@
const possibleTasks = [ 'lint', 'report-media', 'type-check', 'unit-test', 'phet-io-api' ];
+ try {
+ const packageString = fs.readFileSync( `../${repo}/package.json`, 'utf8' );
+ const packageJSON = JSON.parse( packageString );
+ if ( packageJSON.scripts?.hasOwnProperty( 'test' ) ) {
+ possibleTasks.push( 'npm-run-test' );
+ }
+ }
+ catch( e ) {
+ // no package.json or not parseable
+ }
+
// By default, run all tasks
let tasksToRun = [ ...possibleTasks ];
const OPT_OUT_ALL = '*'; // Key to opt out of all tasks
please be aware of #421 during your review. I confirmed this correctly ignores repos that do not have @zepumph can you please review and see what adjustments are necessary to run it on Windows? Also it appears this would be our first usage of |
This was done differently from Expanding on that thought, what if this was just a sub-section of I also recommend using |
Implemented as prescribed and ready for review in main. |
Oh sorry. I'm changing a few things I see in pre-commit code. |
Ok sorry, I kinda tore some things apart. I felt like we needed separate files for a lot of things, so I did a larger code review of the pre-commit task as part of this. I also added chipper browser unit tests to ensure we were well set up to test both. @samreid how do you feel about this? I also see a big problem here because of phetsims/chipper#1549. It was hard to tests chipper's browser qunit tests because the cache kept hitting. I ended up stubbing out CacheLayer.isCacheSafe() to always return false, there is probably a better way, but oh well. Let me know if you want to discuss. |
I skimmed through the commits and the direction seems good. I'm glad chipper has browser unit tests now. I did not run any sanity checks yet, wasn't sure how thorough a review was warranted. Want to specify or close? |
All good here. Thanks! |
From #384, we would like the precommit hooks to run any node tests that the package.json provides, like
npm run test
.The text was updated successfully, but these errors were encountered: