ripgrep.test.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import { describe, expect, test } from "bun:test"
  2. import fs from "fs/promises"
  3. import path from "path"
  4. import { tmpdir } from "../fixture/fixture"
  5. import { Ripgrep } from "../../src/file/ripgrep"
  6. describe("file.ripgrep", () => {
  7. test("defaults to include hidden", async () => {
  8. await using tmp = await tmpdir({
  9. init: async (dir) => {
  10. await Bun.write(path.join(dir, "visible.txt"), "hello")
  11. await fs.mkdir(path.join(dir, ".opencode"), { recursive: true })
  12. await Bun.write(path.join(dir, ".opencode", "thing.json"), "{}")
  13. },
  14. })
  15. const files = await Array.fromAsync(Ripgrep.files({ cwd: tmp.path }))
  16. const hasVisible = files.includes("visible.txt")
  17. const hasHidden = files.includes(path.join(".opencode", "thing.json"))
  18. expect(hasVisible).toBe(true)
  19. expect(hasHidden).toBe(true)
  20. })
  21. test("hidden false excludes hidden", async () => {
  22. await using tmp = await tmpdir({
  23. init: async (dir) => {
  24. await Bun.write(path.join(dir, "visible.txt"), "hello")
  25. await fs.mkdir(path.join(dir, ".opencode"), { recursive: true })
  26. await Bun.write(path.join(dir, ".opencode", "thing.json"), "{}")
  27. },
  28. })
  29. const files = await Array.fromAsync(Ripgrep.files({ cwd: tmp.path, hidden: false }))
  30. const hasVisible = files.includes("visible.txt")
  31. const hasHidden = files.includes(path.join(".opencode", "thing.json"))
  32. expect(hasVisible).toBe(true)
  33. expect(hasHidden).toBe(false)
  34. })
  35. })