@@ -454,7 +454,7 @@ const tsCheck = async (dir) => {
454454 analyzeTsConfig ( `${ path . resolve ( dir ) } /tsconfig.json` , [
455455 '--excludeDeclarationFiles' ,
456456 '--excludePathsFromReport=' +
457- 'jest/reporter.js;jest/environment.js; build.ts;ui-react/common.ts;' +
457+ 'build.ts;ui-react/common.ts;' +
458458 ALL_MODULES . map ( ( module ) => `${ module } .ts` ) . join ( ';' ) ,
459459 ] ) . unusedExports ,
460460 )
@@ -563,73 +563,34 @@ const compileModule = async (module, dir = DIST_DIR, min = false) => {
563563 }
564564} ;
565565
566- // coverageMode = 0: none; 1: screen; 2: json; 3: html
567- const test = async (
568- dirs ,
569- { coverageMode, countAsserts, puppeteer, serialTests} = { } ,
570- ) => {
571- const { default : jest } = await import ( 'jest' ) ;
572- await makeDir ( TMP_DIR ) ;
573- const {
574- results : { success} ,
575- } = await jest . runCLI (
576- {
577- roots : dirs ,
578- setupFilesAfterEnv : [ './test/jest/setup' ] ,
579- ...( puppeteer
580- ? {
581- setupFilesAfterEnv : [ 'expect-puppeteer' ] ,
582- preset : 'jest-puppeteer' ,
583- detectOpenHandles : true ,
584- maxWorkers : 2 ,
585- }
586- : { testEnvironment : './test/jest/environment' } ) ,
587- ...( coverageMode > 0
588- ? {
589- collectCoverage : true ,
590- coverageProvider : 'babel' ,
591- collectCoverageFrom : [
592- `${ DIST_DIR } /index.js` ,
593- `${ DIST_DIR } /ui-react/index.js` ,
594- // Other modules cannot be fully exercised in isolation.
595- ] ,
596- coverageReporters : [ 'text-summary' ]
597- . concat ( coverageMode > 1 ? [ 'json-summary' ] : [ ] )
598- . concat ( coverageMode > 2 ? [ 'lcov' ] : [ ] ) ,
599- coverageDirectory : 'tmp' ,
600- }
601- : { } ) ,
602- ...( countAsserts
603- ? {
604- testEnvironment : './test/jest/environment' ,
605- reporters : [ 'default' , './test/jest/reporter' ] ,
606- runInBand : true ,
607- }
608- : { } ) ,
609- ...( serialTests ? { runInBand : true } : { } ) ,
610- } ,
611- [ '' ] ,
612- ) ;
613- if ( ! success ) {
566+ const test = async ( dirs , coverage ) => {
567+ await clearDir ( TMP_DIR ) ;
568+
569+ const { startVitest} = await import ( 'vitest/node' ) ;
570+ const vitest = await startVitest ( 'test' , [ ...dirs ] , {
571+ watch : false ,
572+ retry : 3 ,
573+ coverage : { enabled : coverage } ,
574+ } ) ;
575+ await vitest . close ( ) ;
576+
577+ if ( vitest . state . getCountOfFailedTests ( ) > 0 ) {
614578 await removeDir ( TMP_DIR ) ;
615579 throw 'Test failed' ;
616580 }
617- if ( coverageMode == 2 ) {
581+
582+ if ( coverage ) {
618583 await promises . writeFile (
619584 'coverage.json' ,
620585 JSON . stringify ( {
621- ...( countAsserts
622- ? JSON . parse ( await promises . readFile ( './tmp/counts.json' ) )
623- : { } ) ,
624- ...JSON . parse ( await promises . readFile ( './tmp/coverage-summary.json' ) )
625- . total ,
586+ ...JSON . parse ( await promises . readFile ( './tmp/counts.json' ) ) ,
587+ ...JSON . parse (
588+ await promises . readFile ( './tmp/coverage/coverage-summary.json' ) ,
589+ ) . total ,
626590 } ) ,
627591 UTF8 ,
628592 ) ;
629593 }
630- if ( coverageMode < 3 ) {
631- await removeDir ( TMP_DIR ) ;
632- }
633594} ;
634595
635596const compileModulesForProd = async ( ) => {
@@ -710,7 +671,7 @@ export const ts = async () => {
710671export const compileForProd = ( ) => compileModulesForProd ( ) ;
711672
712673export const testUnit = async ( ) => {
713- await test ( [ 'test/unit' ] , { coverageMode : 1 , serialTests : true } ) ;
674+ await test ( [ 'test/unit' ] , true ) ;
714675} ;
715676
716677export const testBun = ( ) =>
@@ -721,23 +682,14 @@ export const testBun = () =>
721682 ) ;
722683
723684export const testUnitFast = async ( ) => {
724- await test ( [ 'test/unit/core' ] , { coverageMode : 1 } ) ;
725- } ;
726- export const testUnitCountAsserts = async ( ) => {
727- await test ( [ 'test/unit' ] , { coverageMode : 2 , countAsserts : true } ) ;
728- } ;
729- export const testUnitSaveCoverage = async ( ) => {
730- await test ( [ 'test/unit/core' ] , { coverageMode : 3 } ) ;
685+ await test ( [ 'test/unit/core' ] ) ;
731686} ;
687+
732688export const compileAndTestUnit = series ( compileForTest , testUnit ) ;
733689export const compileAndTestUnitFast = series ( compileForTest , testUnitFast ) ;
734- export const compileAndTestUnitSaveCoverage = series (
735- compileForTest ,
736- testUnitSaveCoverage ,
737- ) ;
738690
739691export const testPerf = async ( ) => {
740- await test ( [ 'test/perf' ] , { serialTests : true } ) ;
692+ await test ( [ 'test/perf' ] ) ;
741693} ;
742694export const compileAndTestPerf = series ( compileForTest , testPerf ) ;
743695
@@ -749,7 +701,7 @@ export const compileDocs = () => compileDocsAndAssets();
749701
750702export const compileForProdAndDocs = series ( compileForProd , compileDocs ) ;
751703
752- export const testE2e = ( ) => test ( [ 'test/e2e' ] , { puppeteer : true } ) ;
704+ export const testE2e = ( ) => test ( [ 'test/e2e' ] ) ;
753705
754706export const compileAndTestE2e = series ( compileForProdAndDocs , testE2e ) ;
755707
@@ -777,7 +729,7 @@ export const prePublishPackage = series(
777729 compileForTest ,
778730 parallel ( lint , spell , ts ) ,
779731 testBun ,
780- testUnitCountAsserts ,
732+ testUnit ,
781733 testPerf ,
782734 compileForProd ,
783735 testProd ,
0 commit comments