| 1 | import { describe, expect, it } from "vite-plus/test"; |
| 2 | |
| 3 | import { parseCommitTitle } from "./commitTitle"; |
| 4 | |
| 5 | describe("parseCommitTitle", () => { |
| 6 | it("finds issue keys, the conventional prefix, and its scope", () => { |
| 7 | const title = "[ENG-311, ENG-312] fix(api)!: retry flaky uploads"; |
| 8 | const parsed = parseCommitTitle(title); |
| 9 | expect(parsed.issues).toEqual(["ENG-311", "ENG-312"]); |
| 10 | expect(parsed.prefix?.tone).toBe("fix"); |
| 11 | expect(title.slice(parsed.prefix!.from, parsed.prefix!.to)).toBe("fix(api)!:"); |
| 12 | expect(title.slice(parsed.scope!.from, parsed.scope!.to)).toBe("(api)"); |
| 13 | expect(title.slice(parsed.restFrom)).toBe(" retry flaky uploads"); |
| 14 | }); |
| 15 | |
| 16 | it("uses Mergebot's tones: features green, fixes red, anything else blue", () => { |
| 17 | expect(parseCommitTitle("infra: cache browsers").prefix?.tone).toBe("add"); |
| 18 | expect(parseCommitTitle("hotpatch: revert").prefix?.tone).toBe("fix"); |
| 19 | expect(parseCommitTitle("chore: follow-up changes").prefix?.tone).toBe("other"); |
| 20 | }); |
| 21 | |
| 22 | it("marks WIP without a scope highlight and leaves plain titles alone", () => { |
| 23 | expect(parseCommitTitle("WIP(ui): try layouts").prefix?.tone).toBe("wip"); |
| 24 | expect(parseCommitTitle("WIP(ui): try layouts").scope).toBeNull(); |
| 25 | expect(parseCommitTitle("Fix the build").prefix).toBeNull(); |
| 26 | }); |
| 27 | }); |