-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathindex.spec.js
177 lines (160 loc) · 5.07 KB
/
index.spec.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
import {expect} from 'chai';
import {describe, it} from 'mocha';
import getPkgRepo from './index.js';
describe(`get-pkg-repo`, () => {
it(`should error if cannot get repository`, () => {
expect(() => getPkgRepo()).to.throw(
Error,
`No valid "repository" data found in package metadata. Please see https://docs.npmjs.com/files/package.json#repository for proper syntax.`);
expect(() => getPkgRepo({})).to.throw(
Error,
`No valid "repository" data found in package metadata. Please see https://docs.npmjs.com/files/package.json#repository for proper syntax.`);
expect(() => getPkgRepo({repository: {type: `git`}})).to.throw(
Error,
`No valid "repository" data found in package metadata. Please see https://docs.npmjs.com/files/package.json#repository for proper syntax.`);
});
it(`should parse github http when it's just a string`, () => {
const repository = getPkgRepo({repository: `http://github.com/a/b`});
expect(repository).to.contain({
domain: `github.com`,
type: `github`,
user: `a`,
project: `b`,
});
});
it(`should parse github http`, () => {
const repository = getPkgRepo({repository: {url: `http://github.com/a/b`}});
expect(repository).to.contain({
domain: `github.com`,
type: `github`,
user: `a`,
project: `b`,
});
});
it(`should parse github https`, () => {
const repository = getPkgRepo({repository: {url: `https://github.com/a/b`}});
expect(repository).to.contain({
domain: `github.com`,
type: `github`,
user: `a`,
project: `b`,
});
});
it(`should parse gitlab https`, () => {
const repository = getPkgRepo({repository: `https://gitlab.com/hyper-expanse/semantic-release-gitlab-releaser.git`});
expect(repository).to.contain({
domain: `gitlab.com`,
type: `gitlab`,
user: `hyper-expanse`,
project: `semantic-release-gitlab-releaser`,
});
});
it(`should parse github ssh`, () => {
expect(repository).to.contain({
domain: `github.com`,
type: `github`,
user: `joyent`,
project: `node`,
});
});
it(`should parse private gitlab ssh`, () => {
expect(repository).to.contain({
domain: `gitlab.team.com`,
type: `gitlab`,
user: `username`,
project: `test`,
});
});
it(`should parse github short`, () => {
const repository = getPkgRepo({repository: {url: `a/b`}});
expect(repository).to.contain({
domain: `github.com`,
type: `github`,
user: `a`,
project: `b`,
});
});
it(`should parse bitbucket`, () => {
const repository = getPkgRepo({repository: {url: `https://bitbucket.org/a/b.git`}});
expect(repository).to.contain({
domain: `bitbucket.org`,
type: `bitbucket`,
user: `a`,
project: `b`,
});
});
it(`should parse svn`, () => {
const repository = getPkgRepo({repository: {url: `svn://a/b`}});
expect(repository).to.contain({
domain: `a`,
project: null,
type: null,
user: null,
});
});
it(`should parse https`, () => {
const repository = getPkgRepo({repository: {url: `https://a/b`}});
expect(repository).to.contain({
domain: `a`,
project: null,
type: null,
user: null,
});
});
it.skip(`should parse a url with an @`, () => {
expect(repository).to.contain({
domain: null,
project: null,
type: null,
user: null,
});
});
it(`should fix bad protocol`, () => {
const repository = getPkgRepo({repository: {url: `badprotocol://a/b`}});
expect(repository).to.contain({
domain: `a`,
project: null,
type: null,
user: null,
});
});
it(`should parse github enterprise http url`, () => {
const repository = getPkgRepo({repository: {url: `http://github.mycompany.dev/user/myRepo`}});
expect(repository).to.contain({
domain: `github.mycompany.dev`,
user: `user`,
project: `myRepo`,
type: `github`,
});
});
it(`should parse unknown git URL`, () => {
const repository = getPkgRepo({repository: {url: `[email protected]:group1/group2/group3/project.git`}});
expect(repository).to.contain({
domain: `git.ourdomain.co`,
user: `group1/group2/group3`,
project: `project`,
type: null,
});
});
it(`should parse simple unknown host`, () => {
const repository = getPkgRepo({repository: {url: `https://unknown-host/`}});
expect(repository).to.contain({
domain: `unknown-host`,
project: null,
type: null,
user: null,
});
});
it(`should parse weird unknown host`, () => {
const repository = getPkgRepo({repository: {url: `https://unknown-host/.git`}});
expect(repository).to.contain({
domain: `unknown-host`,
project: null,
type: null,
user: null,
});
});
});