test: add dir read check for walkDir (#1773)
* test: add dir read check for walkDir * Update ignore.ts * Update walkDir.test.ts * Update walkDir.test.ts
This commit is contained in:
parent
1ad3b60947
commit
1f62c325c8
4 changed files with 36 additions and 11 deletions
|
|
@ -64,6 +64,7 @@ export const DEFAULT_IGNORE_FILETYPES = [
|
|||
".gitkeep",
|
||||
".continueignore",
|
||||
"config.json",
|
||||
".csv",
|
||||
// "*.prompt", // can be incredibly confusing for the LLM to have another set of instructions injected into the prompt
|
||||
];
|
||||
export const defaultIgnoreFile = ignore().add(DEFAULT_IGNORE_FILETYPES);
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import { EventEmitter } from "events";
|
||||
import { Minimatch } from "minimatch";
|
||||
import path from "node:path";
|
||||
import { FileType, IDE } from "..";
|
||||
import { DEFAULT_IGNORE_DIRS, DEFAULT_IGNORE_FILETYPES } from "./ignore";
|
||||
import { FileType, IDE } from "../index.js";
|
||||
import { DEFAULT_IGNORE_DIRS, DEFAULT_IGNORE_FILETYPES } from "./ignore.js";
|
||||
|
||||
export interface WalkerOptions {
|
||||
isSymbolicLink?: boolean;
|
||||
|
|
@ -34,10 +34,7 @@ class Walker extends EventEmitter {
|
|||
sawError: boolean;
|
||||
exact: boolean | undefined;
|
||||
onlyDirs: boolean | undefined;
|
||||
constructor(
|
||||
opts: WalkerOptions = {},
|
||||
protected readonly ide: IDE,
|
||||
) {
|
||||
constructor(opts: WalkerOptions = {}, protected readonly ide: IDE) {
|
||||
super(opts as any);
|
||||
this.isSymbolicLink = opts.isSymbolicLink || false;
|
||||
this.path = opts.path || process.cwd();
|
||||
|
|
|
|||
|
|
@ -1,12 +1,13 @@
|
|||
import path from "path";
|
||||
import { walkDir, WalkerOptions } from "../indexing/walkDir";
|
||||
import FileSystemIde from "../util/filesystem";
|
||||
import { walkDir, WalkerOptions } from "../indexing/walkDir.js";
|
||||
import FileSystemIde from "../util/filesystem.js";
|
||||
import {
|
||||
addToTestDir,
|
||||
setUpTestDir,
|
||||
tearDownTestDir,
|
||||
TEST_DIR,
|
||||
} from "./testUtils/testDir";
|
||||
} from "./testUtils/testDir.js";
|
||||
|
||||
const ide = new FileSystemIde(TEST_DIR);
|
||||
|
||||
async function walkTestDir(
|
||||
|
|
@ -273,4 +274,30 @@ describe("walkDir", () => {
|
|||
);
|
||||
expect(results.some((file) => file.includes(".tmLanguage"))).toBe(false);
|
||||
});
|
||||
|
||||
test("should perform the same number of dir reads as 1 + the number of dirs that contain files", async () => {
|
||||
const files = [
|
||||
"a.txt",
|
||||
"b.py",
|
||||
"c.ts",
|
||||
"d/",
|
||||
"d/e.txt",
|
||||
"d/f.py",
|
||||
"d/g/",
|
||||
"d/g/h.ts",
|
||||
"d/g/i/",
|
||||
"d/g/i/j.ts",
|
||||
];
|
||||
|
||||
const numDirs = files.filter((file) => !file.includes(".")).length;
|
||||
const numDirsPlusTopLevelRead = numDirs + 1;
|
||||
|
||||
addToTestDir(files);
|
||||
|
||||
const mockListDir = jest.spyOn(ide, "listDir");
|
||||
|
||||
await walkTestDir();
|
||||
|
||||
expect(mockListDir).toHaveBeenCalledTimes(numDirsPlusTopLevelRead);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -61,8 +61,8 @@ class FileSystemIde implements IDE {
|
|||
dirent.isDirectory()
|
||||
? (2 as FileType.Directory)
|
||||
: dirent.isSymbolicLink()
|
||||
? (64 as FileType.SymbolicLink)
|
||||
: (1 as FileType.File),
|
||||
? (64 as FileType.SymbolicLink)
|
||||
: (1 as FileType.File),
|
||||
]);
|
||||
return Promise.resolve(all);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue