feat(cli): Add --startFrom and --stopAt options to filter test files by range

This commit is contained in:
2025-05-23 23:05:38 +00:00
parent 83b324b09f
commit 27c950c1a1
4 changed files with 80 additions and 10 deletions

View File

@@ -16,6 +16,8 @@ export class TsTest {
public executionMode: TestExecutionMode;
public logger: TsTestLogger;
public filterTags: string[];
public startFromFile: number | null;
public stopAtFile: number | null;
public smartshellInstance = new plugins.smartshell.Smartshell({
executor: 'bash',
@@ -26,16 +28,35 @@ export class TsTest {
public tsbundleInstance = new plugins.tsbundle.TsBundle();
constructor(cwdArg: string, testPathArg: string, executionModeArg: TestExecutionMode, logOptions: LogOptions = {}, tags: string[] = []) {
constructor(cwdArg: string, testPathArg: string, executionModeArg: TestExecutionMode, logOptions: LogOptions = {}, tags: string[] = [], startFromFile: number | null = null, stopAtFile: number | null = null) {
this.executionMode = executionModeArg;
this.testDir = new TestDirectory(cwdArg, testPathArg, executionModeArg);
this.logger = new TsTestLogger(logOptions);
this.filterTags = tags;
this.startFromFile = startFromFile;
this.stopAtFile = stopAtFile;
}
async run() {
const testGroups = await this.testDir.getTestFileGroups();
const allFiles = [...testGroups.serial, ...Object.values(testGroups.parallelGroups).flat()];
let allFiles = [...testGroups.serial, ...Object.values(testGroups.parallelGroups).flat()];
// Apply file range filtering if specified
if (this.startFromFile !== null || this.stopAtFile !== null) {
const startIndex = this.startFromFile ? this.startFromFile - 1 : 0; // Convert to 0-based index
const endIndex = this.stopAtFile ? this.stopAtFile : allFiles.length;
allFiles = allFiles.slice(startIndex, endIndex);
// Filter the serial and parallel groups based on remaining files
testGroups.serial = testGroups.serial.filter(file => allFiles.includes(file));
Object.keys(testGroups.parallelGroups).forEach(groupName => {
testGroups.parallelGroups[groupName] = testGroups.parallelGroups[groupName].filter(file => allFiles.includes(file));
// Remove empty groups
if (testGroups.parallelGroups[groupName].length === 0) {
delete testGroups.parallelGroups[groupName];
}
});
}
// Log test discovery
this.logger.testDiscovery(