Skip to content

Commit e79a323

Browse files
committed
test(@modulify/conventional-git): URL's of remotes, edge cases
1 parent 3976dc3 commit e79a323

2 files changed

Lines changed: 79 additions & 0 deletions

File tree

packages/conventional-git/tests/Client.test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,4 +268,31 @@ describe('Client', () => {
268268
expect(await client.version({ prefix: 'pkg@' })).toBe('1.1.0')
269269
})
270270
})
271+
272+
describe('url', () => {
273+
it('should return remote url', async () => {
274+
exec('git remote add origin https://github.com/fork/conventional.git')
275+
exec('git remote add upstream https://github.com/modulify/conventional.git')
276+
277+
const client = new Client({ cwd })
278+
279+
expect(await client.url()).toBe('https://github.com/fork/conventional.git')
280+
expect(await client.url('upstream')).toBe('https://github.com/modulify/conventional.git')
281+
})
282+
283+
it('should return empty string if remote does not exist', async () => {
284+
const client = new Client({ cwd })
285+
286+
expect(await client.url('non-existent')).toBe('')
287+
})
288+
289+
it('should throw other errors', async () => {
290+
const client = new Client({ cwd })
291+
292+
// @ts-expect-error accessing private for test
293+
vi.spyOn(client._git.cmd, 'exec').mockRejectedValue(new Error('Unexpected error'))
294+
295+
await expect(client.url()).rejects.toThrow('Unexpected error')
296+
})
297+
})
271298
})

packages/conventional-git/tests/parse.test.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,5 +295,57 @@ describe('parse', () => {
295295
expect(commit.hash).toBe('1234567')
296296
expect(commit.type).toBe('feat')
297297
})
298+
299+
it('should handle notes followed by other notes', () => {
300+
const commit = parse('feat: subject\n\nBREAKING CHANGE: note 1\nBREAKING CHANGE: note 2')
301+
302+
expect(commit.notes).toHaveLength(2)
303+
expect(commit.notes[0].text).toBe('note 1')
304+
expect(commit.notes[1].text).toBe('note 2')
305+
})
306+
307+
it('should handle notes followed by references', () => {
308+
const commit = parse('feat: subject\n\nBREAKING CHANGE: note 1\nCloses #123')
309+
expect(commit.notes[0].text).toBe('note 1')
310+
expect(commit.references[0].issue).toBe('123')
311+
})
312+
313+
it('should handle merge commits with correspondence that are not manageable', () => {
314+
const parse = createParser({
315+
mergePattern: /^Merge branch '([\w-]+)'/,
316+
mergeCorrespondence: ['nonManageable'],
317+
})
318+
319+
const commit = parse('Merge branch \'feature\'\nheader')
320+
321+
expect(commit.meta.nonManageable).toBe('feature')
322+
})
323+
324+
it('should handle parseReference returning null for malformed reference', () => {
325+
const parse = createParser({
326+
issuePrefixes: ['#'],
327+
})
328+
329+
const commit = parse('fix: something with # but no number #abc')
330+
331+
expect(commit.references).toEqual([])
332+
})
333+
334+
it('should handle parseRevert with missing correspondence fields', () => {
335+
const parse = createParser({
336+
revertPattern: /^Revert (.*)/,
337+
revertCorrespondence: ['customField'],
338+
})
339+
340+
const commit = parse('Revert some subject')
341+
342+
expect(commit.revert?.customField).toBe('some subject')
343+
})
344+
345+
it('should handle trimLineBreaks for only line breaks', () => {
346+
const commit = parse('\n\n')
347+
348+
expect(commit.header).toBe(null)
349+
})
298350
})
299351
})

0 commit comments

Comments
 (0)