@@ -21,6 +21,7 @@ const bunRuntime = (globalThis as unknown as { Bun: BunRuntime }).Bun;
2121const WEB_ROOT = resolve ( process . cwd ( ) , "packages/web" ) ;
2222const WEB_SRC = resolve ( WEB_ROOT , "src" ) ;
2323const WEB_TEST_FILE_PATTERN = / \. ( s p e c | t e s t ) \. [ t j ] s x ? $ / ;
24+ const DEFAULT_WEB_TEST_BATCH_SIZE = 3 ;
2425
2526const TEST_PROJECTS = {
2627 backend : {
@@ -62,6 +63,26 @@ function findWebTestFiles(dir: string): string[] {
6263 . sort ( ) ;
6364}
6465
66+ function chunk < T > ( items : T [ ] , size : number ) : T [ ] [ ] {
67+ const chunks : T [ ] [ ] = [ ] ;
68+
69+ for ( let index = 0 ; index < items . length ; index += size ) {
70+ chunks . push ( items . slice ( index , index + size ) ) ;
71+ }
72+
73+ return chunks ;
74+ }
75+
76+ function getWebTestBatchSize ( ) {
77+ const configuredBatchSize = Number ( process . env [ "WEB_TEST_BATCH_SIZE" ] ) ;
78+
79+ if ( Number . isInteger ( configuredBatchSize ) && configuredBatchSize > 0 ) {
80+ return configuredBatchSize ;
81+ }
82+
83+ return DEFAULT_WEB_TEST_BATCH_SIZE ;
84+ }
85+
6586function assertBackendConfigFile ( ) {
6687 const configFilePath = resolve ( process . cwd ( ) , "compass.yaml" ) ;
6788
@@ -91,15 +112,16 @@ function runCommand(cmd: string[], cwd = process.cwd()) {
91112 }
92113}
93114
94- function runWebProject ( ) {
95- for ( const testFile of findWebTestFiles ( WEB_SRC ) ) {
96- runCommand ( [ process . execPath , "test" , "--cwd" , WEB_ROOT , testFile ] ) ;
97- }
98- }
99-
100115function runProject ( projectName : keyof typeof TEST_PROJECTS ) {
101116 if ( projectName === "web" ) {
102- runWebProject ( ) ;
117+ const testFileBatches = chunk (
118+ findWebTestFiles ( WEB_SRC ) ,
119+ getWebTestBatchSize ( ) ,
120+ ) ;
121+
122+ for ( const testFiles of testFileBatches ) {
123+ runCommand ( [ "bun" , "test" , "--cwd" , WEB_ROOT , ...testFiles ] ) ;
124+ }
103125 return ;
104126 }
105127
0 commit comments