@markjaquith/agency 3.2.6 → 3.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/check-commits.test.ts +58 -0
package/package.json
CHANGED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, test } from "bun:test"
|
|
2
|
+
import { writeFileSync } from "node:fs"
|
|
3
|
+
import { join } from "node:path"
|
|
4
|
+
import { cleanupTempDir, createTempDir } from "./test-utils"
|
|
5
|
+
|
|
6
|
+
const checkCommits = join(import.meta.dir, "../scripts/check-commits")
|
|
7
|
+
|
|
8
|
+
describe("check-commits", () => {
|
|
9
|
+
let root: string
|
|
10
|
+
|
|
11
|
+
function git(...args: string[]): void {
|
|
12
|
+
const result = Bun.spawnSync(["git", ...args], { cwd: root })
|
|
13
|
+
if (result.exitCode !== 0) {
|
|
14
|
+
throw new Error(new TextDecoder().decode(result.stderr))
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function commit(subject: string, file: string): void {
|
|
19
|
+
writeFileSync(join(root, file), `${subject}\n`)
|
|
20
|
+
git("add", file)
|
|
21
|
+
git("commit", "-m", subject)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
beforeEach(async () => {
|
|
25
|
+
root = await createTempDir()
|
|
26
|
+
git("init", "--initial-branch=main")
|
|
27
|
+
git("config", "user.email", "agency@example.com")
|
|
28
|
+
git("config", "user.name", "Agency Test")
|
|
29
|
+
commit("chore: initial commit", "initial.txt")
|
|
30
|
+
git("update-ref", "refs/remotes/origin/main", "HEAD")
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
afterEach(async () => cleanupTempDir(root))
|
|
34
|
+
|
|
35
|
+
test("allows merge commits with non-conventional subjects", () => {
|
|
36
|
+
git("checkout", "-b", "feature")
|
|
37
|
+
commit("feat: add feature", "feature.txt")
|
|
38
|
+
git("checkout", "-b", "topic", "main")
|
|
39
|
+
commit("fix: add topic", "topic.txt")
|
|
40
|
+
git("checkout", "feature")
|
|
41
|
+
git("merge", "--no-ff", "topic", "-m", "Combine topic into feature")
|
|
42
|
+
|
|
43
|
+
const result = Bun.spawnSync([checkCommits], { cwd: root })
|
|
44
|
+
|
|
45
|
+
expect(result.exitCode).toBe(0)
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
test("rejects non-conventional non-merge commits", () => {
|
|
49
|
+
commit("not a conventional commit", "invalid.txt")
|
|
50
|
+
|
|
51
|
+
const result = Bun.spawnSync([checkCommits], { cwd: root })
|
|
52
|
+
|
|
53
|
+
expect(result.exitCode).toBe(1)
|
|
54
|
+
expect(new TextDecoder().decode(result.stderr)).toContain(
|
|
55
|
+
"not a conventional commit",
|
|
56
|
+
)
|
|
57
|
+
})
|
|
58
|
+
})
|