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(); }); 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'); }); }); });