-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
gitlab-resolver.js
50 lines (40 loc) · 1.34 KB
/
gitlab-resolver.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
/* @flow */
import GitLabResolver from '../../../src/resolvers/exotics/gitlab-resolver.js';
import type {ExplodedFragment} from '../../../src/resolvers/exotics/hosted-git-resolver.js';
import Git from '../../../src/util/git.js';
const url = require('url');
test('getGitSSHUrl with hash', () => {
const gitSSHUrl = GitLabResolver.getGitSSHUrl({
hash: 'some-hash',
repo: 'some-repo',
user: 'some-user',
});
expect(gitSSHUrl).toContain('some-hash');
});
test('getGitSSHUrl with no hash', () => {
const gitSSHUrl = GitLabResolver.getGitSSHUrl({
hash: '',
repo: 'some-repo',
user: 'some-user',
});
expect(gitSSHUrl).toContain('some-repo');
expect(gitSSHUrl).toContain('some-user');
});
test('getGitHTTPUrl should return the correct git gitlab SSH url', () => {
const fragment: ExplodedFragment = {
user: 'foo',
repo: 'bar',
hash: '',
};
const expected = 'git+ssh://git@gitlab.com/' + fragment.user + '/' + fragment.repo + '.git';
expect(GitLabResolver.getGitSSHUrl(fragment)).toBe(expected);
});
test('getGitSSHUrl should return URL containing protocol', () => {
const gitSSHUrl = GitLabResolver.getGitSSHUrl({
hash: '',
repo: 'some-repo',
user: 'some-user',
});
expect(url.parse(gitSSHUrl).protocol).toEqual('git+ssh:');
expect(Git.npmUrlToGitUrl(gitSSHUrl).protocol).toEqual('ssh:');
});