Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2โ
3import { sanitizeCommitSubject } from "./textGenerationUtils.ts";
4โ
5describe("sanitizeCommitSubject", () => {
6 it.each([
7 { name: "an emoji", prefixLength: 71, character: "๐" },
8 { name: "an accented character", prefixLength: 71, character: "e\u0301" },
9 { name: "an emoji with a skin tone", prefixLength: 70, character: "๐๐ฝ" },
10 { name: "a flag", prefixLength: 69, character: "๐ฎ๐น" },
11 { name: "a joined emoji", prefixLength: 65, character: "๐จโ๐ฉโ๐งโ๐ฆ" },
12 ])("keeps $name intact at the subject limit", ({ prefixLength, character }) => {
13 const prefix = "a".repeat(prefixLength);
14โ
15 expect(sanitizeCommitSubject(`${prefix}${character} more`)).toBe(prefix);
16 });
17โ
18 it("keeps a complete character that ends exactly at the limit", () => {
19 const expected = `${"a".repeat(70)}๐`;
20โ
21 expect(sanitizeCommitSubject(`${expected} more`)).toBe(expected);
22 });
23โ
24 it("uses the existing fallback when a single character exceeds the limit", () => {
25 expect(sanitizeCommitSubject(`a${"\u0301".repeat(72)} more`)).toBe("Update project files");
26 });
27โ
28 it("keeps the existing ASCII limit and subject normalization", () => {
29 expect(sanitizeCommitSubject("a".repeat(80))).toBe("a".repeat(72));
30 expect(sanitizeCommitSubject(" Fix tests...\nignored ")).toBe("Fix tests");
31 expect(sanitizeCommitSubject("...")).toBe("Update project files");
32 });
33});