ignore.test.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import { expect, test } from "bun:test"
  2. import { Ignore } from "@opencode-ai/core/filesystem/ignore"
  3. // @ts-ignore
  4. import { createWrapper } from "@parcel/watcher/wrapper"
  5. test("match nested and non-nested", () => {
  6. expect(Ignore.match("node_modules/index.js")).toBe(true)
  7. expect(Ignore.match("node_modules")).toBe(true)
  8. expect(Ignore.match("node_modules/")).toBe(true)
  9. expect(Ignore.match("node_modules/bar")).toBe(true)
  10. expect(Ignore.match("node_modules/bar/")).toBe(true)
  11. })
  12. test("parcel patterns ignore built-in folders at any depth", async () => {
  13. let ignoreGlobs: string[] = []
  14. const watcher = createWrapper({
  15. subscribe: async (
  16. _directory: string,
  17. _callback: (...args: unknown[]) => unknown,
  18. options: { ignoreGlobs?: string[] },
  19. ) => {
  20. ignoreGlobs = options.ignoreGlobs ?? []
  21. },
  22. })
  23. await watcher.subscribe("/tmp/project", () => {}, { ignore: Ignore.PATTERNS })
  24. const patterns = ignoreGlobs.map((source) => new RegExp(source))
  25. for (const path of [
  26. "nested/node_modules",
  27. "nested/node_modules/package/index.js",
  28. "nested/.git",
  29. "nested/.git/HEAD",
  30. "nested/dist",
  31. "nested/dist/index.js",
  32. ]) {
  33. expect(patterns.some((pattern) => pattern.test(path))).toBe(true)
  34. }
  35. expect(patterns.some((pattern) => pattern.test("nested/src/index.ts"))).toBe(false)
  36. })