-
Notifications
You must be signed in to change notification settings - Fork 339
/
Copy pathgetRepoUrl.test.ts
54 lines (52 loc) · 2.73 KB
/
getRepoUrl.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import getRepoUrl from '../src/lib/getRepoUrl'
import chaiSetup from './helpers/chaiSetup'
const should = chaiSetup()
describe('getRepoUrl', () => {
it('return null if package is not installed', async () => {
should.equal(await getRepoUrl('not-installed/package'), null)
})
it('return null repository field is undefined', async () => {
should.equal(await getRepoUrl('package-name', {}), null)
})
it('return null repository field is unknown type', async () => {
should.equal(await getRepoUrl('package-name', { repository: true as any /* allow to compile */ }), null)
})
it('return url directly from repository field if valid https url', async () => {
const url = await getRepoUrl('package-name', { repository: 'https://github.com/user/repo' })
url!.should.equal('https://github.com/user/repo')
})
it('return url directly from repository field if valid http url', async () => {
const url = await getRepoUrl('package-name', { repository: 'http://anything.com/user/repo' })
url!.should.equal('http://anything.com/user/repo')
})
it('return url constructed from github shortcut syntax string', async () => {
const url = await getRepoUrl('package-name', { repository: 'user/repo' })
url!.should.equal('https://github.com/user/repo')
})
it('return url constructed from repository specific shortcut syntax string', async () => {
const url = await getRepoUrl('package-name', { repository: 'github:user/repo' })
url!.should.equal('https://github.com/user/repo')
})
it('return url directly from url field if not a known git host', async () => {
const url = await getRepoUrl('package-name', { repository: { url: 'https://any.website.com/some/path' } })
url!.should.equal('https://any.website.com/some/path')
})
it('return url constructed from git-https protocol', async () => {
const url = await getRepoUrl('package-name', { repository: { url: 'git+https://github.com/user/repo.git' } })
url!.should.equal('https://github.com/user/repo')
})
it('return url constructed from git protocol', async () => {
const url = await getRepoUrl('package-name', { repository: { url: 'git://github.com/user/repo.git' } })
url!.should.equal('https://github.com/user/repo')
})
it('return url constructed from http protocol', async () => {
const url = await getRepoUrl('package-name', { repository: { url: 'http://github.com/user/repo.git' } })
url!.should.equal('https://github.com/user/repo')
})
it('return url with directory path', async () => {
const url = await getRepoUrl('package-name', {
repository: { url: 'http://github.com/user/repo.git', directory: 'packages/specific-package' },
})
url!.should.equal('https://github.com/user/repo/tree/HEAD/packages/specific-package')
})
})