-
Notifications
You must be signed in to change notification settings - Fork 10
/
test.js
146 lines (126 loc) · 4.64 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
var assert = require('assert')
var parse = require('./')
describe('versionless', function () {
[
'component/emitter',
'https://github.com/component/emitter',
'git://github.com/component/emitter.git',
'https://github.com/repos/component/emitter/tarball',
'https://github.com/repos/component/emitter/zipball',
'https://codeload.github.com/component/emitter/legacy.zip',
'https://codeload.github.com/component/emitter/legacy.tar.gz',
].forEach(function (url) {
it(url, function () {
assert.deepEqual(['component', 'emitter', ''], parse(url))
})
})
it('works for www.github.com', function () {
var url = 'https://www.github.com/component/emitter'
var parsed = parse(url)
assert.deepEqual(['component', 'emitter', ''], parsed)
})
it('works for http://www.github.com', function () {
var url = 'http://www.github.com/component/emitter'
var parsed = parse(url)
assert.deepEqual(['component', 'emitter', ''], parsed)
})
})
describe('versioned', function () {
[
'component/emitter#1',
'component/emitter@1',
'component/emitter#"1"',
'component/emitter@"1"',
'git://github.com/component/emitter.git#1',
'https://github.com/repos/component/emitter/tarball/1',
'https://github.com/repos/component/emitter/zipball/1',
'https://codeload.github.com/component/emitter/legacy.zip/1',
'https://codeload.github.com/component/emitter/legacy.tar.gz/1',
'https://github.com/component/emitter/archive/1.tar.gz',
].forEach(function (url) {
it(url, function () {
assert.deepEqual(['component', 'emitter', '1'], parse(url))
})
})
})
describe('dotted user', function () {
[
'my.component/emitter',
'https://github.com/my.component/emitter',
'https://github.com/repos/my.component/emitter/tarball',
'https://codeload.github.com/my.component/emitter/legacy.zip',
].forEach(function (url) {
it(url, function () {
assert.deepEqual(['my.component', 'emitter', ''], parse(url))
})
})
})
describe('url parse', function () {
var builtinUrlParse = require('url').parse
it('handles https:// url', function () {
var url = 'https://foo.com/bar'
var parsed = builtinUrlParse(url)
assert.equal('foo.com', parsed.hostname)
})
it('does not handle emails', function () {
var url = '[email protected]/bar'
var parsed = builtinUrlParse(url)
assert.equal(null, parsed.hostname, JSON.stringify(parsed))
})
})
describe('gitlab urls', function () {
it('parses https gitlab url', function () {
var url = 'https://gitlab.mycompany.com/user/test1.git'
var parsed = parse(url)
assert.deepEqual(['user', 'test1', ''], parsed)
})
it('parses git gitlab url', function () {
var url = '[email protected]:user/test1.git'
var parsed = parse(url)
assert.deepEqual(['user', 'test1', ''], parsed)
})
it('parses git gitlab url with one subgroup', function () {
var url = '[email protected]:user/subgroup/test1.git'
var parsed = parse(url)
assert.deepEqual(['user/subgroup', 'test1', ''], parsed)
})
it('parses git gitlab url with two nested subgroups', function () {
var url = '[email protected]:user/subgroup1/subgroup2/test1.git'
var parsed = parse(url)
assert.deepEqual(['user/subgroup1/subgroup2', 'test1', ''], parsed)
})
it('parses git gitlab url with three nested subgroups', function () {
var url = '[email protected]:user/subgroup1/subgroup2/subgroup3/test1.git'
var parsed = parse(url)
assert.deepEqual(['user/subgroup1/subgroup2/subgroup3', 'test1', ''], parsed)
})
it('parses git hosted gitlab url with subgroups', function () {
var url = '[email protected]:user/subgroup1/subgroup2/subgroup3/test1.git'
var parsed = parse(url)
assert.deepEqual(['user/subgroup1/subgroup2/subgroup3', 'test1', ''], parsed)
})
it('cannot parse subgroups in non-gitlab URLs', function () {
var url = '[email protected]:user/subgroup1/subgroup2/subgroup3/test1.git'
var parsed = parse(url)
assert.equal(false, parsed)
})
})
describe('git @ syntax', function () {
it('works for git url', function () {
var url = '[email protected]:bahmutov/lazy-ass.git'
var parsed = parse(url)
assert.deepEqual(['bahmutov', 'lazy-ass', ''], parsed)
});
it('works for https:git url', function () {
var url = 'https:[email protected]:bahmutov/lazy-ass.git'
var parsed = parse(url)
assert.deepEqual(['bahmutov', 'lazy-ass', ''], parsed)
});
})
describe('github enterprise urls', function () {
it('parses https github enterprise url', function () {
var url = 'https://git.mycompany.com/user/test1.git'
var parsed = parse(url)
assert.deepEqual(['user', 'test1', ''], parsed)
})
})