feat(cli): Add --startFrom and --stopAt options to filter test files by range
This commit is contained in:
		
							
								
								
									
										55
									
								
								ts/index.ts
									
									
									
									
									
								
							
							
						
						
									
										55
									
								
								ts/index.ts
									
									
									
									
									
								
							| @@ -13,6 +13,8 @@ export const runCli = async () => { | ||||
|   const logOptions: LogOptions = {}; | ||||
|   let testPath: string | null = null; | ||||
|   let tags: string[] = []; | ||||
|   let startFromFile: number | null = null; | ||||
|   let stopAtFile: number | null = null; | ||||
|    | ||||
|   // Parse options | ||||
|   for (let i = 0; i < args.length; i++) { | ||||
| @@ -42,6 +44,32 @@ export const runCli = async () => { | ||||
|           tags = args[++i].split(','); | ||||
|         } | ||||
|         break; | ||||
|       case '--startFrom': | ||||
|         if (i + 1 < args.length) { | ||||
|           const value = parseInt(args[++i], 10); | ||||
|           if (isNaN(value) || value < 1) { | ||||
|             console.error('Error: --startFrom must be a positive integer'); | ||||
|             process.exit(1); | ||||
|           } | ||||
|           startFromFile = value; | ||||
|         } else { | ||||
|           console.error('Error: --startFrom requires a number argument'); | ||||
|           process.exit(1); | ||||
|         } | ||||
|         break; | ||||
|       case '--stopAt': | ||||
|         if (i + 1 < args.length) { | ||||
|           const value = parseInt(args[++i], 10); | ||||
|           if (isNaN(value) || value < 1) { | ||||
|             console.error('Error: --stopAt must be a positive integer'); | ||||
|             process.exit(1); | ||||
|           } | ||||
|           stopAtFile = value; | ||||
|         } else { | ||||
|           console.error('Error: --stopAt requires a number argument'); | ||||
|           process.exit(1); | ||||
|         } | ||||
|         break; | ||||
|       default: | ||||
|         if (!arg.startsWith('-')) { | ||||
|           testPath = arg; | ||||
| @@ -49,16 +77,24 @@ export const runCli = async () => { | ||||
|     } | ||||
|   } | ||||
|    | ||||
|   // Validate test file range options | ||||
|   if (startFromFile !== null && stopAtFile !== null && startFromFile > stopAtFile) { | ||||
|     console.error('Error: --startFrom cannot be greater than --stopAt'); | ||||
|     process.exit(1); | ||||
|   } | ||||
|    | ||||
|   if (!testPath) { | ||||
|     console.error('You must specify a test directory/file/pattern as argument. Please try again.'); | ||||
|     console.error('\nUsage: tstest <path> [options]'); | ||||
|     console.error('\nOptions:'); | ||||
|     console.error('  --quiet, -q     Minimal output'); | ||||
|     console.error('  --verbose, -v   Verbose output'); | ||||
|     console.error('  --no-color      Disable colored output'); | ||||
|     console.error('  --json          Output results as JSON'); | ||||
|     console.error('  --logfile       Write logs to .nogit/testlogs/[testfile].log'); | ||||
|     console.error('  --tags          Run only tests with specified tags (comma-separated)'); | ||||
|     console.error('  --quiet, -q       Minimal output'); | ||||
|     console.error('  --verbose, -v     Verbose output'); | ||||
|     console.error('  --no-color        Disable colored output'); | ||||
|     console.error('  --json            Output results as JSON'); | ||||
|     console.error('  --logfile         Write logs to .nogit/testlogs/[testfile].log'); | ||||
|     console.error('  --tags <tags>     Run only tests with specified tags (comma-separated)'); | ||||
|     console.error('  --startFrom <n>   Start running from test file number n'); | ||||
|     console.error('  --stopAt <n>      Stop running at test file number n'); | ||||
|     process.exit(1); | ||||
|   } | ||||
|    | ||||
| @@ -73,6 +109,11 @@ export const runCli = async () => { | ||||
|     executionMode = TestExecutionMode.DIRECTORY; | ||||
|   } | ||||
|    | ||||
|   const tsTestInstance = new TsTest(process.cwd(), testPath, executionMode, logOptions, tags); | ||||
|   const tsTestInstance = new TsTest(process.cwd(), testPath, executionMode, logOptions, tags, startFromFile, stopAtFile); | ||||
|   await tsTestInstance.run(); | ||||
| }; | ||||
|  | ||||
| // Execute CLI when this file is run directly | ||||
| if (import.meta.url === `file://${process.argv[1]}`) { | ||||
|   runCli(); | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user