@@ -853,7 +853,7 @@ export const handlers: Handler[] = [
853853 const mochaScriptName = scripts [ "test:mocha" ] !== undefined ? "test:mocha" : "test" ;
854854 const mochaScript = scripts [ mochaScriptName ] ;
855855
856- if ( ! mochaScript || ! mochaScript . startsWith ( "mocha" ) ) {
856+ if ( mochaScript === undefined || ! mochaScript . startsWith ( "mocha" ) ) {
857857 // skip irregular test script for now
858858 return undefined ;
859859 }
@@ -871,4 +871,63 @@ export const handlers: Handler[] = [
871871 }
872872 } ,
873873 } ,
874+
875+ {
876+ name : "npm-package-json-script-jest-config" ,
877+ match,
878+ handler : ( file , root ) => {
879+ let json ;
880+
881+ try {
882+ json = JSON . parse ( readFile ( file ) ) ;
883+ } catch ( err ) {
884+ return "Error parsing JSON file: " + file ;
885+ }
886+
887+ const scripts = json . scripts ;
888+ if ( scripts === undefined ) {
889+ return undefined ;
890+ }
891+ const jestScriptName = scripts [ "test:jest" ] !== undefined ? "test:jest" : "test" ;
892+ const jestScript = scripts [ jestScriptName ] ;
893+
894+ if ( jestScript === undefined || ! jestScript . startsWith ( "jest" ) ) {
895+ // skip irregular test script for now
896+ return undefined ;
897+ }
898+
899+ const packageDir = path . dirname ( file ) ;
900+ const jestFileName = [ "jest.config.js" , "jest.config.cjs" ] . find ( ( name ) =>
901+ fs . existsSync ( path . join ( packageDir , name ) ) ,
902+ ) ;
903+ if ( jestFileName === undefined ) {
904+ return `Missing jest config file.` ;
905+ }
906+
907+ const jestConfigFile = path . join ( packageDir , jestFileName ) ;
908+ const config = require ( path . resolve ( jestConfigFile ) ) ;
909+ if ( config . reporters === undefined ) {
910+ return `Missing reporters in '${ jestConfigFile } '` ;
911+ }
912+
913+ const expectedReporter = [
914+ "default" ,
915+ [
916+ "jest-junit" ,
917+ {
918+ outputDirectory : "nyc" ,
919+ outputName : "jest-junit-report.xml" ,
920+ } ,
921+ ] ,
922+ ] ;
923+
924+ if ( JSON . stringify ( config . reporters ) !== JSON . stringify ( expectedReporter ) ) {
925+ return `Unexpected reporters in '${ jestConfigFile } '` ;
926+ }
927+
928+ if ( json [ "jest-junit" ] !== undefined ) {
929+ return `Extraneous jest-unit config in ${ file } ` ;
930+ }
931+ } ,
932+ } ,
874933] ;
0 commit comments