Skip to content

Commit 65d500b

Browse files
authored
fix: correct #137 hanging the tests on Windows (#139)
* fix: add a failing test * fix: don't slice the root when it's the root directory * fix: test both `sync` and `withPromise` properly * chore: revert formatting changes * fix: handle Windows root directories correctly * chore: revert the formatting change * chore: revert the formatting change * chore: re-add the whitespace after the comma * test: add an assertion to the test * chore: revert the formatting change (sorry)
1 parent b2ee512 commit 65d500b

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

__tests__/symlinks.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,9 +376,13 @@ for (const type of apiTypes) {
376376

377377
test(
378378
"doesn't hang when resolving symlinks in the root directory",
379-
async () => {
379+
async (t) => {
380380
const api = new fdir().withSymlinks({ resolvePaths: false }).crawl("/");
381-
await api[type]();
381+
const files = await api[type]();
382+
const expectedFiles = normalize(["/lib/file-1", "/usr/lib/file-1"])
383+
for (const expectedFile of expectedFiles) {
384+
t.expect(files).toContain(expectedFile);
385+
}
382386
},
383387
{ timeout: 1000 }
384388
);

src/api/walker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { basename, dirname } from "path";
2-
import { normalizePath } from "../utils";
2+
import { isRootDirectory, normalizePath } from "../utils";
33
import { ResultCallback, WalkerState, Options } from "../types";
44
import * as joinPath from "./functions/join-path";
55
import * as pushDirectory from "./functions/push-directory";
@@ -37,7 +37,7 @@ export class Walker<TOutput extends Output> {
3737

3838
this.root = normalizePath(root, options);
3939
this.state = {
40-
root: this.root === "/" ? this.root : this.root.slice(0, -1),
40+
root: isRootDirectory(this.root) ? this.root : this.root.slice(0, -1),
4141
// Perf: we explicitly tell the compiler to optimize for String arrays
4242
paths: [""].slice(0, 0),
4343
groups: [],

src/utils.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ export function convertSlashes(path: string, separator: PathSeparator) {
1717
return path.replace(SLASHES_REGEX, separator);
1818
}
1919

20+
export function isRootDirectory(path: string) {
21+
return path === "/" || /^[a-z]:\\$/i.test(path);
22+
}
23+
2024
export function normalizePath(
2125
path: string,
2226
options: {

0 commit comments

Comments
 (0)