1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
#!/usr/bin/env node
'use strict'
process.env.COMMIT_TYPES = 'customtype'
const assert = require('node:assert/strict')
const commits = require('../commits.js')
const { validateCommitMessage, normalizeCommitType } = commits
const validMessages = [
'feat(ui): add redesigned settings panel',
'refactor: drop deprecated launcher flag support',
'chore(ci): refresh workflows configuration',
'11.feat: support legacy numbered commit type format',
'23.deps(deps): bump dependency pins',
'release: publish stable build artifacts',
'customtype: allow env commit type overrides',
]
for (const message of validMessages) {
const result = validateCommitMessage(message)
assert.equal(
result.valid,
true,
`Expected commit "${message}" to be valid, got: ${result.message}`
)
}
const invalidType = validateCommitMessage('unknown(scope): add feature that is real enough')
assert.equal(invalidType.valid, false, 'Expected invalid type to be rejected')
assert.match(invalidType.message, /Unknown commit type/i)
const shortDescription = validateCommitMessage('feat: short')
assert.equal(shortDescription.valid, false, 'Expected short description to fail validation')
assert.match(shortDescription.message, /too short/i)
assert.equal(normalizeCommitType('11.feat'), 'feat')
assert.equal(normalizeCommitType('23.deps'), 'deps')
assert.equal(normalizeCommitType('chore'), 'chore')
console.log('commits.js tests passed')
|