ignore.test.ts 1.0 KB

12345678910111213141516171819202122232425262728293031
  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("parcel patterns ignore built-in folders at any depth", async () => {
  6. let ignoreGlobs: string[] = []
  7. const watcher = createWrapper({
  8. subscribe: async (
  9. _directory: string,
  10. _callback: (...args: unknown[]) => unknown,
  11. options: { ignoreGlobs?: string[] },
  12. ) => {
  13. ignoreGlobs = options.ignoreGlobs ?? []
  14. },
  15. })
  16. await watcher.subscribe("/tmp/project", () => {}, { ignore: Ignore.PATTERNS })
  17. const patterns = ignoreGlobs.map((source) => new RegExp(source))
  18. for (const path of [
  19. "nested/node_modules",
  20. "nested/node_modules/package/index.js",
  21. "nested/.git",
  22. "nested/.git/HEAD",
  23. "nested/dist",
  24. "nested/dist/index.js",
  25. ]) {
  26. expect(patterns.some((pattern) => pattern.test(path))).toBe(true)
  27. }
  28. expect(patterns.some((pattern) => pattern.test("nested/src/index.ts"))).toBe(false)
  29. })