8000 fix: do not stop crawling at `currentDepth` 0 (#149) · thecodrr/fdir@c2593d2 · GitHub
[go: up one dir, main page]

Skip to content

Commit c2593d2

Browse files
fix: do not stop crawling at currentDepth 0 (#149)
* fix: do not stop crawling at `currentDepth` 0 * chore: improve depth tests
1 parent 7a72642 commit c2593d2

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

__tests__/fdir.test.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,24 @@ for (const type of apiTypes) {
5252
includeBasePath: true,
5353
}).crawl("node_modules");
5454
const files = await api[type]();
55-
t.expect(files.every((file) => file.split("/").length <= 2)).toBe(true);
55+
t.expect(files).not.toHaveLength(0);
56+
t.expect(files.every((file) => file.split(path.sep).length === 2)).toBe(
57+
true
58+
);
5659
});
5760

5861
test(`[${type}] crawl multi depth directory with options`, async (t) => {
5962
const api = new fdir({
6063
maxDepth: 1,
64+
includeBasePath: true,
6165
}).crawl("node_modules");
6266
const files = await api[type]();
63-
t.expect(
64-
files.every((file) => file.split(path.sep).length <= 3)
65-
).toBeTruthy();
67+
t.expect(files.some((file) => file.split(path.sep).length === 3)).toBe(
68+
true
69+
);
70+
t.expect(files.every((file) => file.split(path.sep).length <= 3)).toBe(
71+
true
72+
);
6673
});
6774

6875
test(`[${type}] crawl multi depth directory`, async (t) => {

src/api/functions/walk-directory.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const walkAsync: WalkDirectoryFunction = (
2020
) => {
2121
state.queue.enqueue();
2222

23-
if (currentDepth <= 0) return state.queue.dequeue(null, state);
23+
if (currentDepth < 0) return state.queue.dequeue(null, state);
2424

2525
state.visited.push(crawlPath);
2626
state.counts.directories++;
@@ -41,7 +41,7 @@ const walkSync: WalkDirectoryFunction = (
4141
currentDepth,
4242
callback
4343
) => {
44-
if (currentDepth <= 0) return;
44+
if (currentDepth < 0) return;
4545
state.visited.push(crawlPath);
4646
state.counts.directories++;
4747

0 commit comments

Comments
 (0)
0