Skip to content

Commit

Permalink
add support for npm run tests, #223
Browse files Browse the repository at this point in the history
  • Loading branch information
zepumph committed Nov 13, 2024
1 parent 966fba7 commit 7f61cb6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
12 changes: 12 additions & 0 deletions js/server/ContinuousServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const getRepoList = require( '../../../perennial/js/common/getRepoList.js' );
const gitPull = require( '../../../perennial/js/common/gitPull.js' );
const gitRevParse = require( '../../../perennial/js/common/gitRevParse.js' );
const gruntCommand = require( '../../../perennial/js/common/gruntCommand.js' );
const npmCommand = require( '../../../perennial/js/common/npmCommand.js' );
const isStale = require( '../../../perennial/js/common/isStale.js' );
const npmUpdate = require( '../../../perennial/js/common/npmUpdate.js' );
const transpileAll = require( '../../../perennial/js/common/transpileAll.js' );
Expand Down Expand Up @@ -660,6 +661,17 @@ class ContinuousServer {
ContinuousServer.testFail( test, Date.now() - startTimestamp, `Lint-everything failed with status code ${e.code}:\n${e.stdout}\n${e.stderr}`.trim() );
}
}
else if ( test.type === 'npm-run' ) {
test.complete = true;
try {
const output = await execute( npmCommand, [ 'run', ...test.testCommand.split( ' ' ) ], `${snapshot.directory}/${test.repo}` );

ContinuousServer.testPass( test, Date.now() - startTimestamp, output );
}
catch( e ) {
ContinuousServer.testFail( test, Date.now() - startTimestamp, `Lint-everything failed with status code ${e.code}:\n${e.stdout}\n${e.stderr}`.trim() );
}
}
else if ( test.type === 'build' ) {
test.complete = true;
try {
Expand Down
16 changes: 13 additions & 3 deletions js/server/Test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,15 @@ const assert = require( 'assert' );
const _ = require( 'lodash' );

// constants
const TEST_TYPES = [
const LOCAL_TEST_TYPES = [
'lint',
'lint-everything',
'build',
'npm-run'
];

const TEST_TYPES = [
...LOCAL_TEST_TYPES,
'sim-test',
'qunit-test',
'pageload-test',
Expand Down Expand Up @@ -72,7 +77,7 @@ class Test {
// @public {string|null}
this.repo = null;

if ( this.type === 'lint' || this.type === 'build' ) {
if ( this.type === 'lint' || this.type === 'build' || this.type === 'npm-run' ) {
assert( typeof description.repo === 'string', `${this.type} tests should have a repo` );

this.repo = description.repo;
Expand Down Expand Up @@ -138,6 +143,11 @@ class Test {
this.count = 0;
}

get testCommand() {
assert( this.type === 'npm run', 'command only supported for npm running' );
return this.description.command;
}

/**
* Records a test result
* @public
Expand All @@ -157,7 +167,7 @@ class Test {
* @returns {boolean}
*/
isLocallyAvailable() {
return !this.complete && ( this.type === 'lint' || this.type === 'lint-everything' || this.type === 'build' );
return !this.complete && LOCAL_TEST_TYPES.includes( this.type );
}

/**
Expand Down

0 comments on commit 7f61cb6

Please sign in to comment.