Skip to content

Commit 888f9b4

Browse files
author
Michael Perrotte
committedSep 27, 2019
test: added default fixtures and github specific fixtures
1 parent 3d1ad71 commit 888f9b4

File tree

6 files changed

+807
-82
lines changed

6 files changed

+807
-82
lines changed
 

‎test/fixtures/github.js

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
'use strict'
2+
3+
module.exports = [
4+
// Github Shorturls
5+
{
6+
host: function (p) { return p.owner + '/' + p.project },
7+
label: 'github-short'
8+
},
9+
{
10+
host: function (p) { return p.owner + '/' + p.project + '#' + p.branch },
11+
label: 'github-short#branch',
12+
hasBranch: true
13+
},
14+
{
15+
host: function (p) { return p.owner + '/' + p.project + '#' + p.branch },
16+
label: 'github-short#branch',
17+
hasBranch: true
18+
},
19+
// Insecure Protocols
20+
{
21+
host: function (p) { return 'git://' + p.domain + '/' + p.owner + '/' + p.project },
22+
label: 'git'
23+
},
24+
{
25+
host: function (p) { return 'git://' + p.domain + '/' + p.owner + '/' + p.project + '.git' },
26+
label: 'git.git'
27+
},
28+
{
29+
host: function (p) { return 'git://' + p.domain + '/' + p.owner + '/' + p.project + '#' + p.branch },
30+
label: 'git#branch',
31+
hasBranch: true
32+
},
33+
{
34+
host: function (p) { return 'git://' + p.domain + '/' + p.owner + '/' + p.project + '.git#' + p.branch },
35+
label: 'git.git#branch',
36+
hasBranch: true
37+
}
38+
]

‎test/fixtures/gitlab-subgroups.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
'use strict'
2+
3+
module.exports = [
4+
{
5+
host: function (p) { return p.shortname + ':' + p.owner + '/' + p.group + '/' + p.project },
6+
label: 'shortname'
7+
},
8+
{
9+
host: function (p) { return p.shortname + ':' + p.owner + '/' + p.group + '/' + p.project },
10+
label: 'shortname.git'
11+
},
12+
{
13+
host: function (p) { return p.shortname + ':' + p.owner + '/' + p.group + '/' + p.project + '#' + p.branch },
14+
label: 'shortname#branch',
15+
hasBranch: true
16+
},
17+
{
18+
host: function (p) { return p.shortname + ':' + p.owner + '/' + p.group + '/' + p.project + '#' + p.branch },
19+
label: 'shortname.git#branch',
20+
hasBranch: true
21+
}
22+
]

‎test/fixtures/gitlab.js

+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
'use strcit'
2+
3+
module.exports = [
4+
{
5+
host: function (p) { return 'https://' + p.domain + '/' + p.owner + '/' + p.project },
6+
label: 'https'
7+
},
8+
{
9+
host: function (p) { return 'https://' + p.domain + '/' + p.owner + '/' + p.project + '.git' },
10+
label: 'https.git'
11+
},
12+
{
13+
host: function (p) { return 'https://' + p.domain + '/' + p.owner + '/' + p.project + '#' + p.branch },
14+
label: 'https#branch',
15+
hasBranch: true
16+
},
17+
{
18+
host: function (p) { return 'https://' + p.domain + '/' + p.owner + '/' + p.project + '.git#' + p.branch },
19+
label: 'https.git#branch',
20+
hasBranch: true
21+
},
22+
{
23+
host: function (p) { return 'https://' + p.domain + '/' + p.owner + '/' + p.project + '/-/' + 'archive' + '/3.3.2' + '/ws-3.3.2.tar.gz' },
24+
label: 'https.tar',
25+
isUndefined: true
26+
},
27+
{
28+
host: function (p) { return 'git+https://' + p.domain + '/' + p.owner + '/' + p.project },
29+
label: 'git+https'
30+
},
31+
{
32+
host: function (p) { return 'git+https://' + p.domain + '/' + p.owner + '/' + p.project + '.git' },
33+
label: 'git+https.git'
34+
},
35+
{
36+
host: function (p) { return 'git+https://' + p.domain + '/' + p.owner + '/' + p.project + '#' + p.branch },
37+
label: 'git+https#branch',
38+
hasBranch: true
39+
},
40+
{
41+
host: function (p) { return 'git+https://' + p.domain + '/' + p.owner + '/' + p.project + '.git#' + p.branch },
42+
label: 'git+https.git#branch',
43+
hasBranch: true
44+
},
45+
{
46+
host: function (p) { return 'git@' + p.domain + ':' + p.owner + '/' + p.project },
47+
label: 'ssh'
48+
},
49+
{
50+
host: function (p) { return 'git@' + p.domain + ':' + p.owner + '/' + p.project + '.git' },
51+
label: 'ssh.git'
52+
},
53+
{
54+
host: function (p) { return 'git@' + p.domain + ':' + p.owner + '/' + p.project + '#' + p.branch },
55+
label: 'ssh#branch',
56+
hasBranch: true
57+
},
58+
{
59+
host: function (p) { return 'git@' + p.domain + ':' + p.owner + '/' + p.project + '.git#' + p.branch },
60+
label: 'ssh.git#branch',
61+
hasBranch: true
62+
},
63+
{
64+
host: function (p) { return 'git+ssh://git@' + p.domain + '/' + p.owner + '/' + p.project },
65+
label: 'ssh-url'
66+
},
67+
{
68+
host: function (p) { return 'git+ssh://git@' + p.domain + '/' + p.owner + '/' + p.project + '.git' },
69+
label: 'ssh-url.git'
70+
},
71+
{
72+
host: function (p) { return 'git+ssh://git@' + p.domain + '/' + p.owner + '/' + p.project + '#' + p.branch },
73+
label: 'ssh-url#branch',
74+
hasBranch: true
75+
},
76+
{
77+
host: function (p) { return 'git+ssh://git@' + p.domain + '/' + p.owner + '/' + p.project + '.git#' + p.branch },
78+
label: 'ssh-url.git#branch',
79+
hasBranch: true
80+
},
81+
{
82+
host: function (p) { return p.shortname + ':' + p.owner + '/' + p.project },
83+
label: 'shortcut'
84+
},
85+
{
86+
host: function (p) { return p.shortname + ':' + p.owner + '/' + p.project + '.git' },
87+
label: 'shortcut.git'
88+
},
89+
{
90+
host: function (p) { return p.shortname + ':' + p.owner + '/' + p.project + '#' + p.branch },
91+
label: 'shortcut#branch',
92+
hasBranch: true
93+
},
94+
{
95+
host: function (p) { return p.shortname + ':' + p.owner + '/' + p.project + '.git#' + p.branch },
96+
label: 'shortcut.git#branch',
97+
hasBranch: true
98+
}
99+
]

