Implement watch exclusion lists
Some checks failed
Docs / docs (push) Has been cancelled
Docs / deploy (push) Has been cancelled

Allow exclusion of directories when watching recursively.
This commit is contained in:
T. R. Bernstein
2026-03-15 22:30:10 +01:00
parent 9cb30f6902
commit a12c20af33
5 changed files with 75 additions and 25 deletions

View File

@@ -21,6 +21,24 @@ struct RecursiveEventTests {
}
}
@Test func ignoresFileCreationInIgnoredSubfolder() async throws {
try await withTempDir { dir in
let subDirectory = "\(dir)/Subfolder"
let filepath = "\(subDirectory)/modify-target.txt"
try FileManager.default.createDirectory(atPath: subDirectory, withIntermediateDirectories: true)
let events = try await getEventsForTrigger(
in: dir,
mask: [.create],
recursive: .recursive,
exclude: ["Subfolder"]
) { _ in try createFile(at: "\(filepath)", contents: "hello") }
let createEvent = events.first { $0.mask.contains(.create) && $0.path.string == filepath }
#expect(createEvent == nil, "Did not expect CREATE for '\(filepath)', got: \(events)")
}
}
@Test func newSubfoldersOfRecursiveWatchAreAutomaticallyWatchedToo() async throws {
try await withTempDir { dir in
let subDirectory = "\(dir)/Subfolder"
@@ -32,7 +50,7 @@ struct RecursiveEventTests {
recursive: .withAutomaticSubtreeWatching
) { _ in
try FileManager.default.createDirectory(atPath: subDirectory, withIntermediateDirectories: true)
try await Task.sleep(for: .milliseconds(200))
try await Task.sleep(for: .milliseconds(400))
try createFile(at: "\(filepath)", contents: "hello")
}