Skip to content

Commit 8b5a86c

Browse files
committed
refactor: enhance walkDir function to support depth parameter for directory traversal
1 parent be33a72 commit 8b5a86c

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

src/tools/percy-snapshot-utils/detect-test-files.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,13 @@ import {
1616

1717
import { DetectionConfig } from "../percy-snapshot-utils/types.js";
1818

19-
async function walkDir(dir: string, extensions: string[]): Promise<string[]> {
19+
async function walkDir(
20+
dir: string,
21+
extensions: string[],
22+
depth: number = 6,
23+
): Promise<string[]> {
2024
const result: string[] = [];
25+
if (depth < 0) return result;
2126
try {
2227
const entries = await fs.promises.readdir(dir, { withFileTypes: true });
2328

@@ -26,7 +31,7 @@ async function walkDir(dir: string, extensions: string[]): Promise<string[]> {
2631

2732
if (entry.isDirectory()) {
2833
if (!EXCLUDED_DIRS.has(entry.name) && !entry.name.startsWith(".")) {
29-
result.push(...(await walkDir(fullPath, extensions)));
34+
result.push(...(await walkDir(fullPath, extensions, depth - 1)));
3035
}
3136
} else if (extensions.some((ext) => entry.name.endsWith(ext))) {
3237
result.push(fullPath);
@@ -112,7 +117,7 @@ export async function listTestFiles(
112117
// Step 1: Collect all files with matching extensions
113118
let files: string[] = [];
114119
try {
115-
files = await walkDir(baseDir, config.extensions);
120+
files = await walkDir(baseDir, config.extensions, 6);
116121
} catch {
117122
return [];
118123
}
@@ -151,7 +156,7 @@ export async function listTestFiles(
151156
// Step 4: Handle SpecFlow .feature files for C# + SpecFlow
152157
if (language === "csharp" && framework === "specflow") {
153158
try {
154-
const featureFiles = await walkDir(baseDir, [".feature"]);
159+
const featureFiles = await walkDir(baseDir, [".feature"], 6);
155160
featureFiles.forEach((file) => candidateFiles.set(file, 2));
156161
logger.info(`Added ${featureFiles.length} SpecFlow .feature files`);
157162
} catch {

src/tools/review-agent-utils/percy-snapshots.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ export async function getChangedPercySnapshotIds(
99
orgId: string | undefined,
1010
browserIds: string[],
1111
): Promise<string[]> {
12-
1312
if (!buildId || !orgId) {
1413
throw new Error(
1514
"Failed to fetch AI Summary: Missing build ID or organization ID",

0 commit comments

Comments
 (0)