‎test/fixtures/index.js

+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
'use strcit'
2+
3+
module.exports = [
4+
{
5+
host: function (p) { return 'https://' + p.domain + '/' + p.owner + '/' + p.project },
6+
label: 'https'
7+
},
8+
{
9+
host: function (p) { return 'https://' + p.domain + '/' + p.owner + '/' + p.project + '.git' },
10+
label: 'https.git'
11+
},
12+
{
13+
host: function (p) { return 'https://' + p.domain + '/' + p.owner + '/' + p.project + '#' + p.branch },
14+
label: 'https#branch',
15+
hasBranch: true
16+
},
17+
{
18+
host: function (p) { return 'https://' + p.domain + '/' + p.owner + '/' + p.project + '.git#' + p.branch },
19+
label: 'https.git#branch',
20+
hasBranch: true
21+
},
22+
{
23+
host: function (p) { return 'https://' + p.domain + '/' + p.owner + '/' + p.project + '/-/' + 'archive' + '/3.3.2' + '/ws-3.3.2.tar.gz' },
24+
label: 'https.tar',
25+
isUndefined: true
26+
},
27+
{
28+
host: function (p) { return 'git+https://' + p.domain + '/' + p.owner + '/' + p.project },
29+
label: 'git+https'
30+
},
31+
{
32+
host: function (p) { return 'git+https://' + p.domain + '/' + p.owner + '/' + p.project + '.git' },
33+
label: 'git+https.git'
34+
},
35+
{
36+
host: function (p) { return 'git+https://' + p.domain + '/' + p.owner + '/' + p.project + '#' + p.branch },
37+
label: 'git+https#branch',
38+
hasBranch: true
39+
},
40+
{
41+
host: function (p) { return 'git+https://' + p.domain + '/' + p.owner + '/' + p.project + '.git#' + p.branch },
42+
label: 'git+https.git#branch',
43+
hasBranch: true
44+
},
45+
{
46+
host: function (p) { return 'git@' + p.domain + ':' + p.owner + '/' + p.project },
47+
label: 'ssh'
48+
},
49+
{
50+
host: function (p) { return 'git@' + p.domain + ':' + p.owner + '/' + p.project + '.git' },
51+
label: 'ssh.git'
52+
},
53+
{
54+
host: function (p) { return 'git@' + p.domain + ':' + p.owner + '/' + p.project + '#' + p.branch },
55+
label: 'ssh#branch',
56+
hasBranch: true
57+
},
58+
{
59+
host: function (p) { return 'git@' + p.domain + ':' + p.owner + '/' + p.project + '.git#' + p.branch },
60+
label: 'ssh.git#branch',
61+
hasBranch: true
62+
},
63+
{
64+
host: function (p) { return 'git+ssh://git@' + p.domain + '/' + p.owner + '/' + p.project },
65+
label: 'ssh-url'
66+
},
67+
{
68+
host: function (p) { return 'git+ssh://git@' + p.domain + '/' + p.owner + '/' + p.project + '.git' },
69+
label: 'ssh-url.git'
70+
},
71+
{
72+
host: function (p) { return 'git+ssh://git@' + p.domain + '/' + p.owner + '/' + p.project + '#' + p.branch },
73+
label: 'ssh-url#branch',
74+
hasBranch: true
75+
},
76+
{
77+
host: function (p) { return 'git+ssh://git@' + p.domain + '/' + p.owner + '/' + p.project + '.git#' + p.branch },
78+
label: 'ssh-url.git#branch',
79+
hasBranch: true
80+
},
81+
{
82+
host: function (p) { return p.shortname + ':' + p.owner + '/' + p.project },
83+
label: 'shortcut'
84+
},
85+
{
86+
host: function (p) { return p.shortname + ':' + p.owner + '/' + p.project + '.git' },
87+
label: 'shortcut.git'
88+
},
89+
{
90+
host: function (p) { return p.shortname + ':' + p.owner + '/' + p.project + '#' + p.branch },
91+
label: 'shortcut#branch',
92+
hasBranch: true
93+
},
94+
{
95+
host: function (p) { return p.shortname + ':' + p.owner + '/' + p.project + '.git#' + p.branch },
96+
label: 'shortcut.git#branch',
97+
hasBranch: true
98+
}
99+
]

