|
| 1 | +import { describe, expect, it } from 'vitest' |
| 2 | + |
| 3 | +import { normalizeScmUrl } from '../extract' |
| 4 | +import { isPrerelease, parseRepoUrl } from '../normalize' |
| 5 | + |
| 6 | +describe('isPrerelease', () => { |
| 7 | + it('returns false for a stable version', () => { |
| 8 | + expect(isPrerelease('3.12.0')).toBe(false) |
| 9 | + }) |
| 10 | + |
| 11 | + it('detects SNAPSHOT', () => { |
| 12 | + expect(isPrerelease('1.0.0-SNAPSHOT')).toBe(true) |
| 13 | + }) |
| 14 | + |
| 15 | + it('detects alpha', () => { |
| 16 | + expect(isPrerelease('2.0.0-alpha')).toBe(true) |
| 17 | + expect(isPrerelease('2.0.0-ALPHA.1')).toBe(true) |
| 18 | + }) |
| 19 | + |
| 20 | + it('detects beta', () => { |
| 21 | + expect(isPrerelease('1.5.0-beta.2')).toBe(true) |
| 22 | + }) |
| 23 | + |
| 24 | + it('detects rc', () => { |
| 25 | + expect(isPrerelease('4.0.0-rc1')).toBe(true) |
| 26 | + expect(isPrerelease('4.0.0-RC.2')).toBe(true) |
| 27 | + }) |
| 28 | + |
| 29 | + it('detects milestone (m1, m10)', () => { |
| 30 | + expect(isPrerelease('5.3.0-m1')).toBe(true) |
| 31 | + expect(isPrerelease('5.3.0-M10')).toBe(true) |
| 32 | + }) |
| 33 | + |
| 34 | + it('returns false for versions with numbers that are not milestones', () => { |
| 35 | + expect(isPrerelease('1.2.3')).toBe(false) |
| 36 | + expect(isPrerelease('10.0.0')).toBe(false) |
| 37 | + }) |
| 38 | +}) |
| 39 | + |
| 40 | +describe('parseRepoUrl', () => { |
| 41 | + it('identifies github.com', () => { |
| 42 | + expect(parseRepoUrl('https://github.com/apache/commons-lang')).toEqual({ |
| 43 | + host: 'github', |
| 44 | + owner: 'apache', |
| 45 | + name: 'commons-lang', |
| 46 | + }) |
| 47 | + }) |
| 48 | + |
| 49 | + it('identifies gitlab.com', () => { |
| 50 | + expect(parseRepoUrl('https://gitlab.com/owner/repo')).toEqual({ |
| 51 | + host: 'gitlab', |
| 52 | + owner: 'owner', |
| 53 | + name: 'repo', |
| 54 | + }) |
| 55 | + }) |
| 56 | + |
| 57 | + it('identifies bitbucket.org', () => { |
| 58 | + expect(parseRepoUrl('https://bitbucket.org/owner/repo')).toEqual({ |
| 59 | + host: 'bitbucket', |
| 60 | + owner: 'owner', |
| 61 | + name: 'repo', |
| 62 | + }) |
| 63 | + }) |
| 64 | + |
| 65 | + it('returns other for unknown hosts', () => { |
| 66 | + const result = parseRepoUrl('https://svn.example.com/repo') |
| 67 | + expect(result?.host).toBe('other') |
| 68 | + }) |
| 69 | + |
| 70 | + it('returns null for invalid URLs', () => { |
| 71 | + expect(parseRepoUrl('not-a-url')).toBeNull() |
| 72 | + }) |
| 73 | + |
| 74 | + it('handles URLs with no path segments', () => { |
| 75 | + const result = parseRepoUrl('https://github.com/') |
| 76 | + expect(result).toEqual({ host: 'github', owner: null, name: null }) |
| 77 | + }) |
| 78 | +}) |
| 79 | + |
| 80 | +describe('normalizeScmUrl', () => { |
| 81 | + it('returns null for null input', () => { |
| 82 | + expect(normalizeScmUrl(null)).toBeNull() |
| 83 | + }) |
| 84 | + |
| 85 | + it('strips scm:git: prefix', () => { |
| 86 | + expect(normalizeScmUrl('scm:git:https://github.com/apache/commons-lang')).toBe( |
| 87 | + 'https://github.com/apache/commons-lang', |
| 88 | + ) |
| 89 | + }) |
| 90 | + |
| 91 | + it('converts SSH git@ to https', () => { |
| 92 | + expect(normalizeScmUrl('git@github.com:apache/commons-lang.git')).toBe( |
| 93 | + 'https://github.com/apache/commons-lang', |
| 94 | + ) |
| 95 | + }) |
| 96 | + |
| 97 | + it('converts git:// to https://', () => { |
| 98 | + expect(normalizeScmUrl('git://github.com/apache/commons-lang.git')).toBe( |
| 99 | + 'https://github.com/apache/commons-lang', |
| 100 | + ) |
| 101 | + }) |
| 102 | + |
| 103 | + it('strips trailing .git', () => { |
| 104 | + expect(normalizeScmUrl('https://github.com/apache/commons-lang.git')).toBe( |
| 105 | + 'https://github.com/apache/commons-lang', |
| 106 | + ) |
| 107 | + }) |
| 108 | + |
| 109 | + it('strips /tree/... path suffix', () => { |
| 110 | + expect(normalizeScmUrl('https://github.com/apache/commons-lang/tree/master')).toBe( |
| 111 | + 'https://github.com/apache/commons-lang', |
| 112 | + ) |
| 113 | + }) |
| 114 | + |
| 115 | + it('strips trailing slash', () => { |
| 116 | + expect(normalizeScmUrl('https://github.com/apache/commons-lang/')).toBe( |
| 117 | + 'https://github.com/apache/commons-lang', |
| 118 | + ) |
| 119 | + }) |
| 120 | + |
| 121 | + it('handles combined scm:git: + SSH form', () => { |
| 122 | + expect(normalizeScmUrl('scm:git:git@github.com:apache/commons-lang.git')).toBe( |
| 123 | + 'https://github.com/apache/commons-lang', |
| 124 | + ) |
| 125 | + }) |
| 126 | + |
| 127 | + it('returns null for non-https result', () => { |
| 128 | + expect(normalizeScmUrl('svn://svn.apache.org/repos/commons-lang')).toBeNull() |
| 129 | + }) |
| 130 | +}) |
0 commit comments