apply-patch-file.test.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { describe, expect, test } from "bun:test"
  2. import { patchFiles } from "./apply-patch-file"
  3. import { text } from "./session-diff"
  4. describe("apply patch file", () => {
  5. test("parses patch metadata from the server", () => {
  6. const file = patchFiles([
  7. {
  8. filePath: "/tmp/a.ts",
  9. relativePath: "a.ts",
  10. type: "update",
  11. patch:
  12. "Index: a.ts\n===================================================================\n--- a.ts\t\n+++ a.ts\t\n@@ -1,2 +1,2 @@\n one\n-two\n+three\n",
  13. additions: 1,
  14. deletions: 1,
  15. },
  16. ])[0]
  17. expect(file).toBeDefined()
  18. expect(file?.view.fileDiff.name).toBe("a.ts")
  19. expect(file?.view.fileDiff.isPartial).toBe(false)
  20. expect(text(file!.view, "deletions")).toBe("one\ntwo\n")
  21. expect(text(file!.view, "additions")).toBe("one\nthree\n")
  22. })
  23. test("keeps legacy before and after payloads working", () => {
  24. const file = patchFiles([
  25. {
  26. filePath: "/tmp/a.ts",
  27. relativePath: "a.ts",
  28. type: "update",
  29. before: "one\n",
  30. after: "two\n",
  31. additions: 1,
  32. deletions: 1,
  33. },
  34. ])[0]
  35. expect(file).toBeDefined()
  36. expect(text(file!.view, "deletions")).toBe("one\n")
  37. expect(text(file!.view, "additions")).toBe("two\n")
  38. })
  39. })