‎test/github.js

+281-44
Original file line numberDiff line numberDiff line change
@@ -2,56 +2,293 @@
22
var HostedGit = require('../index')
33
var test = require('tap').test
44

5-
test('fromUrl(github url)', function (t) {
6-
function verify (host, label, branch) {
5+
var showLabel = function (label, fn) { return label + ' -> ' + fn }
6+
7+
var testFixtures = function (t, params, fixtures) {
8+
for (var i = 0; i < fixtures.length; ++i) {
9+
var fixture = fixtures[i]
10+
var host = fixture.host(params)
711
var hostinfo = HostedGit.fromUrl(host)
8-
var hash = branch ? '#' + branch : ''
9-
var treebranch = branch ? '/tree/' + branch : ''
10-
t.equal(hostinfo._fill(), undefined)
11-
t.ok(hostinfo, label)
12-
if (!hostinfo) return
13-
t.is(hostinfo.https(), 'git+https://github.com/111/222.git' + hash, label + ' -> https')
14-
t.is(hostinfo.git(), 'git://github.com/111/222.git' + hash, label + ' -> git')
15-
t.is(hostinfo.browse(), 'https://github.com/111/222' + treebranch, label + ' -> browse')
16-
t.is(hostinfo.browse(''), 'https://github.com/111/222/tree/' + (branch || 'master') + '/', label + ' -> browse("")')
17-
t.is(hostinfo.browse('C'), 'https://github.com/111/222/tree/' + (branch || 'master') + '/C', label + ' -> browse(path)')
18-
t.is(hostinfo.browse('C/D'), 'https://github.com/111/222/tree/' + (branch || 'master') + '/C/D', label + ' -> browse(path)')
19-
t.is(hostinfo.browse('C', 'A'), 'https://github.com/111/222/tree/' + (branch || 'master') + '/C#a', label + ' -> browse(path, fragment)')
20-
t.is(hostinfo.browse('C/D', 'A'), 'https://github.com/111/222/tree/' + (branch || 'master') + '/C/D#a', label + ' -> browse(path, fragment)')
21-
t.is(hostinfo.bugs(), 'https://github.com/111/222/issues', label + ' -> bugs')
22-
t.is(hostinfo.docs(), 'https://github.com/111/222' + treebranch + '#readme', label + ' -> docs')
23-
t.is(hostinfo.ssh(), 'git@github.com:111/222.git' + hash, label + ' -> ssh')
24-
t.is(hostinfo.sshurl(), 'git+ssh://git@github.com/111/222.git' + hash, label + ' -> sshurl')
25-
t.is(hostinfo.sshurl({ noGitPlus: true }), 'ssh://git@github.com/111/222.git' + hash, label + ' -> sshurl (no git plus)')
26-
t.is(hostinfo.path(), '111/222' + hash, ' -> path')
27-
t.is(hostinfo.hash(), hash, ' -> hash')
28-
t.is(hostinfo.path({ noCommittish: true }), '111/222', ' -> path (no committish)')
29-
t.is(hostinfo.shortcut(), 'github:111/222' + hash, label + ' -> shortcut')
30-
t.is(hostinfo.file(''), 'https://raw.githubusercontent.com/111/222/' + (branch || 'master') + '/', label + ' -> file')
31-
t.is(hostinfo.file('C'), 'https://raw.githubusercontent.com/111/222/' + (branch || 'master') + '/C', label + ' -> file')
32-
t.is(hostinfo.file('C/D'), 'https://raw.githubusercontent.com/111/222/' + (branch || 'master') + '/C/D', label + ' -> file')
33-
t.is(hostinfo.tarball(), 'https://codeload.github.com/111/222/tar.gz/' + (branch || 'master'), label + ' -> tarball')
34-
t.is(hostinfo.tarball({ noCommittish: true }), 'https://codeload.github.com/111/222/tar.gz/' + (branch || 'master'), label + ' -> tarball')
35-
}
3612

37-
// github shorturls
38-
verify('111/222', 'github-short')
39-
verify('111/222#branch', 'github-short#branch', 'branch')
13+
// INFO: from Url should return `undefined` from fixture input
14+
if (fixture.isUndefined) {
15+
t.test('input results in undefined', function (tt) {
16+
tt.is(hostinfo, undefined)
17+
tt.end()
18+
})
19+
break
20+
}
4021

41-
// insecure protocols
42-
verify('git://github.com/111/222', 'git')
43-
verify('git://github.com/111/222.git', 'git.git')
44-
verify('git://github.com/111/222#branch', 'git#branch', 'branch')
45-
verify('git://github.com/111/222.git#branch', 'git.git#branch', 'branch')
22+
t.test('hostinfo.https', function (tt) {
23+
var expected = function (url, hasBranch) {
24+
return (hasBranch)
25+
? url + '#' + params.branch
26+
: url
27+
}
28+
tt.is(
29+
hostinfo.https(),
30+
expected('git+https://github.com/some-owner/some-repo.git', fixture.hasBranch),
31+
showLabel(fixture.label, 'https')
32+
)
33+
tt.end()
34+
})
35+
t.test('hostinfo.git', function (tt) {
36+
var expected = function (url, hasBranch) {
37+
return (hasBranch)
38+
? url + '#' + params.branch
39+
: url
40+
}
41+
tt.is(
42+
hostinfo.git(),
43+
expected('git://github.com/some-owner/some-repo.git', fixture.hasBranch),
44+
showLabel(fixture.label, 'git')
45+
)
46+
tt.end()
47+
})
48+
t.test('hostinfo.browse', function (tt) {
49+
var expected = function (url, hasBranch) {
50+
if (hasBranch) {
51+
if (url.indexOf('master') === -1) {
52+
return url + '/tree/' + params.branch
53+
} else {
54+
return url.replace(/master/gi, params.branch)
55+
}
56+
}
57+
return url
58+
}
59+
tt.is(
60+
hostinfo.browse(),
61+
expected('https://github.com/some-owner/some-repo', fixture.hasBranch),
62+
showLabel(fixture.label, 'browse')
63+
)
64+
tt.is(
65+
hostinfo.browse(''),
66+
expected('https://github.com/some-owner/some-repo/tree/master/', fixture.hasBranch),
67+
showLabel(fixture.label, "browse('')")
68+
)
69+
tt.is(
70+
hostinfo.browse('C'),
71+
expected('https://github.com/some-owner/some-repo/tree/master/C', fixture.hasBranch),
72+
showLabel(fixture.label, "browse('C')")
73+
)
74+
tt.is(
75+
hostinfo.browse('C/D'),
76+
expected('https://github.com/some-owner/some-repo/tree/master/C/D', fixture.hasBranch),
77+
showLabel(fixture.label, "browse('C/D')")
78+
)
79+
tt.is(
80+
hostinfo.browse('C', 'A'),
81+
expected('https://github.com/some-owner/some-repo/tree/master/C#a', fixture.hasBranch),
82+
showLabel(fixture.label, "browse('C', 'A')")
83+
)
84+
tt.is(
85+
hostinfo.browse('C/D', 'A'),
86+
expected('https://github.com/some-owner/some-repo/tree/master/C/D#a', fixture.hasBranch),
87+
showLabel(fixture.label, "browse('C/D', 'A')")
88+
)
89+
tt.end()
90+
})
91+
t.test('hostinfo.bugs', function (tt) {
92+
tt.is(
93+
hostinfo.bugs(),
94+
'https://github.com/some-owner/some-repo/issues',
95+
showLabel(fixture.label, 'bugs')
96+
)
97+
tt.end()
98+
})
99+
t.test('hostinfo.docs', function (tt) {
100+
var expected = function (url, hasBranch) {
101+
if (hasBranch) {
102+
var splitUrl = url.split('#')
103+
return splitUrl[0] + '/tree/' + params.branch + '#' + splitUrl[1]
104+
}
105+
return url
106+
}
107+
tt.is(
108+
hostinfo.docs(),
109+
expected('https://github.com/some-owner/some-repo#readme', fixture.hasBranch),
110+
showLabel(fixture.label, 'docs')
111+
)
112+
tt.end()
113+
})
114+
t.test('hostinfo.ssh', function (tt) {
115+
var expected = function (url, hasBranch) {
116+
return (hasBranch)
117+
? url + '#' + params.branch
118+
: url
119+
}
120+
tt.is(hostinfo.ssh(), expected('git@github.com:some-owner/some-repo.git', fixture.hasBranch), showLabel(fixture.label, 'ssh'))
121+
tt.end()
122+
})
123+
t.test('hostinfo.sshurl', function (tt) {
124+
var expected = function (url, hasBranch) {
125+
return (hasBranch)
126+
? url + '#' + params.branch
127+
: url
128+
}
129+
tt.is(
130+
hostinfo.sshurl(),
131+
expected('git+ssh://git@github.com/some-owner/some-repo.git', fixture.hasBranch),
132+
showLabel(fixture.label, 'sshurl')
133+
)
134+
tt.is(
135+
hostinfo.sshurl({ noGitPlus: true }),
136+
expected('ssh://git@github.com/some-owner/some-repo.git', fixture.hasBranch),
137+
showLabel(fixture.label, 'sshurl({ noGitPlus: true })')
138+
)
139+
tt.is(
140+
hostinfo.sshurl({ noGitPlus: false }),
141+
expected('git+ssh://git@github.com/some-owner/some-repo.git', fixture.hasBranch),
142+
showLabel(fixture.label, 'sshurl({ noGitPlus: false })')
143+
)
144+
tt.end()
145+
})
146+
t.test('hostinfo.path', function (tt) {
147+
var expected = function (url, hasBranch) {
148+
return (hasBranch)
149+
? url + '#' + params.branch
150+
: url
151+
}
152+
tt.is(
153+
hostinfo.path(),
154+
expected('some-owner/some-repo', fixture.hasBranch),
155+
showLabel(fixture.label, 'path')
156+
)
157+
tt.is(
158+
hostinfo.path({ noCommittish: true }),
159+
// INFO: not using `expected` because with `{noCommittish: true}` the output is always the same
160+
'some-owner/some-repo',
161+
showLabel(fixture.label, 'path({ noCommittish: true })')
162+
)
163+
tt.end()
164+
})
165+
t.test('hostinfo.hash', function (tt) {
166+
var expected = function (url, hasBranch) {
167+
return (hasBranch)
168+
? url + '#' + params.branch
169+
: url
170+
}
171+
tt.is(
172+
hostinfo.hash(),
173+
expected('', fixture.hasBranch),
174+
showLabel(fixture.label, 'hash')
175+
)
176+
tt.end()
177+
})
178+
t.test('hostinfo.shortcut', function (tt) {
179+
var expected = function (url, hasBranch) {
180+
return (hasBranch)
181+
? url + '#' + params.branch
182+
: url
183+
}
184+
tt.is(
185+
hostinfo.shortcut(),
186+
expected('github:some-owner/some-repo', fixture.hasBranch),
187+
showLabel(fixture.label, 'shortcut')
188+
)
189+
tt.is(
190+
hostinfo.shortcut({ noCommittish: true }),
191+
// INFO: not using `expected` because with `{noCommittish: true}` the output is always the same
192+
'github:some-owner/some-repo',
193+
showLabel(fixture.label, 'shortcut({ noCommittish: true })')
194+
)
195+
tt.is(
196+
hostinfo.shortcut({ noCommittish: false }),
197+
expected('github:some-owner/some-repo', fixture.hasBranch),
198+
showLabel(fixture.label, 'shortcut({ noCommittish: false })')
199+
)
200+
tt.is(
201+
hostinfo.shortcut({ noGitPlus: true }),
202+
expected('github:some-owner/some-repo', fixture.hasBranch),
203+
showLabel(fixture.label, 'shortcut({ noGitPlus: true })')
204+
)
205+
tt.is(
206+
hostinfo.shortcut({ noGitPlus: false }),
207+
expected('github:some-owner/some-repo', fixture.hasBranch),
208+
showLabel(fixture.label, 'shortcut({ noGitPlus: false })')
209+
)
210+
tt.end()
211+
})
212+
t.test('hostinfo.file', function (tt) {
213+
var expected = function (url, hasBranch) {
214+
return (hasBranch)
215+
? url.replace(/master/gi, params.branch)
216+
: url
217+
}
218+
tt.is(
219+
hostinfo.file(''),
220+
expected('https://raw.githubusercontent.com/some-owner/some-repo/master/', fixture.hasBranch),
221+
showLabel(fixture.label, 'file')
222+
)
223+
tt.is(
224+
hostinfo.file('C'),
225+
expected('https://raw.githubusercontent.com/some-owner/some-repo/master/C', fixture.hasBranch),
226+
showLabel(fixture.label, "file('C')")
227+
)
228+
// NOTE: This seems weird, don't think you'd ever pass the `opts` param with `.file()`
229+
tt.is(
230+
hostinfo.file('C', { noCommittish: true }),
231+
'https://raw.githubusercontent.com/some-owner/some-repo//C',
232+
showLabel(fixture.label, "file('C', { noCommittish: true })")
233+
)
234+
tt.is(
235+
hostinfo.file('C/D'),
236+
expected('https://raw.githubusercontent.com/some-owner/some-repo/master/C/D', fixture.hasBranch),
237+
showLabel(fixture.label, "file('C/D'")
238+
)
239+
tt.end()
240+
})
241+
t.test('hostinfo.tarball', function (tt) {
242+
var expected = function (url, hasBranch) {
243+
return (hasBranch)
244+
? url.replace(/master/gi, params.branch)
245+
: url
246+
}
247+
tt.is(
248+
hostinfo.tarball(),
249+
expected('https://codeload.github.com/some-owner/some-repo/tar.gz/master', fixture.hasBranch),
250+
showLabel(fixture.label, 'tarball')
251+
)
252+
tt.is(
253+
hostinfo.tarball({ noCommittish: true }),
254+
expected('https://codeload.github.com/some-owner/some-repo/tar.gz/master', fixture.hasBranch),
255+
showLabel(fixture.label, 'tarball({ noCommittish: true })')
256+
)
257+
tt.end()
258+
})
259+
}
260+
}
46261

47-
verify('http://github.com/111/222', 'http')
48-
verify('http://github.com/111/222.git', 'http.git')
49-
verify('http://github.com/111/222#branch', 'http#branch', 'branch')
50-
verify('http://github.com/111/222.git#branch', 'http.git#branch', 'branch')
262+
test('fromUrl(github url)', function (t) {
263+
var fixtures = require('./fixtures')
264+
var githubFixtures = require('./fixtures/github')
265+
var collectedFixtures = [].concat(fixtures, githubFixtures)
51266

52-
require('./lib/standard-tests')(verify, 'github.com', 'github')
267+
t.test('domain: github.com', function (tt) {
268+
var params = {
269+
domain: 'github.com',
270+
shortname: 'github',
271+
label: 'github',
272+
owner: 'some-owner',
273+
project: 'some-repo',
274+
branch: 'feature-branch'
275+
}
276+
testFixtures(tt, params, collectedFixtures)
277+
tt.end()
278+
})
53279

54-
require('./lib/standard-tests')(verify, 'www.github.com', 'github')
280+
t.test('domain: www.github.com', function (tt) {
281+
var params = {
282+
domain: 'www.github.com',
283+
shortname: 'github',
284+
label: 'github',
285+
owner: 'some-owner',
286+
project: 'some-repo',
287+
branch: 'feature-branch'
288+
}
289+
testFixtures(tt, params, collectedFixtures)
290+
tt.end()
291+
})
55292

56293
t.equal(HostedGit.fromUrl('git+ssh://github.com/foo.git'), undefined)
57294

‎test/gitlab.js

+268-38
Original file line numberDiff line numberDiff line change
@@ -2,47 +2,277 @@
22
var HostedGit = require('../index')
33
var test = require('tap').test
44

5-
test('fromUrl(gitlab url)', function (t) {
6-
function verify (host, label, branch) {
5+
var showLabel = function (label, fn) { return label + ' -> ' + fn }
6+
7+
var testFixtures = function (t, params, fixtures) {
8+
for (var i = 0; i < fixtures.length; ++i) {
9+
var fixture = fixtures[i]
10+
11+
var host = fixture.host(params)
712
var hostinfo = HostedGit.fromUrl(host)
8-
var hash = branch ? '#' + branch : ''
9-
t.ok(hostinfo, label)
10-
if (!hostinfo) return
11-
t.is(hostinfo.https(), 'git+https://gitlab.com/111/222.git' + hash, label + ' -> https')
12-
t.is(hostinfo.browse(), 'https://gitlab.com/111/222' + (branch ? '/tree/' + branch : ''), label + ' -> browse')
13-
t.is(hostinfo.browse(''), 'https://gitlab.com/111/222/tree/' + (branch || 'master') + '/', label + ' -> browse(path)')
14-
t.is(hostinfo.browse('C'), 'https://gitlab.com/111/222/tree/' + (branch || 'master') + '/C', label + ' -> browse(path)')
15-
t.is(hostinfo.browse('C/D'), 'https://gitlab.com/111/222/tree/' + (branch || 'master') + '/C/D', label + ' -> browse(path)')
16-
t.is(hostinfo.browse('C', 'A'), 'https://gitlab.com/111/222/tree/' + (branch || 'master') + '/C#a', label + ' -> browse(path, fragment)')
17-
t.is(hostinfo.browse('C/D', 'A'), 'https://gitlab.com/111/222/tree/' + (branch || 'master') + '/C/D#a', label + ' -> browse(path, fragment)')
18-
t.is(hostinfo.docs(), 'https://gitlab.com/111/222' + (branch ? '/tree/' + branch : '') + '#readme', label + ' -> docs')
19-
t.is(hostinfo.ssh(), 'git@gitlab.com:111/222.git' + hash, label + ' -> ssh')
20-
t.is(hostinfo.sshurl(), 'git+ssh://git@gitlab.com/111/222.git' + hash, label + ' -> sshurl')
21-
t.is(hostinfo.shortcut(), 'gitlab:111/222' + hash, label + ' -> shortcut')
22-
t.is(hostinfo.file(''), 'https://gitlab.com/111/222/raw/' + (branch || 'master') + '/', label + ' -> file')
23-
t.is(hostinfo.file('C'), 'https://gitlab.com/111/222/raw/' + (branch || 'master') + '/C', label + ' -> file')
24-
t.is(hostinfo.file('C/D'), 'https://gitlab.com/111/222/raw/' + (branch || 'master') + '/C/D', label + ' -> file')
25-
t.is(hostinfo.tarball(), 'https://gitlab.com/111/222/repository/archive.tar.gz?ref=' + (branch || 'master'), label + ' -> tarball')
26-
t.is(hostinfo.tarball({ noCommittish: true }), 'https://gitlab.com/111/222/repository/archive.tar.gz?ref=' + (branch || 'master'), label + ' -> tarball')
13+
14+
// INFO: fromUrl should return `undefined` from fixture input
15+
if (fixture.isUndefined) {
16+
t.test('input results in undefined', function (tt) {
17+
tt.is(hostinfo, undefined)
18+
tt.end()
19+
})
20+
break
21+
}
22+
23+
t.test('hostinfo.https', function (tt) {
24+
var expected = function (url, hasBranch) {
25+
return (hasBranch)
26+
? url + '#' + params.branch
27+
: url
28+
}
29+
tt.is(
30+
hostinfo.https(),
31+
expected('git+https://gitlab.com/some-owner/some-repo.git', fixture.hasBranch, fixture.hasGroup),
32+
showLabel(fixture.label, 'https')
33+
)
34+
tt.is(
35+
hostinfo.https({ noCommittish: true }),
36+
// INFO: not using `expected` because with `{noCommittish: true}` the output is always the same
37+
'git+https://gitlab.com/some-owner/some-repo.git',
38+
showLabel(fixture.label, 'https({ noCommittish: true })')
39+
)
40+
tt.is(
41+
hostinfo.https({ noGitPlus: true }),
42+
expected('https://gitlab.com/some-owner/some-repo.git', fixture.hasBranch),
43+
showLabel(fixture.label, 'https({ noGitPlus: true })')
44+
)
45+
tt.end()
46+
})
47+
t.test('hostinfo.browse', function (tt) {
48+
var expected = function (url, hasBranch) {
49+
if (hasBranch) {
50+
if (url.indexOf('master') === -1) {
51+
return url + '/tree/' + params.branch
52+
} else {
53+
return url.replace(/master/gi, params.branch)
54+
}
55+
}
56+
return url
57+
}
58+
tt.is(
59+
hostinfo.browse(),
60+
expected('https://gitlab.com/some-owner/some-repo', fixture.hasBranch),
61+
showLabel(fixture.label, 'browse')
62+
)
63+
tt.is(
64+
hostinfo.browse(''),
65+
expected('https://gitlab.com/some-owner/some-repo/tree/master/', fixture.hasBranch),
66+
showLabel(fixture.label, "browse('')")
67+
)
68+
tt.is(
69+
hostinfo.browse('C'),
70+
expected('https://gitlab.com/some-owner/some-repo/tree/master/C', fixture.hasBranch),
71+
showLabel(fixture.label, "browse('C')")
72+
)
73+
tt.is(
74+
hostinfo.browse('C/D'),
75+
expected('https://gitlab.com/some-owner/some-repo/tree/master/C/D', fixture.hasBranch),
76+
showLabel(fixture.label, "browse('C/D')")
77+
)
78+
tt.is(
79+
hostinfo.browse('C', 'A'),
80+
expected('https://gitlab.com/some-owner/some-repo/tree/master/C#a', fixture.hasBranch),
81+
showLabel(fixture.label, "browse('C', 'A')")
82+
)
83+
tt.is(
84+
hostinfo.browse('C/D', 'A'),
85+
expected('https://gitlab.com/some-owner/some-repo/tree/master/C/D#a', fixture.hasBranch),
86+
showLabel(fixture.label, "browse('C/D', 'A')")
87+
)
88+
tt.end()
89+
})
90+
t.test('hostinfo.docs', function (tt) {
91+
var expected = function (url, hasBranch) {
92+
if (hasBranch) {
93+
var splitUrl = url.split('#')
94+
return splitUrl[0] + '/tree/' + params.branch + '#' + splitUrl[1]
95+
}
96+
return url
97+
}
98+
tt.is(
99+
hostinfo.docs(),
100+
expected('https://gitlab.com/some-owner/some-repo#readme', fixture.hasBranch),
101+
showLabel(fixture.label, 'docs')
102+
)
103+
tt.is(
104+
hostinfo.docs({ noCommittish: true }),
105+
// INFO: not using `expected` because with `{noCommittish: true}` the output is always the same
106+
'https://gitlab.com/some-owner/some-repo#readme',
107+
showLabel(fixture.label, 'docs({ noCommittish: true })')
108+
)
109+
tt.is(
110+
hostinfo.docs({ noGitPlus: true }),
111+
expected('https://gitlab.com/some-owner/some-repo#readme', fixture.hasBranch),
112+
showLabel(fixture.label, 'docs({ noGitPlus: true })')
113+
)
114+
tt.end()
115+
})
116+
t.test('hostinfo.ssh', function (tt) {
117+
var expected = function (url, hasBranch) {
118+
return (hasBranch)
119+
? url + '#' + params.branch
120+
: url
121+
}
122+
tt.is(
123+
hostinfo.ssh(),
124+
expected('git@gitlab.com:some-owner/some-repo.git', fixture.hasBranch),
125+
showLabel(fixture.label, 'ssh')
126+
)
127+
tt.end()
128+
})
129+
t.test('hostinfo.sshurl', function (tt) {
130+
var expected = function (url, hasBranch) {
131+
return (hasBranch)
132+
? url + '#' + params.branch
133+
: url
134+
}
135+
tt.is(
136+
hostinfo.sshurl(),
137+
expected('git+ssh://git@gitlab.com/some-owner/some-repo.git', fixture.hasBranch),
138+
showLabel(fixture.label, 'sshurl')
139+
)
140+
tt.end()
141+
})
142+
t.test('hostinfo.shortcut', function (tt) {
143+
var expected = function (url, hasBranch) {
144+
return (hasBranch)
145+
? url + '#' + params.branch
146+
: url
147+
}
148+
tt.is(
149+
hostinfo.shortcut(),
150+
expected('gitlab:some-owner/some-repo', fixture.hasBranch),
151+
showLabel(fixture.label, 'shortcut')
152+
)
153+
tt.end()
154+
})
155+
t.test('hostinfo.file', function (tt) {
156+
var expected = function (url, hasBranch) {
157+
return (hasBranch)
158+
? url.replace(/master/gi, params.branch)
159+
: url
160+
}
161+
tt.is(
162+
hostinfo.file(),
163+
expected('https://gitlab.com/some-owner/some-repo/raw/master/', fixture.hasBranch),
164+
showLabel(fixture.label, 'file')
165+
)
166+
tt.is(
167+
hostinfo.file('C'),
168+
expected('https://gitlab.com/some-owner/some-repo/raw/master/C', fixture.hasBranch),
169+
showLabel(fixture.label, "file('C')")
170+
)
171+
tt.is(
172+
hostinfo.file('C/D'),
173+
expected('https://gitlab.com/some-owner/some-repo/raw/master/C/D', fixture.hasBranch),
174+
showLabel(fixture.label, "file('C/D')")
175+
)
176+
tt.end()
177+
})
178+
t.test('hostinfo.tarball', function (tt) {
179+
var expected = function (url, hasBranch) {
180+
return (hasBranch)
181+
? url.replace(/master/gi, params.branch)
182+
: url
183+
}
184+
tt.is(
185+
hostinfo.tarball(),
186+
expected('https://gitlab.com/some-owner/some-repo/repository/archive.tar.gz?ref=master', fixture.hasBranch),
187+
showLabel(fixture.label, 'tarball')
188+
)
189+
tt.is(
190+
hostinfo.tarball({ noCommittish: true }),
191+
expected('https://gitlab.com/some-owner/some-repo/repository/archive.tar.gz?ref=master', fixture.hasBranch),
192+
showLabel(fixture.label, 'tarball({ noCommittish: true })')
193+
)
194+
tt.end()
195+
})
27196
}
197+
}
198+
test('fromUrl(gitlab url)', function (t) {
199+
var fixtures = require('./fixtures')
200+
var gitlabFixtures = require('./fixtures/gitlab')
201+
var collectedFixtures = [].concat(fixtures, gitlabFixtures)
202+
203+
t.test('domain: gitlab.com', function (tt) {
204+
var params = {
205+
domain: 'gitlab.com',
206+
shortname: 'gitlab',
207+
label: 'gitlab',
208+
owner: 'some-owner',
209+
project: 'some-repo',
210+
branch: 'feature-branch'
211+
}
212+
testFixtures(tt, params, collectedFixtures)
213+
tt.end()
214+
})
215+
216+
t.test('domain: www.gitlab.com', function (tt) {
217+
var params = {
218+
domain: 'www.gitlab.com',
219+
shortname: 'gitlab',
220+
label: 'gitlab',
221+
owner: 'some-owner',
222+
project: 'some-repo',
223+
branch: 'feature-branch'
224+
}
225+
testFixtures(tt, params, collectedFixtures)
226+
tt.end()
227+
})
228+
229+
t.test('subgroups', function (tt) {
230+
var groupFixtures = require('./fixtures/gitlab-subgroups')
231+
232+
var params = {
233+
domain: 'gitlab.com',
234+
shortname: 'gitlab',
235+
label: 'gitlab',
236+
owner: 'some-owner',
237+
project: 'some-repo',
238+
group: 'group/sub-group1',
239+
branch: 'feature-branch'
240+
}
241+
for (var g = 0; g < groupFixtures.length; ++g) {
242+
var fixture = groupFixtures[g]
243+
var host = fixture.host(params)
244+
var hostinfo = HostedGit.fromUrl(host)
245+
246+
var expected = function (url, hasBranch) {
247+
return (hasBranch)
248+
? url + '#' + params.branch
249+
: url
250+
}
251+
tt.is(
252+
hostinfo.https(),
253+
expected('git+https://gitlab.com/some-owner/group/sub-group1/some-repo.git', fixture.hasBranch),
254+
showLabel(fixture.label, 'https')
255+
)
256+
tt.is(
257+
hostinfo.https({ noCommittish: true }),
258+
// INFO: not using `expected` because with `{noCommittish: true}` the output is always the same
259+
'git+https://gitlab.com/some-owner/group/sub-group1/some-repo.git',
260+
showLabel(fixture.label, 'https({ noCommittish: true })')
261+
)
262+
tt.is(
263+
hostinfo.https({ noGitPlus: true }),
264+
expected('https://gitlab.com/some-owner/group/sub-group1/some-repo.git', fixture.hasBranch),
265+
showLabel(fixture.label, 'https({ noGitPlus: true })')
266+
)
267+
}
28268

29-
require('./lib/standard-tests')(verify, 'gitlab.com', 'gitlab')
30-
require('./lib/standard-tests')(verify, 'www.gitlab.com', 'gitlab')
31-
32-
const subsShort = HostedGit.fromUrl('gitlab:adpt/starters/hello-node')
33-
const subsFull = HostedGit.fromUrl('git+https://gitlab.com/adpt/starters/hello-node.git')
34-
t.ok(subsShort)
35-
t.equal(subsShort.https(), 'git+https://gitlab.com/adpt/starters/hello-node.git')
36-
t.equal(subsShort.ssh(), 'git@gitlab.com:adpt/starters/hello-node.git')
37-
t.ok(subsFull)
38-
t.equal(subsFull.https(), 'git+https://gitlab.com/adpt/starters/hello-node.git')
39-
t.equal(subsFull.ssh(), 'git@gitlab.com:adpt/starters/hello-node.git')
40-
41-
t.is(
42-
HostedGit.fromUrl('gitlab:group/sub group1/subgroup2/repo').https(),
43-
'git+https://gitlab.com/group/sub%20group1/subgroup2/repo.git',
44-
'subgroups are delimited with slashes and url encoded (shortcut -> https)'
45-
)
269+
tt.is(
270+
HostedGit.fromUrl('gitlab:group/sub group1/subgroup2/repo').https(),
271+
'git+https://gitlab.com/group/sub%20group1/subgroup2/repo.git',
272+
'subgroups are delimited with slashes and url encoded (shortcut -> https)'
273+
)
274+
tt.end()
275+
})
46276

47277
t.end()
48278
})

0 commit comments

Comments
 (0)
Please sign in to comment.