tstest/ts/index.ts

30 lines
883 B
TypeScript

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/file/pattern as argument. Please try again.');
process.exit(1);
}
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();
};