1'use strict' 2var test = require('tap').test 3 4var npm = require('../../lib/npm.js') 5var common = require('../common-tap.js') 6var npa = require('npm-package-arg') 7 8var getResolved = null 9 10/** 11 * Note: This is here because `normalizeGitUrl` is usually called 12 * before getResolved is, and receives *that* URL. 13 */ 14function tryGetResolved (uri, treeish) { 15 return getResolved(npa(uri), uri, treeish) 16} 17 18test('setup', function (t) { 19 var opts = { 20 registry: common.registry, 21 loglevel: 'silent' 22 } 23 npm.load(opts, function (er) { 24 t.ifError(er, 'npm loaded without error') 25 getResolved = require('../../lib/cache/add-remote-git.js').getResolved 26 t.end() 27 }) 28}) 29 30test('add-remote-git#get-resolved git: passthru', function (t) { 31 verify('git:github.com/foo/repo') 32 verify('git:github.com/foo/repo.git') 33 verify('git://github.com/foo/repo#decadacefadabade') 34 verify('git://github.com/foo/repo.git#decadacefadabade') 35 36 function verify (uri) { 37 t.equal( 38 tryGetResolved(uri, 'decadacefadabade'), 39 'git://github.com/foo/repo.git#decadacefadabade', 40 uri + ' normalized to canonical form git://github.com/foo/repo.git#decadacefadabade' 41 ) 42 } 43 t.end() 44}) 45 46test('add-remote-git#get-resolved SSH', function (t) { 47 t.comment('tests for https://github.com/npm/npm/issues/7961') 48 verify('git+ssh://git@github.com:foo/repo') 49 verify('git+ssh://git@github.com:foo/repo#master') 50 verify('git+ssh://git@github.com/foo/repo#master') 51 verify('git+ssh://git@github.com/foo/repo#decadacefadabade') 52 53 function verify (uri) { 54 t.equal( 55 tryGetResolved(uri, 'decadacefadabade'), 56 'git+ssh://git@github.com/foo/repo.git#decadacefadabade', 57 uri + ' normalized to canonical form git+ssh://git@github.com/foo/repo.git#decadacefadabade' 58 ) 59 } 60 t.end() 61}) 62 63test('add-remote-git#get-resolved HTTPS', function (t) { 64 verify('https://github.com/foo/repo') 65 verify('https://github.com/foo/repo#master') 66 verify('git+https://github.com/foo/repo.git#master') 67 verify('git+https://github.com/foo/repo#decadacefadabade') 68 // DEPRECATED 69 // this is an invalid URL but we normalize it 70 // anyway. Users shouldn't use this in the future. See note 71 // below for how this affected non-hosted URLs. 72 // See https://github.com/npm/npm/issues/8881 73 verify('git+https://github.com:foo/repo.git#master') 74 75 function verify (uri) { 76 t.equal( 77 tryGetResolved(uri, 'decadacefadabade'), 78 'git+https://github.com/foo/repo.git#decadacefadabade', 79 uri + ' normalized to canonical form git+https://github.com/foo/repo.git#decadacefadabade' 80 ) 81 } 82 t.end() 83}) 84 85test('add-remote-git#get-resolved edge cases', function (t) { 86 t.equal( 87 tryGetResolved('git+ssh://user@bananaboat.com:galbi/blah.git', 'decadacefadabade'), 88 'git+ssh://user@bananaboat.com:galbi/blah.git#decadacefadabade', 89 'don\'t break non-hosted scp-style locations' 90 ) 91 /* 92 t.equal( 93 tryGetResolved('git+ssh://bananaboat:galbi/blah', 'decadacefadabade'), 94 'git+ssh://bananaboat:galbi/blah#decadacefadabade', 95 'don\'t break non-hosted scp-style locations' 96 ) 97 98 // DEPRECATED 99 // When we were normalizing all git URIs, git+https: was being 100 // automatically converted to ssh:. Some users were relying 101 // on this funky behavior, so after removing the aggressive 102 // normalization from non-hosted URIs, we brought this back. 103 // See https://github.com/npm/npm/issues/8881 104 t.equal( 105 tryGetResolved('git+https://bananaboat:galbi/blah', 'decadacefadabade'), 106 'git+https://bananaboat/galbi/blah#decadacefadabade', 107 'don\'t break non-hosted scp-style locations' 108 ) 109 110 t.equal( 111 tryGetResolved('git+ssh://git.bananaboat.net/foo', 'decadacefadabade'), 112 'git+ssh://git.bananaboat.net/foo#decadacefadabade', 113 'don\'t break non-hosted SSH URLs' 114 ) 115 116 t.equal( 117 tryGetResolved('git+ssh://git.bananaboat.net:/foo', 'decadacefadabade'), 118 'git+ssh://git.bananaboat.net:/foo#decadacefadabade', 119 'don\'t break non-hosted SSH URLs' 120 ) 121 122 t.equal( 123 tryGetResolved('git://gitbub.com/foo/bar.git', 'decadacefadabade'), 124 'git://gitbub.com/foo/bar.git#decadacefadabade', 125 'don\'t break non-hosted git: URLs' 126 ) 127*/ 128 t.end() 129}) 130