Skip to content

Commit

Permalink
fix: test patterna and line number
Browse files Browse the repository at this point in the history
  • Loading branch information
khalatevarun committed Feb 27, 2025
1 parent 1f71e1f commit 86abd48
Show file tree
Hide file tree
Showing 3 changed files with 1,138 additions and 584 deletions.
9 changes: 3 additions & 6 deletions packages/shortest/src/cli/bin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,17 +175,14 @@ const main = async () => {
const baseUrl = args
.find((arg) => arg.startsWith("--target="))
?.split("=")[1];
const testPattern = args.find((arg) => !arg.startsWith("--"));
let testPattern = args.find((arg) => !arg.startsWith("--"));
const noCache = args.includes("--no-cache");
let testFile: string | undefined;
let lineNumber: number | undefined;

if (testPattern?.includes(":")) {
const [file, line] = testPattern.split(":");
testFile = file;
testPattern = file;
lineNumber = parseInt(line, 10);
} else {
testFile = testPattern;
}

const cliOptions: CLIOptions = {
Expand All @@ -204,7 +201,7 @@ const main = async () => {
log.trace("Initializing TestRunner");
const runner = new TestRunner(process.cwd(), config);
await runner.initialize();
const success = await runner.execute(config.testPattern);
const success = await runner.execute(config.testPattern, lineNumber);
process.exitCode = success ? 0 : 1;
} catch (error: any) {
log.trace("Handling error for TestRunner");
Expand Down
12 changes: 3 additions & 9 deletions packages/shortest/src/core/runner/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -464,14 +464,14 @@ export class TestRunner {
// await this.initialize();
// const files = await this.findTestFiles(pattern);

async execute(testPattern: string): Promise<boolean> {
async execute(testPattern: string, lineNumber?: number): Promise<boolean> {
this.log.trace("Finding test files", { testPattern });

const files = await glob(testPattern, {
cwd: this.cwd,
absolute: true,
});


if (files.length === 0) {
this.reporter.error(
"Test Discovery",
Expand All @@ -483,13 +483,7 @@ export class TestRunner {
return false;
}

let lineNumber: number | undefined;

if (testPattern?.includes(":")) {
const [_, line] = testPattern.split(":");
lineNumber = parseInt(line, 10);
}



this.reporter.onRunStart(files.length);
for (const file of files) {
Expand Down
Loading

0 comments on commit 86abd48

Please sign in to comment.