fsmonitor.test.ts 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import { $ } from "bun"
  2. import { describe, expect, test } from "bun:test"
  3. import fs from "fs/promises"
  4. import path from "path"
  5. import { File } from "../../src/file"
  6. import { Instance } from "../../src/project/instance"
  7. import { tmpdir } from "../fixture/fixture"
  8. const wintest = process.platform === "win32" ? test : test.skip
  9. describe("file fsmonitor", () => {
  10. wintest("status does not start fsmonitor for readonly git checks", async () => {
  11. await using tmp = await tmpdir({ git: true })
  12. const target = path.join(tmp.path, "tracked.txt")
  13. await fs.writeFile(target, "base\n")
  14. await $`git add tracked.txt`.cwd(tmp.path).quiet()
  15. await $`git commit -m init`.cwd(tmp.path).quiet()
  16. await $`git config core.fsmonitor true`.cwd(tmp.path).quiet()
  17. await $`git fsmonitor--daemon stop`.cwd(tmp.path).quiet().nothrow()
  18. await fs.writeFile(target, "next\n")
  19. await fs.writeFile(path.join(tmp.path, "new.txt"), "new\n")
  20. const before = await $`git fsmonitor--daemon status`.cwd(tmp.path).quiet().nothrow()
  21. expect(before.exitCode).not.toBe(0)
  22. await Instance.provide({
  23. directory: tmp.path,
  24. fn: async () => {
  25. await File.status()
  26. },
  27. })
  28. const after = await $`git fsmonitor--daemon status`.cwd(tmp.path).quiet().nothrow()
  29. expect(after.exitCode).not.toBe(0)
  30. })
  31. wintest("read does not start fsmonitor for git diffs", async () => {
  32. await using tmp = await tmpdir({ git: true })
  33. const target = path.join(tmp.path, "tracked.txt")
  34. await fs.writeFile(target, "base\n")
  35. await $`git add tracked.txt`.cwd(tmp.path).quiet()
  36. await $`git commit -m init`.cwd(tmp.path).quiet()
  37. await $`git config core.fsmonitor true`.cwd(tmp.path).quiet()
  38. await $`git fsmonitor--daemon stop`.cwd(tmp.path).quiet().nothrow()
  39. await fs.writeFile(target, "next\n")
  40. const before = await $`git fsmonitor--daemon status`.cwd(tmp.path).quiet().nothrow()
  41. expect(before.exitCode).not.toBe(0)
  42. await Instance.provide({
  43. directory: tmp.path,
  44. fn: async () => {
  45. await File.read("tracked.txt")
  46. },
  47. })
  48. const after = await $`git fsmonitor--daemon status`.cwd(tmp.path).quiet().nothrow()
  49. expect(after.exitCode).not.toBe(0)
  50. })
  51. })