From 888f9b4908be6e8fdd2f856190301c079834d035 Mon Sep 17 00:00:00 2001 From: Michael Perrotte Date: Fri, 27 Sep 2019 14:19:57 -0400 Subject: [PATCH 01/10] test: added default fixtures and github specific fixtures --- test/fixtures/github.js | 38 ++++ test/fixtures/gitlab-subgroups.js | 22 ++ test/fixtures/gitlab.js | 99 +++++++++ test/fixtures/index.js | 99 +++++++++ test/github.js | 325 ++++++++++++++++++++++++++---- test/gitlab.js | 306 ++++++++++++++++++++++++---- 6 files changed, 807 insertions(+), 82 deletions(-) create mode 100644 test/fixtures/github.js create mode 100644 test/fixtures/gitlab-subgroups.js create mode 100644 test/fixtures/gitlab.js create mode 100644 test/fixtures/index.js diff --git a/test/fixtures/github.js b/test/fixtures/github.js new file mode 100644 index 0000000..596d74a --- /dev/null +++ b/test/fixtures/github.js @@ -0,0 +1,38 @@ +'use strict' + +module.exports = [ + // Github Shorturls + { + host: function (p) { return p.owner + '/' + p.project }, + label: 'github-short' + }, + { + host: function (p) { return p.owner + '/' + p.project + '#' + p.branch }, + label: 'github-short#branch', + hasBranch: true + }, + { + host: function (p) { return p.owner + '/' + p.project + '#' + p.branch }, + label: 'github-short#branch', + hasBranch: true + }, + // Insecure Protocols + { + host: function (p) { return 'git://' + p.domain + '/' + p.owner + '/' + p.project }, + label: 'git' + }, + { + host: function (p) { return 'git://' + p.domain + '/' + p.owner + '/' + p.project + '.git' }, + label: 'git.git' + }, + { + host: function (p) { return 'git://' + p.domain + '/' + p.owner + '/' + p.project + '#' + p.branch }, + label: 'git#branch', + hasBranch: true + }, + { + host: function (p) { return 'git://' + p.domain + '/' + p.owner + '/' + p.project + '.git#' + p.branch }, + label: 'git.git#branch', + hasBranch: true + } +] diff --git a/test/fixtures/gitlab-subgroups.js b/test/fixtures/gitlab-subgroups.js new file mode 100644 index 0000000..5598e52 --- /dev/null +++ b/test/fixtures/gitlab-subgroups.js @@ -0,0 +1,22 @@ +'use strict' + +module.exports = [ + { + host: function (p) { return p.shortname + ':' + p.owner + '/' + p.group + '/' + p.project }, + label: 'shortname' + }, + { + host: function (p) { return p.shortname + ':' + p.owner + '/' + p.group + '/' + p.project }, + label: 'shortname.git' + }, + { + host: function (p) { return p.shortname + ':' + p.owner + '/' + p.group + '/' + p.project + '#' + p.branch }, + label: 'shortname#branch', + hasBranch: true + }, + { + host: function (p) { return p.shortname + ':' + p.owner + '/' + p.group + '/' + p.project + '#' + p.branch }, + label: 'shortname.git#branch', + hasBranch: true + } +] diff --git a/test/fixtures/gitlab.js b/test/fixtures/gitlab.js new file mode 100644 index 0000000..33053da --- /dev/null +++ b/test/fixtures/gitlab.js @@ -0,0 +1,99 @@ +'use strcit' + +module.exports = [ + { + host: function (p) { return 'https://' + p.domain + '/' + p.owner + '/' + p.project }, + label: 'https' + }, + { + host: function (p) { return 'https://' + p.domain + '/' + p.owner + '/' + p.project + '.git' }, + label: 'https.git' + }, + { + host: function (p) { return 'https://' + p.domain + '/' + p.owner + '/' + p.project + '#' + p.branch }, + label: 'https#branch', + hasBranch: true + }, + { + host: function (p) { return 'https://' + p.domain + '/' + p.owner + '/' + p.project + '.git#' + p.branch }, + label: 'https.git#branch', + hasBranch: true + }, + { + host: function (p) { return 'https://' + p.domain + '/' + p.owner + '/' + p.project + '/-/' + 'archive' + '/3.3.2' + '/ws-3.3.2.tar.gz' }, + label: 'https.tar', + isUndefined: true + }, + { + host: function (p) { return 'git+https://' + p.domain + '/' + p.owner + '/' + p.project }, + label: 'git+https' + }, + { + host: function (p) { return 'git+https://' + p.domain + '/' + p.owner + '/' + p.project + '.git' }, + label: 'git+https.git' + }, + { + host: function (p) { return 'git+https://' + p.domain + '/' + p.owner + '/' + p.project + '#' + p.branch }, + label: 'git+https#branch', + hasBranch: true + }, + { + host: function (p) { return 'git+https://' + p.domain + '/' + p.owner + '/' + p.project + '.git#' + p.branch }, + label: 'git+https.git#branch', + hasBranch: true + }, + { + host: function (p) { return 'git@' + p.domain + ':' + p.owner + '/' + p.project }, + label: 'ssh' + }, + { + host: function (p) { return 'git@' + p.domain + ':' + p.owner + '/' + p.project + '.git' }, + label: 'ssh.git' + }, + { + host: function (p) { return 'git@' + p.domain + ':' + p.owner + '/' + p.project + '#' + p.branch }, + label: 'ssh#branch', + hasBranch: true + }, + { + host: function (p) { return 'git@' + p.domain + ':' + p.owner + '/' + p.project + '.git#' + p.branch }, + label: 'ssh.git#branch', + hasBranch: true + }, + { + host: function (p) { return 'git+ssh://git@' + p.domain + '/' + p.owner + '/' + p.project }, + label: 'ssh-url' + }, + { + host: function (p) { return 'git+ssh://git@' + p.domain + '/' + p.owner + '/' + p.project + '.git' }, + label: 'ssh-url.git' + }, + { + host: function (p) { return 'git+ssh://git@' + p.domain + '/' + p.owner + '/' + p.project + '#' + p.branch }, + label: 'ssh-url#branch', + hasBranch: true + }, + { + host: function (p) { return 'git+ssh://git@' + p.domain + '/' + p.owner + '/' + p.project + '.git#' + p.branch }, + label: 'ssh-url.git#branch', + hasBranch: true + }, + { + host: function (p) { return p.shortname + ':' + p.owner + '/' + p.project }, + label: 'shortcut' + }, + { + host: function (p) { return p.shortname + ':' + p.owner + '/' + p.project + '.git' }, + label: 'shortcut.git' + }, + { + host: function (p) { return p.shortname + ':' + p.owner + '/' + p.project + '#' + p.branch }, + label: 'shortcut#branch', + hasBranch: true + }, + { + host: function (p) { return p.shortname + ':' + p.owner + '/' + p.project + '.git#' + p.branch }, + label: 'shortcut.git#branch', + hasBranch: true + } +] diff --git a/test/fixtures/index.js b/test/fixtures/index.js new file mode 100644 index 0000000..33053da --- /dev/null +++ b/test/fixtures/index.js @@ -0,0 +1,99 @@ +'use strcit' + +module.exports = [ + { + host: function (p) { return 'https://' + p.domain + '/' + p.owner + '/' + p.project }, + label: 'https' + }, + { + host: function (p) { return 'https://' + p.domain + '/' + p.owner + '/' + p.project + '.git' }, + label: 'https.git' + }, + { + host: function (p) { return 'https://' + p.domain + '/' + p.owner + '/' + p.project + '#' + p.branch }, + label: 'https#branch', + hasBranch: true + }, + { + host: function (p) { return 'https://' + p.domain + '/' + p.owner + '/' + p.project + '.git#' + p.branch }, + label: 'https.git#branch', + hasBranch: true + }, + { + host: function (p) { return 'https://' + p.domain + '/' + p.owner + '/' + p.project + '/-/' + 'archive' + '/3.3.2' + '/ws-3.3.2.tar.gz' }, + label: 'https.tar', + isUndefined: true + }, + { + host: function (p) { return 'git+https://' + p.domain + '/' + p.owner + '/' + p.project }, + label: 'git+https' + }, + { + host: function (p) { return 'git+https://' + p.domain + '/' + p.owner + '/' + p.project + '.git' }, + label: 'git+https.git' + }, + { + host: function (p) { return 'git+https://' + p.domain + '/' + p.owner + '/' + p.project + '#' + p.branch }, + label: 'git+https#branch', + hasBranch: true + }, + { + host: function (p) { return 'git+https://' + p.domain + '/' + p.owner + '/' + p.project + '.git#' + p.branch }, + label: 'git+https.git#branch', + hasBranch: true + }, + { + host: function (p) { return 'git@' + p.domain + ':' + p.owner + '/' + p.project }, + label: 'ssh' + }, + { + host: function (p) { return 'git@' + p.domain + ':' + p.owner + '/' + p.project + '.git' }, + label: 'ssh.git' + }, + { + host: function (p) { return 'git@' + p.domain + ':' + p.owner + '/' + p.project + '#' + p.branch }, + label: 'ssh#branch', + hasBranch: true + }, + { + host: function (p) { return 'git@' + p.domain + ':' + p.owner + '/' + p.project + '.git#' + p.branch }, + label: 'ssh.git#branch', + hasBranch: true + }, + { + host: function (p) { return 'git+ssh://git@' + p.domain + '/' + p.owner + '/' + p.project }, + label: 'ssh-url' + }, + { + host: function (p) { return 'git+ssh://git@' + p.domain + '/' + p.owner + '/' + p.project + '.git' }, + label: 'ssh-url.git' + }, + { + host: function (p) { return 'git+ssh://git@' + p.domain + '/' + p.owner + '/' + p.project + '#' + p.branch }, + label: 'ssh-url#branch', + hasBranch: true + }, + { + host: function (p) { return 'git+ssh://git@' + p.domain + '/' + p.owner + '/' + p.project + '.git#' + p.branch }, + label: 'ssh-url.git#branch', + hasBranch: true + }, + { + host: function (p) { return p.shortname + ':' + p.owner + '/' + p.project }, + label: 'shortcut' + }, + { + host: function (p) { return p.shortname + ':' + p.owner + '/' + p.project + '.git' }, + label: 'shortcut.git' + }, + { + host: function (p) { return p.shortname + ':' + p.owner + '/' + p.project + '#' + p.branch }, + label: 'shortcut#branch', + hasBranch: true + }, + { + host: function (p) { return p.shortname + ':' + p.owner + '/' + p.project + '.git#' + p.branch }, + label: 'shortcut.git#branch', + hasBranch: true + } +] diff --git a/test/github.js b/test/github.js index 74ecaa6..146a203 100644 --- a/test/github.js +++ b/test/github.js @@ -2,56 +2,293 @@ var HostedGit = require('../index') var test = require('tap').test -test('fromUrl(github url)', function (t) { - function verify (host, label, branch) { +var showLabel = function (label, fn) { return label + ' -> ' + fn } + +var testFixtures = function (t, params, fixtures) { + for (var i = 0; i < fixtures.length; ++i) { + var fixture = fixtures[i] + var host = fixture.host(params) var hostinfo = HostedGit.fromUrl(host) - var hash = branch ? '#' + branch : '' - var treebranch = branch ? '/tree/' + branch : '' - t.equal(hostinfo._fill(), undefined) - t.ok(hostinfo, label) - if (!hostinfo) return - t.is(hostinfo.https(), 'git+https://github.com/111/222.git' + hash, label + ' -> https') - t.is(hostinfo.git(), 'git://github.com/111/222.git' + hash, label + ' -> git') - t.is(hostinfo.browse(), 'https://github.com/111/222' + treebranch, label + ' -> browse') - t.is(hostinfo.browse(''), 'https://github.com/111/222/tree/' + (branch || 'master') + '/', label + ' -> browse("")') - t.is(hostinfo.browse('C'), 'https://github.com/111/222/tree/' + (branch || 'master') + '/C', label + ' -> browse(path)') - t.is(hostinfo.browse('C/D'), 'https://github.com/111/222/tree/' + (branch || 'master') + '/C/D', label + ' -> browse(path)') - t.is(hostinfo.browse('C', 'A'), 'https://github.com/111/222/tree/' + (branch || 'master') + '/C#a', label + ' -> browse(path, fragment)') - t.is(hostinfo.browse('C/D', 'A'), 'https://github.com/111/222/tree/' + (branch || 'master') + '/C/D#a', label + ' -> browse(path, fragment)') - t.is(hostinfo.bugs(), 'https://github.com/111/222/issues', label + ' -> bugs') - t.is(hostinfo.docs(), 'https://github.com/111/222' + treebranch + '#readme', label + ' -> docs') - t.is(hostinfo.ssh(), 'git@github.com:111/222.git' + hash, label + ' -> ssh') - t.is(hostinfo.sshurl(), 'git+ssh://git@github.com/111/222.git' + hash, label + ' -> sshurl') - t.is(hostinfo.sshurl({ noGitPlus: true }), 'ssh://git@github.com/111/222.git' + hash, label + ' -> sshurl (no git plus)') - t.is(hostinfo.path(), '111/222' + hash, ' -> path') - t.is(hostinfo.hash(), hash, ' -> hash') - t.is(hostinfo.path({ noCommittish: true }), '111/222', ' -> path (no committish)') - t.is(hostinfo.shortcut(), 'github:111/222' + hash, label + ' -> shortcut') - t.is(hostinfo.file(''), 'https://raw.githubusercontent.com/111/222/' + (branch || 'master') + '/', label + ' -> file') - t.is(hostinfo.file('C'), 'https://raw.githubusercontent.com/111/222/' + (branch || 'master') + '/C', label + ' -> file') - t.is(hostinfo.file('C/D'), 'https://raw.githubusercontent.com/111/222/' + (branch || 'master') + '/C/D', label + ' -> file') - t.is(hostinfo.tarball(), 'https://codeload.github.com/111/222/tar.gz/' + (branch || 'master'), label + ' -> tarball') - t.is(hostinfo.tarball({ noCommittish: true }), 'https://codeload.github.com/111/222/tar.gz/' + (branch || 'master'), label + ' -> tarball') - } - // github shorturls - verify('111/222', 'github-short') - verify('111/222#branch', 'github-short#branch', 'branch') + // INFO: from Url should return `undefined` from fixture input + if (fixture.isUndefined) { + t.test('input results in undefined', function (tt) { + tt.is(hostinfo, undefined) + tt.end() + }) + break + } - // insecure protocols - verify('git://github.com/111/222', 'git') - verify('git://github.com/111/222.git', 'git.git') - verify('git://github.com/111/222#branch', 'git#branch', 'branch') - verify('git://github.com/111/222.git#branch', 'git.git#branch', 'branch') + t.test('hostinfo.https', function (tt) { + var expected = function (url, hasBranch) { + return (hasBranch) + ? url + '#' + params.branch + : url + } + tt.is( + hostinfo.https(), + expected('git+https://github.com/some-owner/some-repo.git', fixture.hasBranch), + showLabel(fixture.label, 'https') + ) + tt.end() + }) + t.test('hostinfo.git', function (tt) { + var expected = function (url, hasBranch) { + return (hasBranch) + ? url + '#' + params.branch + : url + } + tt.is( + hostinfo.git(), + expected('git://github.com/some-owner/some-repo.git', fixture.hasBranch), + showLabel(fixture.label, 'git') + ) + tt.end() + }) + t.test('hostinfo.browse', function (tt) { + var expected = function (url, hasBranch) { + if (hasBranch) { + if (url.indexOf('master') === -1) { + return url + '/tree/' + params.branch + } else { + return url.replace(/master/gi, params.branch) + } + } + return url + } + tt.is( + hostinfo.browse(), + expected('https://github.com/some-owner/some-repo', fixture.hasBranch), + showLabel(fixture.label, 'browse') + ) + tt.is( + hostinfo.browse(''), + expected('https://github.com/some-owner/some-repo/tree/master/', fixture.hasBranch), + showLabel(fixture.label, "browse('')") + ) + tt.is( + hostinfo.browse('C'), + expected('https://github.com/some-owner/some-repo/tree/master/C', fixture.hasBranch), + showLabel(fixture.label, "browse('C')") + ) + tt.is( + hostinfo.browse('C/D'), + expected('https://github.com/some-owner/some-repo/tree/master/C/D', fixture.hasBranch), + showLabel(fixture.label, "browse('C/D')") + ) + tt.is( + hostinfo.browse('C', 'A'), + expected('https://github.com/some-owner/some-repo/tree/master/C#a', fixture.hasBranch), + showLabel(fixture.label, "browse('C', 'A')") + ) + tt.is( + hostinfo.browse('C/D', 'A'), + expected('https://github.com/some-owner/some-repo/tree/master/C/D#a', fixture.hasBranch), + showLabel(fixture.label, "browse('C/D', 'A')") + ) + tt.end() + }) + t.test('hostinfo.bugs', function (tt) { + tt.is( + hostinfo.bugs(), + 'https://github.com/some-owner/some-repo/issues', + showLabel(fixture.label, 'bugs') + ) + tt.end() + }) + t.test('hostinfo.docs', function (tt) { + var expected = function (url, hasBranch) { + if (hasBranch) { + var splitUrl = url.split('#') + return splitUrl[0] + '/tree/' + params.branch + '#' + splitUrl[1] + } + return url + } + tt.is( + hostinfo.docs(), + expected('https://github.com/some-owner/some-repo#readme', fixture.hasBranch), + showLabel(fixture.label, 'docs') + ) + tt.end() + }) + t.test('hostinfo.ssh', function (tt) { + var expected = function (url, hasBranch) { + return (hasBranch) + ? url + '#' + params.branch + : url + } + tt.is(hostinfo.ssh(), expected('git@github.com:some-owner/some-repo.git', fixture.hasBranch), showLabel(fixture.label, 'ssh')) + tt.end() + }) + t.test('hostinfo.sshurl', function (tt) { + var expected = function (url, hasBranch) { + return (hasBranch) + ? url + '#' + params.branch + : url + } + tt.is( + hostinfo.sshurl(), + expected('git+ssh://git@github.com/some-owner/some-repo.git', fixture.hasBranch), + showLabel(fixture.label, 'sshurl') + ) + tt.is( + hostinfo.sshurl({ noGitPlus: true }), + expected('ssh://git@github.com/some-owner/some-repo.git', fixture.hasBranch), + showLabel(fixture.label, 'sshurl({ noGitPlus: true })') + ) + tt.is( + hostinfo.sshurl({ noGitPlus: false }), + expected('git+ssh://git@github.com/some-owner/some-repo.git', fixture.hasBranch), + showLabel(fixture.label, 'sshurl({ noGitPlus: false })') + ) + tt.end() + }) + t.test('hostinfo.path', function (tt) { + var expected = function (url, hasBranch) { + return (hasBranch) + ? url + '#' + params.branch + : url + } + tt.is( + hostinfo.path(), + expected('some-owner/some-repo', fixture.hasBranch), + showLabel(fixture.label, 'path') + ) + tt.is( + hostinfo.path({ noCommittish: true }), + // INFO: not using `expected` because with `{noCommittish: true}` the output is always the same + 'some-owner/some-repo', + showLabel(fixture.label, 'path({ noCommittish: true })') + ) + tt.end() + }) + t.test('hostinfo.hash', function (tt) { + var expected = function (url, hasBranch) { + return (hasBranch) + ? url + '#' + params.branch + : url + } + tt.is( + hostinfo.hash(), + expected('', fixture.hasBranch), + showLabel(fixture.label, 'hash') + ) + tt.end() + }) + t.test('hostinfo.shortcut', function (tt) { + var expected = function (url, hasBranch) { + return (hasBranch) + ? url + '#' + params.branch + : url + } + tt.is( + hostinfo.shortcut(), + expected('github:some-owner/some-repo', fixture.hasBranch), + showLabel(fixture.label, 'shortcut') + ) + tt.is( + hostinfo.shortcut({ noCommittish: true }), + // INFO: not using `expected` because with `{noCommittish: true}` the output is always the same + 'github:some-owner/some-repo', + showLabel(fixture.label, 'shortcut({ noCommittish: true })') + ) + tt.is( + hostinfo.shortcut({ noCommittish: false }), + expected('github:some-owner/some-repo', fixture.hasBranch), + showLabel(fixture.label, 'shortcut({ noCommittish: false })') + ) + tt.is( + hostinfo.shortcut({ noGitPlus: true }), + expected('github:some-owner/some-repo', fixture.hasBranch), + showLabel(fixture.label, 'shortcut({ noGitPlus: true })') + ) + tt.is( + hostinfo.shortcut({ noGitPlus: false }), + expected('github:some-owner/some-repo', fixture.hasBranch), + showLabel(fixture.label, 'shortcut({ noGitPlus: false })') + ) + tt.end() + }) + t.test('hostinfo.file', function (tt) { + var expected = function (url, hasBranch) { + return (hasBranch) + ? url.replace(/master/gi, params.branch) + : url + } + tt.is( + hostinfo.file(''), + expected('https://raw.githubusercontent.com/some-owner/some-repo/master/', fixture.hasBranch), + showLabel(fixture.label, 'file') + ) + tt.is( + hostinfo.file('C'), + expected('https://raw.githubusercontent.com/some-owner/some-repo/master/C', fixture.hasBranch), + showLabel(fixture.label, "file('C')") + ) + // NOTE: This seems weird, don't think you'd ever pass the `opts` param with `.file()` + tt.is( + hostinfo.file('C', { noCommittish: true }), + 'https://raw.githubusercontent.com/some-owner/some-repo//C', + showLabel(fixture.label, "file('C', { noCommittish: true })") + ) + tt.is( + hostinfo.file('C/D'), + expected('https://raw.githubusercontent.com/some-owner/some-repo/master/C/D', fixture.hasBranch), + showLabel(fixture.label, "file('C/D'") + ) + tt.end() + }) + t.test('hostinfo.tarball', function (tt) { + var expected = function (url, hasBranch) { + return (hasBranch) + ? url.replace(/master/gi, params.branch) + : url + } + tt.is( + hostinfo.tarball(), + expected('https://codeload.github.com/some-owner/some-repo/tar.gz/master', fixture.hasBranch), + showLabel(fixture.label, 'tarball') + ) + tt.is( + hostinfo.tarball({ noCommittish: true }), + expected('https://codeload.github.com/some-owner/some-repo/tar.gz/master', fixture.hasBranch), + showLabel(fixture.label, 'tarball({ noCommittish: true })') + ) + tt.end() + }) + } +} - verify('http://github.com/111/222', 'http') - verify('http://github.com/111/222.git', 'http.git') - verify('http://github.com/111/222#branch', 'http#branch', 'branch') - verify('http://github.com/111/222.git#branch', 'http.git#branch', 'branch') +test('fromUrl(github url)', function (t) { + var fixtures = require('./fixtures') + var githubFixtures = require('./fixtures/github') + var collectedFixtures = [].concat(fixtures, githubFixtures) - require('./lib/standard-tests')(verify, 'github.com', 'github') + t.test('domain: github.com', function (tt) { + var params = { + domain: 'github.com', + shortname: 'github', + label: 'github', + owner: 'some-owner', + project: 'some-repo', + branch: 'feature-branch' + } + testFixtures(tt, params, collectedFixtures) + tt.end() + }) - require('./lib/standard-tests')(verify, 'www.github.com', 'github') + t.test('domain: www.github.com', function (tt) { + var params = { + domain: 'www.github.com', + shortname: 'github', + label: 'github', + owner: 'some-owner', + project: 'some-repo', + branch: 'feature-branch' + } + testFixtures(tt, params, collectedFixtures) + tt.end() + }) t.equal(HostedGit.fromUrl('git+ssh://github.com/foo.git'), undefined) diff --git a/test/gitlab.js b/test/gitlab.js index 22b13d0..cd0f7d8 100644 --- a/test/gitlab.js +++ b/test/gitlab.js @@ -2,47 +2,277 @@ var HostedGit = require('../index') var test = require('tap').test -test('fromUrl(gitlab url)', function (t) { - function verify (host, label, branch) { +var showLabel = function (label, fn) { return label + ' -> ' + fn } + +var testFixtures = function (t, params, fixtures) { + for (var i = 0; i < fixtures.length; ++i) { + var fixture = fixtures[i] + + var host = fixture.host(params) var hostinfo = HostedGit.fromUrl(host) - var hash = branch ? '#' + branch : '' - t.ok(hostinfo, label) - if (!hostinfo) return - t.is(hostinfo.https(), 'git+https://gitlab.com/111/222.git' + hash, label + ' -> https') - t.is(hostinfo.browse(), 'https://gitlab.com/111/222' + (branch ? '/tree/' + branch : ''), label + ' -> browse') - t.is(hostinfo.browse(''), 'https://gitlab.com/111/222/tree/' + (branch || 'master') + '/', label + ' -> browse(path)') - t.is(hostinfo.browse('C'), 'https://gitlab.com/111/222/tree/' + (branch || 'master') + '/C', label + ' -> browse(path)') - t.is(hostinfo.browse('C/D'), 'https://gitlab.com/111/222/tree/' + (branch || 'master') + '/C/D', label + ' -> browse(path)') - t.is(hostinfo.browse('C', 'A'), 'https://gitlab.com/111/222/tree/' + (branch || 'master') + '/C#a', label + ' -> browse(path, fragment)') - t.is(hostinfo.browse('C/D', 'A'), 'https://gitlab.com/111/222/tree/' + (branch || 'master') + '/C/D#a', label + ' -> browse(path, fragment)') - t.is(hostinfo.docs(), 'https://gitlab.com/111/222' + (branch ? '/tree/' + branch : '') + '#readme', label + ' -> docs') - t.is(hostinfo.ssh(), 'git@gitlab.com:111/222.git' + hash, label + ' -> ssh') - t.is(hostinfo.sshurl(), 'git+ssh://git@gitlab.com/111/222.git' + hash, label + ' -> sshurl') - t.is(hostinfo.shortcut(), 'gitlab:111/222' + hash, label + ' -> shortcut') - t.is(hostinfo.file(''), 'https://gitlab.com/111/222/raw/' + (branch || 'master') + '/', label + ' -> file') - t.is(hostinfo.file('C'), 'https://gitlab.com/111/222/raw/' + (branch || 'master') + '/C', label + ' -> file') - t.is(hostinfo.file('C/D'), 'https://gitlab.com/111/222/raw/' + (branch || 'master') + '/C/D', label + ' -> file') - t.is(hostinfo.tarball(), 'https://gitlab.com/111/222/repository/archive.tar.gz?ref=' + (branch || 'master'), label + ' -> tarball') - t.is(hostinfo.tarball({ noCommittish: true }), 'https://gitlab.com/111/222/repository/archive.tar.gz?ref=' + (branch || 'master'), label + ' -> tarball') + + // INFO: fromUrl should return `undefined` from fixture input + if (fixture.isUndefined) { + t.test('input results in undefined', function (tt) { + tt.is(hostinfo, undefined) + tt.end() + }) + break + } + + t.test('hostinfo.https', function (tt) { + var expected = function (url, hasBranch) { + return (hasBranch) + ? url + '#' + params.branch + : url + } + tt.is( + hostinfo.https(), + expected('git+https://gitlab.com/some-owner/some-repo.git', fixture.hasBranch, fixture.hasGroup), + showLabel(fixture.label, 'https') + ) + tt.is( + hostinfo.https({ noCommittish: true }), + // INFO: not using `expected` because with `{noCommittish: true}` the output is always the same + 'git+https://gitlab.com/some-owner/some-repo.git', + showLabel(fixture.label, 'https({ noCommittish: true })') + ) + tt.is( + hostinfo.https({ noGitPlus: true }), + expected('https://gitlab.com/some-owner/some-repo.git', fixture.hasBranch), + showLabel(fixture.label, 'https({ noGitPlus: true })') + ) + tt.end() + }) + t.test('hostinfo.browse', function (tt) { + var expected = function (url, hasBranch) { + if (hasBranch) { + if (url.indexOf('master') === -1) { + return url + '/tree/' + params.branch + } else { + return url.replace(/master/gi, params.branch) + } + } + return url + } + tt.is( + hostinfo.browse(), + expected('https://gitlab.com/some-owner/some-repo', fixture.hasBranch), + showLabel(fixture.label, 'browse') + ) + tt.is( + hostinfo.browse(''), + expected('https://gitlab.com/some-owner/some-repo/tree/master/', fixture.hasBranch), + showLabel(fixture.label, "browse('')") + ) + tt.is( + hostinfo.browse('C'), + expected('https://gitlab.com/some-owner/some-repo/tree/master/C', fixture.hasBranch), + showLabel(fixture.label, "browse('C')") + ) + tt.is( + hostinfo.browse('C/D'), + expected('https://gitlab.com/some-owner/some-repo/tree/master/C/D', fixture.hasBranch), + showLabel(fixture.label, "browse('C/D')") + ) + tt.is( + hostinfo.browse('C', 'A'), + expected('https://gitlab.com/some-owner/some-repo/tree/master/C#a', fixture.hasBranch), + showLabel(fixture.label, "browse('C', 'A')") + ) + tt.is( + hostinfo.browse('C/D', 'A'), + expected('https://gitlab.com/some-owner/some-repo/tree/master/C/D#a', fixture.hasBranch), + showLabel(fixture.label, "browse('C/D', 'A')") + ) + tt.end() + }) + t.test('hostinfo.docs', function (tt) { + var expected = function (url, hasBranch) { + if (hasBranch) { + var splitUrl = url.split('#') + return splitUrl[0] + '/tree/' + params.branch + '#' + splitUrl[1] + } + return url + } + tt.is( + hostinfo.docs(), + expected('https://gitlab.com/some-owner/some-repo#readme', fixture.hasBranch), + showLabel(fixture.label, 'docs') + ) + tt.is( + hostinfo.docs({ noCommittish: true }), + // INFO: not using `expected` because with `{noCommittish: true}` the output is always the same + 'https://gitlab.com/some-owner/some-repo#readme', + showLabel(fixture.label, 'docs({ noCommittish: true })') + ) + tt.is( + hostinfo.docs({ noGitPlus: true }), + expected('https://gitlab.com/some-owner/some-repo#readme', fixture.hasBranch), + showLabel(fixture.label, 'docs({ noGitPlus: true })') + ) + tt.end() + }) + t.test('hostinfo.ssh', function (tt) { + var expected = function (url, hasBranch) { + return (hasBranch) + ? url + '#' + params.branch + : url + } + tt.is( + hostinfo.ssh(), + expected('git@gitlab.com:some-owner/some-repo.git', fixture.hasBranch), + showLabel(fixture.label, 'ssh') + ) + tt.end() + }) + t.test('hostinfo.sshurl', function (tt) { + var expected = function (url, hasBranch) { + return (hasBranch) + ? url + '#' + params.branch + : url + } + tt.is( + hostinfo.sshurl(), + expected('git+ssh://git@gitlab.com/some-owner/some-repo.git', fixture.hasBranch), + showLabel(fixture.label, 'sshurl') + ) + tt.end() + }) + t.test('hostinfo.shortcut', function (tt) { + var expected = function (url, hasBranch) { + return (hasBranch) + ? url + '#' + params.branch + : url + } + tt.is( + hostinfo.shortcut(), + expected('gitlab:some-owner/some-repo', fixture.hasBranch), + showLabel(fixture.label, 'shortcut') + ) + tt.end() + }) + t.test('hostinfo.file', function (tt) { + var expected = function (url, hasBranch) { + return (hasBranch) + ? url.replace(/master/gi, params.branch) + : url + } + tt.is( + hostinfo.file(), + expected('https://gitlab.com/some-owner/some-repo/raw/master/', fixture.hasBranch), + showLabel(fixture.label, 'file') + ) + tt.is( + hostinfo.file('C'), + expected('https://gitlab.com/some-owner/some-repo/raw/master/C', fixture.hasBranch), + showLabel(fixture.label, "file('C')") + ) + tt.is( + hostinfo.file('C/D'), + expected('https://gitlab.com/some-owner/some-repo/raw/master/C/D', fixture.hasBranch), + showLabel(fixture.label, "file('C/D')") + ) + tt.end() + }) + t.test('hostinfo.tarball', function (tt) { + var expected = function (url, hasBranch) { + return (hasBranch) + ? url.replace(/master/gi, params.branch) + : url + } + tt.is( + hostinfo.tarball(), + expected('https://gitlab.com/some-owner/some-repo/repository/archive.tar.gz?ref=master', fixture.hasBranch), + showLabel(fixture.label, 'tarball') + ) + tt.is( + hostinfo.tarball({ noCommittish: true }), + expected('https://gitlab.com/some-owner/some-repo/repository/archive.tar.gz?ref=master', fixture.hasBranch), + showLabel(fixture.label, 'tarball({ noCommittish: true })') + ) + tt.end() + }) } +} +test('fromUrl(gitlab url)', function (t) { + var fixtures = require('./fixtures') + var gitlabFixtures = require('./fixtures/gitlab') + var collectedFixtures = [].concat(fixtures, gitlabFixtures) + + t.test('domain: gitlab.com', function (tt) { + var params = { + domain: 'gitlab.com', + shortname: 'gitlab', + label: 'gitlab', + owner: 'some-owner', + project: 'some-repo', + branch: 'feature-branch' + } + testFixtures(tt, params, collectedFixtures) + tt.end() + }) + + t.test('domain: www.gitlab.com', function (tt) { + var params = { + domain: 'www.gitlab.com', + shortname: 'gitlab', + label: 'gitlab', + owner: 'some-owner', + project: 'some-repo', + branch: 'feature-branch' + } + testFixtures(tt, params, collectedFixtures) + tt.end() + }) + + t.test('subgroups', function (tt) { + var groupFixtures = require('./fixtures/gitlab-subgroups') + + var params = { + domain: 'gitlab.com', + shortname: 'gitlab', + label: 'gitlab', + owner: 'some-owner', + project: 'some-repo', + group: 'group/sub-group1', + branch: 'feature-branch' + } + for (var g = 0; g < groupFixtures.length; ++g) { + var fixture = groupFixtures[g] + var host = fixture.host(params) + var hostinfo = HostedGit.fromUrl(host) + + var expected = function (url, hasBranch) { + return (hasBranch) + ? url + '#' + params.branch + : url + } + tt.is( + hostinfo.https(), + expected('git+https://gitlab.com/some-owner/group/sub-group1/some-repo.git', fixture.hasBranch), + showLabel(fixture.label, 'https') + ) + tt.is( + hostinfo.https({ noCommittish: true }), + // INFO: not using `expected` because with `{noCommittish: true}` the output is always the same + 'git+https://gitlab.com/some-owner/group/sub-group1/some-repo.git', + showLabel(fixture.label, 'https({ noCommittish: true })') + ) + tt.is( + hostinfo.https({ noGitPlus: true }), + expected('https://gitlab.com/some-owner/group/sub-group1/some-repo.git', fixture.hasBranch), + showLabel(fixture.label, 'https({ noGitPlus: true })') + ) + } - require('./lib/standard-tests')(verify, 'gitlab.com', 'gitlab') - require('./lib/standard-tests')(verify, 'www.gitlab.com', 'gitlab') - - const subsShort = HostedGit.fromUrl('gitlab:adpt/starters/hello-node') - const subsFull = HostedGit.fromUrl('git+https://gitlab.com/adpt/starters/hello-node.git') - t.ok(subsShort) - t.equal(subsShort.https(), 'git+https://gitlab.com/adpt/starters/hello-node.git') - t.equal(subsShort.ssh(), 'git@gitlab.com:adpt/starters/hello-node.git') - t.ok(subsFull) - t.equal(subsFull.https(), 'git+https://gitlab.com/adpt/starters/hello-node.git') - t.equal(subsFull.ssh(), 'git@gitlab.com:adpt/starters/hello-node.git') - - t.is( - HostedGit.fromUrl('gitlab:group/sub group1/subgroup2/repo').https(), - 'git+https://gitlab.com/group/sub%20group1/subgroup2/repo.git', - 'subgroups are delimited with slashes and url encoded (shortcut -> https)' - ) + tt.is( + HostedGit.fromUrl('gitlab:group/sub group1/subgroup2/repo').https(), + 'git+https://gitlab.com/group/sub%20group1/subgroup2/repo.git', + 'subgroups are delimited with slashes and url encoded (shortcut -> https)' + ) + tt.end() + }) t.end() }) From 53364f9c1d793910bf3a5ca7e455e6d3c65b405d Mon Sep 17 00:00:00 2001 From: Michael Perrotte Date: Fri, 27 Sep 2019 18:28:31 -0400 Subject: [PATCH 02/10] test: added refactered tests for gists --- test/fixtures/gist.js | 60 +++++++++ test/gist.js | 275 ++++++++++++++++++++++++++++++++++++------ 2 files changed, 299 insertions(+), 36 deletions(-) create mode 100644 test/fixtures/gist.js diff --git a/test/fixtures/gist.js b/test/fixtures/gist.js new file mode 100644 index 0000000..866f54a --- /dev/null +++ b/test/fixtures/gist.js @@ -0,0 +1,60 @@ +'use strict' + +module.exports = [ + { + host: function (p) { return 'gist:' + p.owner + '/' + p.project }, + label: 'gist' + }, + { + host: function (p) { return 'git@' + p.domain + ':/' + p.project }, + label: 'git@:/' + }, + { + host: function (p) { return 'git@' + p.domain + ':/' + p.project + '.git' }, + label: 'git@:/.git' + }, + { + host: function (p) { return 'git@' + p.domain + ':' + p.project + '.git' }, + label: 'git@' + }, + { + host: function (p) { return 'git@' + p.domain + ':/' + p.project + '.git' }, + label: 'git@/' + }, + { + host: function (p) { return 'git://' + p.domain + '/' + p.project }, + label: 'git' + }, + { + host: function (p) { return 'git://' + p.domain + '/' + p.project + '.git' }, + label: 'git.git' + }, + { + host: function (p) { return 'git://' + p.domain + '/' + p.project + '#' + p.branch }, + label: 'git#branch', + hasBranch: true + }, + { + host: function (p) { return 'git://' + p.domain + '/' + p.project + '.git#' + p.branch }, + label: 'git.git#branch', + hasBranch: true + }, + { + host: function (p) { return 'git://' + p.domain + ':/' + p.project }, + label: 'git:/' + }, + { + host: function (p) { return 'git://' + p.domain + ':/' + p.project + '.git' }, + label: 'git:/.git' + }, + { + host: function (p) { return 'git://' + p.domain + ':/' + p.project + '#' + p.branch }, + label: 'git:/#branch', + hasBranch: true + }, + { + host: function (p) { return 'git://' + p.domain + ':/' + p.project + '.git#' + p.branch }, + label: 'git:/.git#branch', + hasBranch: true + } +] diff --git a/test/gist.js b/test/gist.js index a3bceed..27ff719 100644 --- a/test/gist.js +++ b/test/gist.js @@ -2,49 +2,252 @@ var HostedGit = require('../index') var test = require('tap').test -test('fromUrl(gist url)', function (t) { - var proj = new Array(33).join('2') - function verify (host, label, branch) { +var showLabel = function (label, fn) { return label + ' -> ' + fn } + +var testFixtures = function (t, params, fixtures) { + for (var i = 0; i < fixtures.length; ++i) { + var fixture = fixtures[i] + var host = fixture.host(params) var hostinfo = HostedGit.fromUrl(host) - var hash = branch ? '#' + branch : '' - t.ok(hostinfo, label) - if (!hostinfo) return - t.is(hostinfo.https(), 'git+https://gist.github.com/' + proj + '.git' + hash, label + ' -> https') - t.is(hostinfo.git(), 'git://gist.github.com/' + proj + '.git' + hash, label + ' -> git') - t.is(hostinfo.browse(), 'https://gist.github.com/' + proj + (branch ? '/' + branch : ''), label + ' -> browse') - t.is(hostinfo.browse('C'), 'https://gist.github.com/' + proj + (branch ? '/' + branch : '') + '#file-c', label + ' -> browse(path)') - t.is(hostinfo.browse('C/D'), 'https://gist.github.com/' + proj + (branch ? '/' + branch : '') + '#file-cd', label + ' -> browse(path)') - t.is(hostinfo.browse('C', 'A'), 'https://gist.github.com/' + proj + (branch ? '/' + branch : '') + '#file-c', label + ' -> browse(path, fragment)') - t.is(hostinfo.browse('C/D', 'A'), 'https://gist.github.com/' + proj + (branch ? '/' + branch : '') + '#file-cd', label + ' -> browse(path)') - t.is(hostinfo.bugs(), 'https://gist.github.com/' + proj, label + ' -> bugs') - t.is(hostinfo.docs(), 'https://gist.github.com/' + proj + (branch ? '/' + branch : ''), label + ' -> docs') - t.is(hostinfo.ssh(), 'git@gist.github.com:/' + proj + '.git' + hash, label + ' -> ssh') - t.is(hostinfo.sshurl(), 'git+ssh://git@gist.github.com/' + proj + '.git' + hash, label + ' -> sshurl') - t.is(hostinfo.shortcut(), 'gist:' + proj + hash, label + ' -> shortcut') + + // INFO: from Url should return `undefined` from fixture input + if (fixture.isUndefined) { + t.test('input results in undefined', function (tt) { + tt.is(hostinfo, undefined) + tt.end() + }) + break + } + + t.test('hostinfo.https', function (tt) { + var expected = function (url, hasBranch) { + return (hasBranch) + ? url + '#' + params.branch + : url + } + tt.is( + hostinfo.https(), + expected('git+https://gist.github.com/a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2.git', fixture.hasBranch), + showLabel(fixture.label, 'https') + ) + tt.is( + hostinfo.https({ noCommittish: true }), + // INFO: not using `expected` because with `{noCommittish: true}` the output is always the same + 'git+https://gist.github.com/a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2.git', + showLabel(fixture.label, 'https({ noCommittish: true })') + ) + tt.is( + hostinfo.https({ noGitPlus: true }), + expected('https://gist.github.com/a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2.git', fixture.hasBranch), + showLabel(fixture.label, 'https({ noGitPlus: true })') + ) + tt.end() + }) + t.test('hostinfo.git', function (tt) { + var expected = function (url, hasBranch) { + return (hasBranch) + ? url + '#' + params.branch + : url + } + tt.is( + hostinfo.git(), + expected('git://gist.github.com/a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2.git', fixture.hasBranch), + showLabel(fixture.label, 'git') + ) + tt.is( + hostinfo.git({ noCommittish: true }), + // INFO: not using `expected` because with `{noCommittish: true}` the output is always the same + 'git://gist.github.com/a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2.git', + showLabel(fixture.label, 'git({ noCommittish: true })') + ) + tt.is( + hostinfo.git({ noGitPlus: true }), + expected('git://gist.github.com/a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2.git', fixture.hasBranch), + showLabel(fixture.label, 'git({ noGitPlus: true })') + ) + tt.end() + }) + t.test('hostinfo.browse', function (tt) { + var expected = function (url, hasBranch) { + return (hasBranch) + ? url + '/' + params.branch + : url + } + tt.is( + hostinfo.browse(), + expected('https://gist.github.com/a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2', fixture.hasBranch), + showLabel(fixture.label, 'browse') + ) + tt.is( + hostinfo.browse('C'), + expected('https://gist.github.com/a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2', fixture.hasBranch) + '#file-c', + showLabel(fixture.label, "browse('C')") + ) + tt.is( + hostinfo.browse('C/D'), + expected('https://gist.github.com/a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2', fixture.hasBranch) + '#file-cd', + showLabel(fixture.label, "browse('C/D')") + ) + tt.is( + hostinfo.browse('C', 'A'), + expected('https://gist.github.com/a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2', fixture.hasBranch) + '#file-c', + showLabel(fixture.label, "browse('C', 'A')") + ) + tt.is( + hostinfo.browse('C/D', 'A'), + expected('https://gist.github.com/a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2', fixture.hasBranch) + '#file-cd', + showLabel(fixture.label, "browse('C/D', 'A')") + ) + tt.end() + }) + t.test('hostinfo.bugs', function (tt) { + tt.is( + hostinfo.bugs(), + 'https://gist.github.com/a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2', + showLabel(fixture.label, 'bugs') + ) + tt.end() + }) + t.test('hostinfo.docs', function (tt) { + var expected = function (url, hasBranch) { + return (hasBranch) + ? url + '/' + params.branch + : url + } + tt.is( + hostinfo.docs(), + expected('https://gist.github.com/a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2', fixture.hasBranch), + showLabel(fixture.label, 'docs') + ) + tt.end() + }) + t.test('hostinfo.ssh', function (tt) { + var expected = function (url, hasBranch) { + return (hasBranch) + ? url + '#' + params.branch + : url + } + tt.is( + hostinfo.ssh(), + expected('git@gist.github.com:/a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2.git', fixture.hasBranch), + showLabel(fixture.label, 'ssh') + ) + tt.end() + }) + t.test('hostinfo.sshurl', function (tt) { + var expected = function (url, hasBranch) { + return (hasBranch) + ? url + '#' + params.branch + : url + } + tt.is( + hostinfo.sshurl(), + expected('git+ssh://git@gist.github.com/a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2.git', fixture.hasBranch), + showLabel(fixture.label, 'sshurl') + ) + tt.end() + }) + t.test('hostinfo.shortcut', function (tt) { + var expected = function (url, hasBranch) { + return (hasBranch) + ? url + '#' + params.branch + : url + } + tt.is( + hostinfo.shortcut(), + expected('gist:a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2', fixture.hasBranch), + showLabel(fixture.label, 'shortcut') + ) + tt.end() + }) if (hostinfo.user) { - t.is(hostinfo.file(''), 'https://gist.githubusercontent.com/111/' + proj + '/raw/' + (branch ? branch + '/' : ''), label + ' -> file') - t.is(hostinfo.file('C'), 'https://gist.githubusercontent.com/111/' + proj + '/raw/' + (branch ? branch + '/' : '') + 'C', label + ' -> file') - t.is(hostinfo.file('C/D'), 'https://gist.githubusercontent.com/111/' + proj + '/raw/' + (branch ? branch + '/' : '') + 'C/D', label + ' -> file') - t.is(hostinfo.tarball(), 'https://codeload.github.com/gist/' + proj + '/tar.gz/' + (branch || 'master'), label + ' -> tarball') - t.is(hostinfo.tarball({ noCommittish: true }), 'https://codeload.github.com/gist/' + proj + '/tar.gz/' + (branch || 'master'), label + ' -> tarball') + t.test('hostinfo.file', function (tt) { + var expected = function (url, hasBranch) { + return (hasBranch) + ? url + params.branch + '/' + : url + } + tt.is( + hostinfo.file(), + expected('https://gist.githubusercontent.com/some-owner/a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2/raw/', fixture.hasBranch), + showLabel(fixture.label, 'file') + ) + tt.is( + hostinfo.file(''), + expected('https://gist.githubusercontent.com/some-owner/a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2/raw/', fixture.hasBranch), + showLabel(fixture.label, "file('')") + ) + tt.is( + hostinfo.file('C'), + expected('https://gist.githubusercontent.com/some-owner/a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2/raw/', fixture.hasBranch) + 'C', + showLabel(fixture.label, "file('C')") + ) + tt.is( + hostinfo.file('C/D'), + expected('https://gist.githubusercontent.com/some-owner/a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2/raw/', fixture.hasBranch) + 'C/D', + showLabel(fixture.label, "file('C/D')") + ) + tt.is( + hostinfo.file('C', 'A'), + expected('https://gist.githubusercontent.com/some-owner/a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2/raw/', fixture.hasBranch) + 'C', + showLabel(fixture.label, "file('C', 'A')") + ) + tt.end() + }) + t.test('hostinfo.tarball', function (tt) { + var expected = function (url, hasBranch) { + return (hasBranch) + ? url.replace(/master/gi, params.branch) + : url + } + tt.is( + hostinfo.tarball(), + expected('https://codeload.github.com/gist/a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2/tar.gz/master', fixture.hasBranch), + showLabel(fixture.label, 'tarball') + ) + tt.is( + hostinfo.tarball({ noCommittish: true }), + expected('https://codeload.github.com/gist/a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2/tar.gz/master', fixture.hasBranch), + showLabel(fixture.label, 'tarball({ noCommittish: true })') + ) + tt.end() + }) } - } - verify('git@gist.github.com:' + proj + '.git', 'git@') - var hostinfo = HostedGit.fromUrl('git@gist.github.com:/c2b12db30a49324325a3781302668408.git') - if (t.ok(hostinfo, 'git@hex')) { - t.is(hostinfo.https(), 'git+https://gist.github.com/c2b12db30a49324325a3781302668408.git', 'git@hex -> https') + t.test('hostinfo.toString', function (tt) { + var expected = function (url, hasBranch) { + return (hasBranch) + ? url + '#' + params.branch + : url + } + tt.is( + hostinfo.toString(), + expected('git+https://gist.github.com/a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2.git', fixture.hasBranch), + showLabel(fixture.label, 'toString') + ) + tt.end() + }) } - verify('git@gist.github.com:/' + proj + '.git', 'git@/') - verify('git://gist.github.com/' + proj, 'git') - verify('git://gist.github.com/' + proj + '.git', 'git.git') - verify('git://gist.github.com/' + proj + '#branch', 'git#branch', 'branch') - verify('git://gist.github.com/' + proj + '.git#branch', 'git.git#branch', 'branch') +} + +test('fromUrl(gist url)', function (t) { + var fixtures = require('./fixtures') + var gistFixtures = require('./fixtures/gist') + var collectedFixtures = [].concat(fixtures, gistFixtures) - require('./lib/standard-tests')(verify, 'gist.github.com', 'gist', proj) + t.test('main fixtures', function (tt) { + var params = { + domain: 'gist.github.com', + shortname: 'github', + label: 'github', + owner: 'some-owner', + project: new Array(17).join('a2'), + branch: 'feature-branch' + } - verify(HostedGit.fromUrl('gist:111/' + proj).toString(), 'round-tripped shortcut') - verify('gist:' + proj, 'shortened shortcut') + testFixtures(tt, params, collectedFixtures) + tt.end() + }) t.end() }) From ffe056fbad08177bf9299176e5ef6d2bcd4a18a8 Mon Sep 17 00:00:00 2001 From: Michael Perrotte Date: Fri, 27 Sep 2019 18:29:46 -0400 Subject: [PATCH 03/10] fix: updated pathmatch for gitlab --- git-host-info.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-host-info.js b/git-host-info.js index d81be20..4dec801 100644 --- a/git-host-info.js +++ b/git-host-info.js @@ -25,7 +25,7 @@ var gitHosts = module.exports = { 'bugstemplate': 'https://{domain}/{user}/{project}/issues', 'httpstemplate': 'git+https://{auth@}{domain}/{user}/{projectPath}.git{#committish}', 'tarballtemplate': 'https://{domain}/{user}/{project}/repository/archive.tar.gz?ref={committish}', - 'pathmatch': /^[/]([^/]+)[/](.+?)(?:[.]git|[/])?$/ + 'pathmatch': /^[/]([^/]+)[/](?!.*\/-\/)(.+?)(?:[.]git|[/])?$/ }, gist: { 'protocols': [ 'git', 'git+ssh', 'git+https', 'ssh', 'https' ], From 921e6dd8c6d0479ef02b332bd95be6418cbc3973 Mon Sep 17 00:00:00 2001 From: Michael Perrotte Date: Fri, 27 Sep 2019 18:30:36 -0400 Subject: [PATCH 04/10] test: added basic test for ._fill() method --- test/basic.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/basic.js b/test/basic.js index 22c0bda..76a8d6f 100644 --- a/test/basic.js +++ b/test/basic.js @@ -4,6 +4,7 @@ var test = require('tap').test test('basic', function (t) { const h = HostedGit.fromUrl('github:user/project') + t.equal(h._fill(), undefined) t.is(h.constructor, HostedGit) t.is(h.constructor.name, 'GitHost') t.is(HostedGit.fromUrl('https://google.com'), undefined, 'null on failure') From 1fd9d66e228c6e9685d78dfdb2ad44ce2a25f8ae Mon Sep 17 00:00:00 2001 From: Michael Perrotte Date: Fri, 27 Sep 2019 21:27:08 -0400 Subject: [PATCH 05/10] test: added ignore; for 100% testing (this seems wonky) --- index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/index.js b/index.js index b64c826..fc959cb 100644 --- a/index.js +++ b/index.js @@ -64,6 +64,7 @@ function fromUrl (giturl, opts) { var pathmatch = gitHostInfo.pathmatch var matched = parsed.path.match(pathmatch) if (!matched) return + /* istanbul ignore else */ if (matched[1] !== null && matched[1] !== undefined) { user = decodeURIComponent(matched[1].replace(/^:/, '')) } From 8d24551b7e801056c8b13c2b9c387085b15e6794 Mon Sep 17 00:00:00 2001 From: Michael Perrotte Date: Fri, 27 Sep 2019 21:49:34 -0400 Subject: [PATCH 06/10] test: added refactered tests for bitbucket --- test/bitbucket-https-with-embedded-auth.js | 27 -- test/bitbucket.js | 306 +++++++++++++++++++-- test/fixtures/bitbucket.js | 99 +++++++ 3 files changed, 382 insertions(+), 50 deletions(-) delete mode 100644 test/bitbucket-https-with-embedded-auth.js create mode 100644 test/fixtures/bitbucket.js diff --git a/test/bitbucket-https-with-embedded-auth.js b/test/bitbucket-https-with-embedded-auth.js deleted file mode 100644 index a2feb2f..0000000 --- a/test/bitbucket-https-with-embedded-auth.js +++ /dev/null @@ -1,27 +0,0 @@ -'use strict' -var HostedGit = require('../index') -var test = require('tap').test - -test('Bitbucket HTTPS URLs with embedded auth', function (t) { - t.is( - HostedGit.fromUrl('https://user:pass@bitbucket.org/user/repo.git').toString(), - 'git+https://user:pass@bitbucket.org/user/repo.git', - 'credentials were included in URL' - ) - t.is( - HostedGit.fromUrl('https://user:pass@bitbucket.org/user/repo').toString(), - 'git+https://user:pass@bitbucket.org/user/repo.git', - 'credentials were included in URL' - ) - t.is( - HostedGit.fromUrl('git+https://user:pass@bitbucket.org/user/repo.git').toString(), - 'git+https://user:pass@bitbucket.org/user/repo.git', - 'credentials were included in URL' - ) - t.is( - HostedGit.fromUrl('git+https://user:pass@bitbucket.org/user/repo').toString(), - 'git+https://user:pass@bitbucket.org/user/repo.git', - 'credentials were included in URL' - ) - t.end() -}) diff --git a/test/bitbucket.js b/test/bitbucket.js index f79d1c3..b486a7a 100644 --- a/test/bitbucket.js +++ b/test/bitbucket.js @@ -2,32 +2,292 @@ var HostedGit = require('../index') var test = require('tap').test -test('fromUrl(bitbucket url)', function (t) { - function verify (host, label, branch) { +var showLabel = function (label, fn) { return label + ' -> ' + fn } + +var testFixtures = function (t, params, fixtures) { + for (var i = 0; i < fixtures.length; ++i) { + var fixture = fixtures[i] + + var host = fixture.host(params) var hostinfo = HostedGit.fromUrl(host) - var hash = branch ? '#' + branch : '' - t.ok(hostinfo, label) - if (!hostinfo) return - t.is(hostinfo.https(), 'git+https://bitbucket.org/111/222.git' + hash, label + ' -> https') - t.is(hostinfo.browse(), 'https://bitbucket.org/111/222' + (branch ? '/src/' + branch : ''), label + ' -> browse') - t.is(hostinfo.browse(''), 'https://bitbucket.org/111/222/src/' + (branch || 'master') + '/', label + ' -> browse(path)') - t.is(hostinfo.browse('C'), 'https://bitbucket.org/111/222/src/' + (branch || 'master') + '/C', label + ' -> browse(path)') - t.is(hostinfo.browse('C/D'), 'https://bitbucket.org/111/222/src/' + (branch || 'master') + '/C/D', label + ' -> browse(path)') - t.is(hostinfo.browse('C', 'A'), 'https://bitbucket.org/111/222/src/' + (branch || 'master') + '/C#a', label + ' -> browse(path, fragment)') - t.is(hostinfo.browse('C/D', 'A'), 'https://bitbucket.org/111/222/src/' + (branch || 'master') + '/C/D#a', label + ' -> browse(path, fragment)') - t.is(hostinfo.docs(), 'https://bitbucket.org/111/222' + (branch ? '/src/' + branch : '') + '#readme', label + ' -> docs') - t.is(hostinfo.ssh(), 'git@bitbucket.org:111/222.git' + hash, label + ' -> ssh') - t.is(hostinfo.sshurl(), 'git+ssh://git@bitbucket.org/111/222.git' + hash, label + ' -> sshurl') - t.is(hostinfo.shortcut(), 'bitbucket:111/222' + hash, label + ' -> shortcut') - t.is(hostinfo.file(''), 'https://bitbucket.org/111/222/raw/' + (branch || 'master') + '/', label + ' -> file') - t.is(hostinfo.file('C'), 'https://bitbucket.org/111/222/raw/' + (branch || 'master') + '/C', label + ' -> file') - t.is(hostinfo.file('C/D'), 'https://bitbucket.org/111/222/raw/' + (branch || 'master') + '/C/D', label + ' -> file') - t.is(hostinfo.tarball(), 'https://bitbucket.org/111/222/get/' + (branch || 'master') + '.tar.gz', label + ' -> tarball') - t.is(hostinfo.tarball({ noCommittish: true }), 'https://bitbucket.org/111/222/get/' + (branch || 'master') + '.tar.gz', label + ' -> tarball') + + // INFO: fromUrl should return `undefined` from fixture input + if (fixture.isUndefined) { + t.test('input results in undefined', function (tt) { + tt.is(hostinfo, undefined) + tt.end() + }) + break + } + + t.test('hostinfo.https', function (tt) { + var expected = function (url, hasBranch) { + return (hasBranch) + ? url + '#' + params.branch + : url + } + tt.is( + hostinfo.https(), + expected('git+https://bitbucket.org/some-owner/some-repo.git', fixture.hasBranch, fixture.hasGroup), + showLabel(fixture.label, 'https') + ) + // INFO: not using `expected` because with `{noCommittish: true}` the output is always the same + tt.is( + hostinfo.https({ noCommittish: true }), + 'git+https://bitbucket.org/some-owner/some-repo.git', + showLabel(fixture.label, 'https({ noCommittish: true })') + ) + tt.is( + hostinfo.https({ noGitPlus: true }), + expected('https://bitbucket.org/some-owner/some-repo.git', fixture.hasBranch), + showLabel(fixture.label, 'https({ noGitPlus: true })') + ) + tt.end() + }) + t.test('hostinfo.browse', function (tt) { + var expected = function (url, hasBranch) { + if (hasBranch) { + if (url.indexOf('master') === -1) { + return url + '/src/' + params.branch + } else { + return url.replace(/master/gi, params.branch) + } + } + return url + } + tt.is( + hostinfo.browse(), + expected('https://bitbucket.org/some-owner/some-repo', fixture.hasBranch), + showLabel(fixture.label, 'browse') + ) + tt.is( + hostinfo.browse(''), + expected('https://bitbucket.org/some-owner/some-repo/src/master/', fixture.hasBranch), + showLabel(fixture.label, "browse('')") + ) + tt.is( + hostinfo.browse('C'), + expected('https://bitbucket.org/some-owner/some-repo/src/master/C', fixture.hasBranch), + showLabel(fixture.label, "browse('C')") + ) + tt.is( + hostinfo.browse('C/D'), + expected('https://bitbucket.org/some-owner/some-repo/src/master/C/D', fixture.hasBranch), + showLabel(fixture.label, "browse('C/D')") + ) + tt.is( + hostinfo.browse('C', 'A'), + expected('https://bitbucket.org/some-owner/some-repo/src/master/C#a', fixture.hasBranch), + showLabel(fixture.label, "browse('C', 'A')") + ) + tt.is( + hostinfo.browse('C/D', 'A'), + expected('https://bitbucket.org/some-owner/some-repo/src/master/C/D#a', fixture.hasBranch), + showLabel(fixture.label, "browse('C/D', 'A')") + ) + tt.end() + }) + t.test('hostinfo.docs', function (tt) { + var expected = function (url, hasBranch) { + if (hasBranch) { + var splitUrl = url.split('#') + return splitUrl[0] + '/src/' + params.branch + '#' + splitUrl[1] + } + return url + } + tt.is( + hostinfo.docs(), + expected('https://bitbucket.org/some-owner/some-repo#readme', fixture.hasBranch), + showLabel(fixture.label, 'docs') + ) + tt.is( + hostinfo.docs({ noCommittish: true }), + // INFO: not using `expected` because with `{noCommittish: true}` the output is always the same + 'https://bitbucket.org/some-owner/some-repo#readme', + showLabel(fixture.label, 'docs({ noCommittish: true })') + ) + tt.is( + hostinfo.docs({ noGitPlus: true }), + expected('https://bitbucket.org/some-owner/some-repo#readme', fixture.hasBranch), + showLabel(fixture.label, 'docs({ noGitPlus: true })') + ) + tt.end() + }) + t.test('hostinfo.ssh', function (tt) { + var expected = function (url, hasBranch) { + return (hasBranch) + ? url + '#' + params.branch + : url + } + tt.is( + hostinfo.ssh(), + expected('git@bitbucket.org:some-owner/some-repo.git', fixture.hasBranch), + showLabel(fixture.label, 'ssh') + ) + tt.is( + hostinfo.ssh({ noCommittish: true }), + // INFO: not using `expected` because with `{noCommittish: true}` the output is always the same + 'git@bitbucket.org:some-owner/some-repo.git', + showLabel(fixture.label, 'ssh({ noCommittish: true })') + ) + tt.is( + hostinfo.ssh({ noGitPlus: true }), + expected('git@bitbucket.org:some-owner/some-repo.git', fixture.hasBranch), + showLabel(fixture.label, 'ssh({ noGitPlus: true })') + ) + tt.end() + }) + t.test('hostinfo.sshurl', function (tt) { + var expected = function (url, hasBranch) { + return (hasBranch) + ? url + '#' + params.branch + : url + } + tt.is( + hostinfo.sshurl(), + expected('git+ssh://git@bitbucket.org/some-owner/some-repo.git', fixture.hasBranch), + showLabel(fixture.label, 'sshurl') + ) + tt.is( + hostinfo.sshurl({ noCommittish: true }), + // INFO: not using `expected` because with `{noCommittish: true}` the output is always the same + 'git+ssh://git@bitbucket.org/some-owner/some-repo.git', + showLabel(fixture.label, 'sshurl({ noCommittish: true })') + ) + tt.is( + hostinfo.sshurl({ noGitPlus: true }), + expected('ssh://git@bitbucket.org/some-owner/some-repo.git', fixture.hasBranch), + showLabel(fixture.label, 'sshurl({ noGitPlus: true })') + ) + tt.end() + }) + t.test('hostinfo.shortcut', function (tt) { + var expected = function (url, hasBranch) { + return (hasBranch) + ? url + '#' + params.branch + : url + } + tt.is( + hostinfo.shortcut(), + expected('bitbucket:some-owner/some-repo', fixture.hasBranch), + showLabel(fixture.label, 'shortcut') + ) + tt.is( + hostinfo.shortcut({ noCommittish: true }), + // INFO: not using `expected` because with `{noCommittish: true}` the output is always the same + 'bitbucket:some-owner/some-repo', + showLabel(fixture.label, 'shortcut({ noCommittish: true })') + ) + tt.is( + hostinfo.shortcut({ noGitPlus: true }), + expected('bitbucket:some-owner/some-repo', fixture.hasBranch), + showLabel(fixture.label, 'shortcut({ noGitPlus: true })') + ) + tt.end() + }) + t.test('hostinfo.file', function (tt) { + var expected = function (url, hasBranch) { + return (hasBranch) + ? url.replace(/master/gi, params.branch) + : url + } + tt.is( + hostinfo.file(), + expected('https://bitbucket.org/some-owner/some-repo/raw/master/', fixture.hasBranch), + showLabel(fixture.label, 'file') + ) + tt.is( + hostinfo.file('C'), + expected('https://bitbucket.org/some-owner/some-repo/raw/master/C', fixture.hasBranch), + showLabel(fixture.label, "file('C')") + ) + tt.is( + hostinfo.file('C/D'), + expected('https://bitbucket.org/some-owner/some-repo/raw/master/C/D', fixture.hasBranch), + showLabel(fixture.label, "file('C/D')") + ) + tt.end() + }) + t.test('hostinfo.tarball', function (tt) { + var expected = function (url, hasBranch) { + return (hasBranch) + ? url.replace(/master/gi, params.branch) + : url + } + tt.is( + hostinfo.tarball(), + expected('https://bitbucket.org/some-owner/some-repo/get/master.tar.gz', fixture.hasBranch), + showLabel(fixture.label, 'tarball') + ) + tt.is( + hostinfo.tarball({ noCommittish: true }), + expected('https://bitbucket.org/some-owner/some-repo/get/master.tar.gz', fixture.hasBranch), + showLabel(fixture.label, 'tarball({ noCommittish: true })') + ) + tt.is( + hostinfo.tarball({ noGitPlus: true }), + expected('https://bitbucket.org/some-owner/some-repo/get/master.tar.gz', fixture.hasBranch), + showLabel(fixture.label, 'tarball({ noGitPlus: true })') + ) + tt.end() + }) } +} + +test('fromUrl(bitbucket url)', function (t) { + var fixtures = require('./fixtures/bitbucket') + // var gitlabFixtures = require('./fixtures/bitbucket') + // var collectedFixtures = [].concat(fixtures, gitlabFixtures) + + t.test('domain: bitbucket.org', function (tt) { + var params = { + domain: 'bitbucket.org', + shortname: 'bitbucket', + label: 'bitbucket', + owner: 'some-owner', + project: 'some-repo', + branch: 'feature-branch' + } + testFixtures(tt, params, fixtures) + tt.end() + }) + + t.test('domain: www.bitbucket.org', function (tt) { + var params = { + domain: 'www.bitbucket.org', + shortname: 'bitbucket', + label: 'bitbucket', + owner: 'some-owner', + project: 'some-repo', + branch: 'feature-branch' + } + testFixtures(tt, params, fixtures) + tt.end() + }) - require('./lib/standard-tests')(verify, 'bitbucket.org', 'bitbucket') - require('./lib/standard-tests')(verify, 'www.bitbucket.org', 'bitbucket') + t.test('Bitbucket HTTPS URLs with embedded auth', function (tt) { + tt.is( + HostedGit.fromUrl('https://user:pass@bitbucket.org/user/repo.git').toString(), + 'git+https://user:pass@bitbucket.org/user/repo.git', + 'credentials were included in URL' + ) + tt.is( + HostedGit.fromUrl('https://user:pass@bitbucket.org/user/repo').toString(), + 'git+https://user:pass@bitbucket.org/user/repo.git', + 'credentials were included in URL' + ) + tt.is( + HostedGit.fromUrl('git+https://user:pass@bitbucket.org/user/repo.git').toString(), + 'git+https://user:pass@bitbucket.org/user/repo.git', + 'credentials were included in URL' + ) + tt.is( + HostedGit.fromUrl('git+https://user:pass@bitbucket.org/user/repo').toString(), + 'git+https://user:pass@bitbucket.org/user/repo.git', + 'credentials were included in URL' + ) + tt.end() + }) t.end() }) diff --git a/test/fixtures/bitbucket.js b/test/fixtures/bitbucket.js new file mode 100644 index 0000000..33053da --- /dev/null +++ b/test/fixtures/bitbucket.js @@ -0,0 +1,99 @@ +'use strcit' + +module.exports = [ + { + host: function (p) { return 'https://' + p.domain + '/' + p.owner + '/' + p.project }, + label: 'https' + }, + { + host: function (p) { return 'https://' + p.domain + '/' + p.owner + '/' + p.project + '.git' }, + label: 'https.git' + }, + { + host: function (p) { return 'https://' + p.domain + '/' + p.owner + '/' + p.project + '#' + p.branch }, + label: 'https#branch', + hasBranch: true + }, + { + host: function (p) { return 'https://' + p.domain + '/' + p.owner + '/' + p.project + '.git#' + p.branch }, + label: 'https.git#branch', + hasBranch: true + }, + { + host: function (p) { return 'https://' + p.domain + '/' + p.owner + '/' + p.project + '/-/' + 'archive' + '/3.3.2' + '/ws-3.3.2.tar.gz' }, + label: 'https.tar', + isUndefined: true + }, + { + host: function (p) { return 'git+https://' + p.domain + '/' + p.owner + '/' + p.project }, + label: 'git+https' + }, + { + host: function (p) { return 'git+https://' + p.domain + '/' + p.owner + '/' + p.project + '.git' }, + label: 'git+https.git' + }, + { + host: function (p) { return 'git+https://' + p.domain + '/' + p.owner + '/' + p.project + '#' + p.branch }, + label: 'git+https#branch', + hasBranch: true + }, + { + host: function (p) { return 'git+https://' + p.domain + '/' + p.owner + '/' + p.project + '.git#' + p.branch }, + label: 'git+https.git#branch', + hasBranch: true + }, + { + host: function (p) { return 'git@' + p.domain + ':' + p.owner + '/' + p.project }, + label: 'ssh' + }, + { + host: function (p) { return 'git@' + p.domain + ':' + p.owner + '/' + p.project + '.git' }, + label: 'ssh.git' + }, + { + host: function (p) { return 'git@' + p.domain + ':' + p.owner + '/' + p.project + '#' + p.branch }, + label: 'ssh#branch', + hasBranch: true + }, + { + host: function (p) { return 'git@' + p.domain + ':' + p.owner + '/' + p.project + '.git#' + p.branch }, + label: 'ssh.git#branch', + hasBranch: true + }, + { + host: function (p) { return 'git+ssh://git@' + p.domain + '/' + p.owner + '/' + p.project }, + label: 'ssh-url' + }, + { + host: function (p) { return 'git+ssh://git@' + p.domain + '/' + p.owner + '/' + p.project + '.git' }, + label: 'ssh-url.git' + }, + { + host: function (p) { return 'git+ssh://git@' + p.domain + '/' + p.owner + '/' + p.project + '#' + p.branch }, + label: 'ssh-url#branch', + hasBranch: true + }, + { + host: function (p) { return 'git+ssh://git@' + p.domain + '/' + p.owner + '/' + p.project + '.git#' + p.branch }, + label: 'ssh-url.git#branch', + hasBranch: true + }, + { + host: function (p) { return p.shortname + ':' + p.owner + '/' + p.project }, + label: 'shortcut' + }, + { + host: function (p) { return p.shortname + ':' + p.owner + '/' + p.project + '.git' }, + label: 'shortcut.git' + }, + { + host: function (p) { return p.shortname + ':' + p.owner + '/' + p.project + '#' + p.branch }, + label: 'shortcut#branch', + hasBranch: true + }, + { + host: function (p) { return p.shortname + ':' + p.owner + '/' + p.project + '.git#' + p.branch }, + label: 'shortcut.git#branch', + hasBranch: true + } +] From ba44d9ff34f1128678662cd44618e7c4c25658cd Mon Sep 17 00:00:00 2001 From: Michael Perrotte Date: Fri, 27 Sep 2019 21:50:30 -0400 Subject: [PATCH 07/10] test: moved all github url tests together --- test/github.js | 41 +++++++++++++++++++++++++++++++ test/https-with-inline-auth.js | 44 ---------------------------------- 2 files changed, 41 insertions(+), 44 deletions(-) delete mode 100644 test/https-with-inline-auth.js diff --git a/test/github.js b/test/github.js index 146a203..9bcdd44 100644 --- a/test/github.js +++ b/test/github.js @@ -292,5 +292,46 @@ test('fromUrl(github url)', function (t) { t.equal(HostedGit.fromUrl('git+ssh://github.com/foo.git'), undefined) + t.test('HTTPS GitHub URL with embedded auth -- generally not a good idea', function (tt) { + function verify (host, label, branch) { + var hostinfo = HostedGit.fromUrl(host) + var hash = branch ? '#' + branch : '' + tt.ok(hostinfo, label) + if (!hostinfo) return + tt.is(hostinfo.https(), 'git+https://user:pass@github.com/111/222.git' + hash, label + ' -> https') + tt.is(hostinfo.git(), 'git://user:pass@github.com/111/222.git' + hash, label + ' -> git') + tt.is(hostinfo.browse(), 'https://github.com/111/222' + (branch ? '/tree/' + branch : ''), label + ' -> browse') + tt.is(hostinfo.browse('C'), 'https://github.com/111/222/tree/' + (branch || 'master') + '/C', label + ' -> browse(path)') + tt.is(hostinfo.browse('C/D'), 'https://github.com/111/222/tree/' + (branch || 'master') + '/C/D', label + ' -> browse(path)') + tt.is(hostinfo.browse('C', 'A'), 'https://github.com/111/222/tree/' + (branch || 'master') + '/C#a', label + ' -> browse(path, fragment)') + tt.is(hostinfo.browse('C/D', 'A'), 'https://github.com/111/222/tree/' + (branch || 'master') + '/C/D#a', label + ' -> browse(path, fragment)') + tt.is(hostinfo.bugs(), 'https://github.com/111/222/issues', label + ' -> bugs') + tt.is(hostinfo.docs(), 'https://github.com/111/222' + (branch ? '/tree/' + branch : '') + '#readme', label + ' -> docs') + tt.is(hostinfo.ssh(), 'git@github.com:111/222.git' + hash, label + ' -> ssh') + tt.is(hostinfo.sshurl(), 'git+ssh://git@github.com/111/222.git' + hash, label + ' -> sshurl') + tt.is(hostinfo.shortcut(), 'github:111/222' + hash, label + ' -> shortcut') + tt.is(hostinfo.file('C'), 'https://user:pass@raw.githubusercontent.com/111/222/' + (branch || 'master') + '/C', label + ' -> file') + tt.is(hostinfo.file('C/D'), 'https://user:pass@raw.githubusercontent.com/111/222/' + (branch || 'master') + '/C/D', label + ' -> file') + } + + // insecure protocols + verify('git://user:pass@github.com/111/222', 'git') + verify('git://user:pass@github.com/111/222.git', 'git.git') + verify('git://user:pass@github.com/111/222#branch', 'git#branch', 'branch') + verify('git://user:pass@github.com/111/222.git#branch', 'git.git#branch', 'branch') + + verify('https://user:pass@github.com/111/222', 'https') + verify('https://user:pass@github.com/111/222.git', 'https.git') + verify('https://user:pass@github.com/111/222#branch', 'https#branch', 'branch') + verify('https://user:pass@github.com/111/222.git#branch', 'https.git#branch', 'branch') + + verify('http://user:pass@github.com/111/222', 'http') + verify('http://user:pass@github.com/111/222.git', 'http.git') + verify('http://user:pass@github.com/111/222#branch', 'http#branch', 'branch') + verify('http://user:pass@github.com/111/222.git#branch', 'http.git#branch', 'branch') + + tt.end() + }) + t.end() }) diff --git a/test/https-with-inline-auth.js b/test/https-with-inline-auth.js deleted file mode 100644 index b14cb29..0000000 --- a/test/https-with-inline-auth.js +++ /dev/null @@ -1,44 +0,0 @@ -'use strict' -var HostedGit = require('../index') -var test = require('tap').test - -test('HTTPS GitHub URL with embedded auth -- generally not a good idea', function (t) { - function verify (host, label, branch) { - var hostinfo = HostedGit.fromUrl(host) - var hash = branch ? '#' + branch : '' - t.ok(hostinfo, label) - if (!hostinfo) return - t.is(hostinfo.https(), 'git+https://user:pass@github.com/111/222.git' + hash, label + ' -> https') - t.is(hostinfo.git(), 'git://user:pass@github.com/111/222.git' + hash, label + ' -> git') - t.is(hostinfo.browse(), 'https://github.com/111/222' + (branch ? '/tree/' + branch : ''), label + ' -> browse') - t.is(hostinfo.browse('C'), 'https://github.com/111/222/tree/' + (branch || 'master') + '/C', label + ' -> browse(path)') - t.is(hostinfo.browse('C/D'), 'https://github.com/111/222/tree/' + (branch || 'master') + '/C/D', label + ' -> browse(path)') - t.is(hostinfo.browse('C', 'A'), 'https://github.com/111/222/tree/' + (branch || 'master') + '/C#a', label + ' -> browse(path, fragment)') - t.is(hostinfo.browse('C/D', 'A'), 'https://github.com/111/222/tree/' + (branch || 'master') + '/C/D#a', label + ' -> browse(path, fragment)') - t.is(hostinfo.bugs(), 'https://github.com/111/222/issues', label + ' -> bugs') - t.is(hostinfo.docs(), 'https://github.com/111/222' + (branch ? '/tree/' + branch : '') + '#readme', label + ' -> docs') - t.is(hostinfo.ssh(), 'git@github.com:111/222.git' + hash, label + ' -> ssh') - t.is(hostinfo.sshurl(), 'git+ssh://git@github.com/111/222.git' + hash, label + ' -> sshurl') - t.is(hostinfo.shortcut(), 'github:111/222' + hash, label + ' -> shortcut') - t.is(hostinfo.file('C'), 'https://user:pass@raw.githubusercontent.com/111/222/' + (branch || 'master') + '/C', label + ' -> file') - t.is(hostinfo.file('C/D'), 'https://user:pass@raw.githubusercontent.com/111/222/' + (branch || 'master') + '/C/D', label + ' -> file') - } - - // insecure protocols - verify('git://user:pass@github.com/111/222', 'git') - verify('git://user:pass@github.com/111/222.git', 'git.git') - verify('git://user:pass@github.com/111/222#branch', 'git#branch', 'branch') - verify('git://user:pass@github.com/111/222.git#branch', 'git.git#branch', 'branch') - - verify('https://user:pass@github.com/111/222', 'https') - verify('https://user:pass@github.com/111/222.git', 'https.git') - verify('https://user:pass@github.com/111/222#branch', 'https#branch', 'branch') - verify('https://user:pass@github.com/111/222.git#branch', 'https.git#branch', 'branch') - - verify('http://user:pass@github.com/111/222', 'http') - verify('http://user:pass@github.com/111/222.git', 'http.git') - verify('http://user:pass@github.com/111/222#branch', 'http#branch', 'branch') - verify('http://user:pass@github.com/111/222.git#branch', 'http.git#branch', 'branch') - - t.end() -}) From 4eb69eb6b59c8d9680c0e9a4e451d6d51289b212 Mon Sep 17 00:00:00 2001 From: Michael Perrotte Date: Fri, 27 Sep 2019 21:50:46 -0400 Subject: [PATCH 08/10] test: removed unused testing structure --- test/lib/standard-tests.js | 28 ---------------------------- 1 file changed, 28 deletions(-) delete mode 100644 test/lib/standard-tests.js diff --git a/test/lib/standard-tests.js b/test/lib/standard-tests.js deleted file mode 100644 index cbd55f7..0000000 --- a/test/lib/standard-tests.js +++ /dev/null @@ -1,28 +0,0 @@ -'use strict' -module.exports = function (verify, domain, shortname, proj) { - proj = proj || '222' - verify('https://' + domain + '/111/' + proj, 'https') - verify('https://' + domain + '/111/' + proj + '.git', 'https.git') - verify('https://' + domain + '/111/' + proj + '#branch', 'https#branch', 'branch') - verify('https://' + domain + '/111/' + proj + '.git#branch', 'https.git#branch', 'branch') - - verify('git+https://' + domain + '/111/' + proj, 'git+https') - verify('git+https://' + domain + '/111/' + proj + '.git', 'git+https.git') - verify('git+https://' + domain + '/111/' + proj + '#branch', 'git+https#branch', 'branch') - verify('git+https://' + domain + '/111/' + proj + '.git#branch', 'git+https.git#branch', 'branch') - - verify('git@' + domain + ':111/' + proj, 'ssh') - verify('git@' + domain + ':111/' + proj + '.git', 'ssh.git') - verify('git@' + domain + ':111/' + proj + '#branch', 'ssh', 'branch') - verify('git@' + domain + ':111/' + proj + '.git#branch', 'ssh.git', 'branch') - - verify('git+ssh://git@' + domain + '/111/' + proj, 'ssh url') - verify('git+ssh://git@' + domain + '/111/' + proj + '.git', 'ssh url.git') - verify('git+ssh://git@' + domain + '/111/' + proj + '#branch', 'ssh url#branch', 'branch') - verify('git+ssh://git@' + domain + '/111/' + proj + '.git#branch', 'ssh url.git#branch', 'branch') - - verify(shortname + ':111/' + proj, 'shortcut') - verify(shortname + ':111/' + proj + '.git', 'shortcut.git') - verify(shortname + ':111/' + proj + '#branch', 'shortcut#branch', 'branch') - verify(shortname + ':111/' + proj + '.git#branch', 'shortcut.git#branch', 'branch') -} From 4e4ea0f0d7a112a47113db79dfa0338962780296 Mon Sep 17 00:00:00 2001 From: Michael Perrotte Date: Fri, 27 Sep 2019 21:52:34 -0400 Subject: [PATCH 09/10] test: added script to get coverage report --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 8f2945b..284da7b 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ "postrelease": "npm publish --tag=ancient-legacy-fixes && git push --follow-tags", "pretest": "standard", "release": "standard-version -s", + "test:coverage": "tap --coverage-report=html -J --100 --no-esm test/*.js", "test": "tap -J --100 --no-esm test/*.js" }, "devDependencies": { From 847bfd5b5e4cac978249b9e37f436fe94825bb35 Mon Sep 17 00:00:00 2001 From: claudiahdz Date: Thu, 3 Oct 2019 13:56:21 +0300 Subject: [PATCH 10/10] fix: updated pathmatch for gitlab --- git-host-info.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-host-info.js b/git-host-info.js index 4dec801..8147e33 100644 --- a/git-host-info.js +++ b/git-host-info.js @@ -25,7 +25,7 @@ var gitHosts = module.exports = { 'bugstemplate': 'https://{domain}/{user}/{project}/issues', 'httpstemplate': 'git+https://{auth@}{domain}/{user}/{projectPath}.git{#committish}', 'tarballtemplate': 'https://{domain}/{user}/{project}/repository/archive.tar.gz?ref={committish}', - 'pathmatch': /^[/]([^/]+)[/](?!.*\/-\/)(.+?)(?:[.]git|[/])?$/ + 'pathmatch': /^[/]([^/]+)[/]((?!.*(\/-\/|\/repository\/archive\.tar\.gz\?=.*|\/repository\/[^/]+\/archive.tar.gz$)).*?)(?:[.]git|[/])?$/ }, gist: { 'protocols': [ 'git', 'git+ssh', 'git+https', 'ssh', 'https' ],