|
1 | 1 | import { describe, expect, it } from 'vitest' |
2 | | -import { parseRepositoryInfo, type RepositoryInfo } from '#shared/utils/git-providers' |
| 2 | +import { |
| 3 | + normalizeGitUrl, |
| 4 | + parseRepositoryInfo, |
| 5 | + type RepositoryInfo, |
| 6 | +} from '#shared/utils/git-providers' |
| 7 | + |
| 8 | +describe('normalizeGitUrl', () => { |
| 9 | + it('should leave plain HTTPS URLs unchanged', () => { |
| 10 | + expect |
| 11 | + .soft(normalizeGitUrl('https://github.com/user/repo')) |
| 12 | + .toBe('https://github.com/user/repo') |
| 13 | + }) |
| 14 | + |
| 15 | + it('should remove git+ prefix', () => { |
| 16 | + expect |
| 17 | + .soft(normalizeGitUrl('git+https://github.com/user/repo')) |
| 18 | + .toBe('https://github.com/user/repo') |
| 19 | + expect |
| 20 | + .soft(normalizeGitUrl('git+https://github.com/user/repo.git')) |
| 21 | + .toBe('https://github.com/user/repo') |
| 22 | + expect |
| 23 | + .soft(normalizeGitUrl('git+ssh://git@github.com/user/repo.git')) |
| 24 | + .toBe('https://github.com/user/repo') |
| 25 | + }) |
| 26 | + |
| 27 | + it('should remove .git suffix', () => { |
| 28 | + expect |
| 29 | + .soft(normalizeGitUrl('https://github.com/user/repo.git')) |
| 30 | + .toBe('https://github.com/user/repo') |
| 31 | + expect |
| 32 | + .soft(normalizeGitUrl('https://gitlab.com/user/repo.git')) |
| 33 | + .toBe('https://gitlab.com/user/repo') |
| 34 | + expect |
| 35 | + .soft(normalizeGitUrl('https://bitbucket.org/user/repo.git')) |
| 36 | + .toBe('https://bitbucket.org/user/repo') |
| 37 | + }) |
| 38 | + |
| 39 | + it('should convert git:// protocol to https://', () => { |
| 40 | + expect.soft(normalizeGitUrl('git://github.com/user/repo')).toBe('https://github.com/user/repo') |
| 41 | + expect |
| 42 | + .soft(normalizeGitUrl('git://github.com/user/repo.git')) |
| 43 | + .toBe('https://github.com/user/repo') |
| 44 | + }) |
| 45 | + |
| 46 | + it('should convert ssh:// protocol to https://', () => { |
| 47 | + expect |
| 48 | + .soft(normalizeGitUrl('ssh://git@github.com/user/repo')) |
| 49 | + .toBe('https://github.com/user/repo') |
| 50 | + expect |
| 51 | + .soft(normalizeGitUrl('ssh://git@github.com/user/repo.git')) |
| 52 | + .toBe('https://github.com/user/repo') |
| 53 | + }) |
| 54 | + |
| 55 | + it('should convert git@github.com SSH format', () => { |
| 56 | + expect.soft(normalizeGitUrl('git@github.com:user/repo')).toBe('https://github.com/user/repo') |
| 57 | + expect |
| 58 | + .soft(normalizeGitUrl('git@github.com:user/repo.git')) |
| 59 | + .toBe('https://github.com/user/repo') |
| 60 | + expect |
| 61 | + .soft(normalizeGitUrl('git@github.com/user/repo:123')) |
| 62 | + .toBe('https://github.com/user/repo:123') |
| 63 | + }) |
| 64 | + |
| 65 | + it('should handle combined permutations', () => { |
| 66 | + expect |
| 67 | + .soft(normalizeGitUrl('git+git://github.com/user/repo.git')) |
| 68 | + .toBe('https://github.com/user/repo') |
| 69 | + expect |
| 70 | + .soft(normalizeGitUrl('git+ssh://git@gitlab.com/user/repo.git')) |
| 71 | + .toBe('https://gitlab.com/user/repo') |
| 72 | + }) |
| 73 | +}) |
3 | 74 |
|
4 | 75 | describe('parseRepositoryInfo', () => { |
5 | 76 | it('returns undefined for undefined input', () => { |
|
0 commit comments