Files
Michael Kriese 52a0e53537 feat: use custom conventional commits detector (#42328)
* feat: use custom conventional commits detector

* fix: update names and add test
2026-04-02 15:26:05 +00:00

64 lines
2.0 KiB
TypeScript

import type { RenovateConfig } from '~test/util.ts';
import { git, partial } from '~test/util.ts';
import { initRepoCache } from '../cache/repository/init.ts';
import { detectSemanticCommits } from './semantic.ts';
let config: RenovateConfig;
beforeEach(() => {
config = partial<RenovateConfig>();
});
describe('util/git/semantic', () => {
describe('detectSemanticCommits()', () => {
beforeEach(async () => {
await initRepoCache({ repoFingerprint: '0123456789abcdef' });
});
it('detects false if unknown', async () => {
config.semanticCommits = undefined;
git.getCommitMessages.mockResolvedValueOnce(['foo', 'bar']);
git.getCommitMessages.mockResolvedValueOnce([
'fix: foo',
'refactor: bar',
]);
const res = await detectSemanticCommits();
expect(res).toBe('disabled');
const res2 = await detectSemanticCommits();
expect(res2).toBe('disabled');
});
it('detects true if known', async () => {
config.semanticCommits = undefined;
git.getCommitMessages.mockResolvedValue(['fix: foo', 'refactor: bar']);
const res = await detectSemanticCommits();
expect(res).toBe('enabled');
});
it('detects false on malformed commits', async () => {
config.semanticCommits = undefined;
git.getCommitMessages.mockResolvedValue([
'fix(): foo',
'fix:',
'some:invalid',
]);
const res = await detectSemanticCommits();
expect(res).toBe('disabled');
});
it('detects true on breaking changes', async () => {
config.semanticCommits = undefined;
git.getCommitMessages.mockResolvedValue(['fix!: foo']);
const res = await detectSemanticCommits();
expect(res).toBe('enabled');
});
it('detects true on breaking changes with scope', async () => {
config.semanticCommits = undefined;
git.getCommitMessages.mockResolvedValue(['fix(scope)!: foo']);
const res = await detectSemanticCommits();
expect(res).toBe('enabled');
});
});
});