Skip to content

Commit

Permalink
better logging for unit-test tasks, and run in parallel, phetsims/per…
Browse files Browse the repository at this point in the history
  • Loading branch information
zepumph committed Dec 17, 2024
1 parent c48159b commit 35dfe6e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
4 changes: 2 additions & 2 deletions js/common/pre-commit/getPreCommitTasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ const SUPPORTED_TASKS = [ 'lint', 'report-media', 'type-check', 'unit-test', 'ph
const getPreCommitTasks = ( outputToConsole: boolean ): string[] => {


// By default, run all tasks
// By default, run all tasks
const OPT_OUT_ALL = '*'; // Key to opt out of all tasks
let tasksToRun = isOptionKeyProvided( OPT_OUT_ALL ) && !getOption( OPT_OUT_ALL ) ? [] : [ ...SUPPORTED_TASKS ];

// check local preferences for overrides for which tasks to turn 'off'
// check local preferences for overrides for which tasks to turn 'off'
const hookPreCommit = buildLocal.hookPreCommit;
if ( hookPreCommit && hookPreCommit[ OPT_OUT_ALL ] === false ) {
outputToConsole && console.log( 'all tasks opted out from build-local.json' );
Expand Down
19 changes: 13 additions & 6 deletions js/common/pre-commit/pre-commit-task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ const repo = getArg( 'repo' );
else if ( command === 'unit-test' ) {

// Run qunit tests if puppeteerQUnit exists in the checked-out SHAs and a test HTML exists.
const qUnitOK = await ( async () => {
const qUnitOKPromise = ( async () => {

const cacheKey = `puppeteerQUnit#${repo}`;

Expand All @@ -107,6 +107,7 @@ const repo = getArg( 'repo' );
return true;
}
else {
outputToConsole && console.log( 'unit-test: testing browser QUnit' );
const browser = await puppeteer.launch( {
args: [
'--disable-gpu'
Expand All @@ -130,14 +131,16 @@ const repo = getArg( 'repo' );
}
}
}
else {
outputToConsole && console.log( 'unit-test: no browser unit tests detected' );
}

outputToConsole && console.log( 'QUnit: no problems detected' );
return true;
}
return true;
} )();

const npmRunTestOk = await ( async () => {
const npmRunTestOkPromise = ( async () => {

// Detect the presence of npm run test by looking in package.json's scripts.test
let hasNpmRunTest = false;
Expand All @@ -152,15 +155,13 @@ const repo = getArg( 'repo' );
// no package.json or not parseable
}

outputToConsole && console.log( `npm run test exists: ${hasNpmRunTest}` );

if ( hasNpmRunTest ) {
outputToConsole && console.log( 'unit-test: testing "npm run test" task' );
const output = await execute( npmCommand, [ 'run', 'test' ], `../${repo}`, { errors: 'resolve' } );
const testPassed = output.code === 0;

( outputToConsole || !testPassed ) && output.stdout.length > 0 && console.log( output.stdout );
( outputToConsole || !testPassed ) && output.stderr.length > 0 && console.log( output.stderr );
( outputToConsole || !testPassed ) && console.log( `npm run test passed: ${testPassed}` );

return testPassed;
}
Expand All @@ -169,6 +170,12 @@ const repo = getArg( 'repo' );
}
} )();

const results = await Promise.all( [ qUnitOKPromise, npmRunTestOkPromise ] );
const qUnitOK = results[ 0 ];
const npmRunTestOk = results[ 1 ];
outputToConsole && console.log( `unit-test: QUnit browser success: ${qUnitOK}` );
outputToConsole && console.log( `unit-test: npm run test success: ${npmRunTestOk}` );

process.exit( ( qUnitOK && npmRunTestOk ) ? 0 : 1 );
}

Expand Down

0 comments on commit 35dfe6e

Please sign in to comment.