1 var parse = require('./');
2 var assert = require('better-assert');
4 describe('parse(url)', function(){
5 it('should support git://*', function(){
6 var url = 'git://github.com/jamesor/mongoose-versioner';
7 parse(url).should.equal('https://github.com/jamesor/mongoose-versioner');
10 it('should support git://*.git', function(){
11 var url = 'git://github.com/treygriffith/cellar.git';
12 parse(url).should.equal('https://github.com/treygriffith/cellar');
15 it('should support https://*', function(){
16 var url = 'https://github.com/Empeeric/i18n-node';
17 parse(url).should.equal('https://github.com/Empeeric/i18n-node');
20 it('should support https://*.git', function(){
21 var url = 'https://jpillora@github.com/banchee/tranquil.git';
22 parse(url).should.equal('https://github.com/banchee/tranquil');
25 it('should return undefined on failure', function(){
26 var url = 'git://github.com/justgord/.git';
27 assert(null == parse(url));
30 it('should parse git@github.com:bcoe/thumbd.git', function() {
31 var url = 'git@github.com:bcoe/thumbd.git';
32 parse(url).should.eql('https://github.com/bcoe/thumbd');
35 it('should parse git@github.com:bcoe/thumbd.git#2.7.0', function() {
36 var url = 'git@github.com:bcoe/thumbd.git#2.7.0';
37 parse(url).should.eql('https://github.com/bcoe/thumbd');
40 it('should parse git+https://github.com/bcoe/thumbd.git', function() {
41 var url = 'git+https://github.com/bcoe/thumbd.git';
42 parse(url).should.eql('https://github.com/bcoe/thumbd');
45 it('should parse git+ssh://github.com/bcoe/thumbd.git', function() {
46 var url = 'git+ssh://github.com/bcoe/thumbd.git';
47 parse(url).should.eql('https://github.com/bcoe/thumbd');
50 it('should parse https://EastCloud@github.com/EastCloud/node-websockets.git', function() {
51 var url = 'https://EastCloud@github.com/EastCloud/node-websockets.git';
52 parse(url).should.eql('https://github.com/EastCloud/node-websockets');
57 it('should parse git@gist urls', function() {
58 var url = 'git@gist.github.com:3135914.git';
59 parse(url).should.equal('https://gist.github.com/3135914')
62 it('should parse https://gist urls', function() {
63 var url = 'https://gist.github.com/3135914.git';
64 parse(url).should.equal('https://gist.github.com/3135914')
67 // Handle arbitrary GitHub Enterprise domains.
69 it('should parse parse extra GHE urls provided', function() {
70 var url = 'git://github.example.com/treygriffith/cellar.git';
72 url, {extraBaseUrls: ['github.example.com']}
73 ).should.equal('https://github.example.com/treygriffith/cellar');
76 it('should parse GHE urls with multiple subdomains', function() {
77 var url = 'git://github.internal.example.com/treygriffith/cellar.git';
79 url, {extraBaseUrls: ['github.internal.example.com']}
80 ).should.equal('https://github.internal.example.com/treygriffith/cellar');
84 describe('re', function() {
85 it('should expose GitHub url parsing regex', function() {
86 parse.re.source.should.equal(
87 /^(?:https?:\/\/|git:\/\/|git\+ssh:\/\/|git\+https:\/\/)?(?:[^@]+@)?(gist.github.com|github.com)[:\/]([^\/]+\/[^\/]+?|[0-9]+)$/.source