Skip to content

Commit

Permalink
optimize code
Browse files Browse the repository at this point in the history
  • Loading branch information
garysassano committed Sep 25, 2023
1 parent ed950a2 commit c58e7bc
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions apps/wing/src/commands/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { generateTmpDir, withSpinner } from "../util";
import { Target } from "@winglang/compiler";
import { nanoid } from "nanoid";
import { readFile, rm, rmSync } from "fs";
import { globSync } from "glob";
import { glob } from "glob";

const log = debug("wing:test");

Expand All @@ -30,18 +30,9 @@ export interface TestOptions extends CompileOptions {
}

export async function test(entrypoints: string[], options: TestOptions): Promise<number> {
// Initialize a Set to store unique file names
let expandedEntrypointsSet: Set<string> = new Set();

// Expand each entrypoint and add file names to the Set
for (const entrypoint of entrypoints) {
const expandedEntrypoint = globSync(entrypoint);
for (const fileName of expandedEntrypoint) {
expandedEntrypointsSet.add(fileName);
}
}
const expandedEntrypoints = await glob(entrypoints);

if (expandedEntrypointsSet.size === 0) {
if (expandedEntrypoints.length === 0) {
// Check if it's the default entrypoint
if (entrypoints[0] === "*.test.w") {
throw new Error("No '.test.w' files found in current directory.");
Expand All @@ -64,8 +55,7 @@ export async function test(entrypoints: string[], options: TestOptions): Promise
});
}
};
entrypoints = Array.from(expandedEntrypointsSet);
await Promise.all(entrypoints.map(testFile));
await Promise.all(expandedEntrypoints.map(testFile));
printResults(results, Date.now() - startTime);

// if we have any failures, exit with 1
Expand Down

0 comments on commit c58e7bc

Please sign in to comment.