feat(cli): Enhance test discovery with support for single file and glob pattern execution using improved CLI argument detection

This commit is contained in:
2025-05-15 14:37:55 +00:00
parent 1f73751a8c
commit a57edeef64
11 changed files with 1660 additions and 1252 deletions

View File

@@ -1,10 +1,29 @@
import { TsTest } from './tstest.classes.tstest.js';
export enum TestExecutionMode {
DIRECTORY = 'directory',
FILE = 'file',
GLOB = 'glob'
}
export const runCli = async () => {
if (!process.argv[2]) {
console.error('You must specify a test directory as argument. Please try again.');
console.error('You must specify a test directory/file/pattern as argument. Please try again.');
process.exit(1);
}
const tsTestInstance = new TsTest(process.cwd(), process.argv[2]);
const testPath = process.argv[2];
let executionMode: TestExecutionMode;
// Detect execution mode based on the argument
if (testPath.includes('*') || testPath.includes('?') || testPath.includes('[') || testPath.includes('{')) {
executionMode = TestExecutionMode.GLOB;
} else if (testPath.endsWith('.ts')) {
executionMode = TestExecutionMode.FILE;
} else {
executionMode = TestExecutionMode.DIRECTORY;
}
const tsTestInstance = new TsTest(process.cwd(), testPath, executionMode);
await tsTestInstance.run();
};