|
2 | 2 | var HostedGit = require('../index')
|
3 | 3 | var test = require('tap').test
|
4 | 4 |
|
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) |
7 | 11 | 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 |
| - } |
36 | 12 |
|
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 | + } |
40 | 21 |
|
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 | +} |
46 | 261 |
|
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) |
51 | 266 |
|
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 | + }) |
53 | 279 |
|
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 | + }) |
55 | 292 |
|
56 | 293 | t.equal(HostedGit.fromUrl('git+ssh://github.com/foo.git'), undefined)
|
57 | 294 |
|
|
0 commit comments