-
-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { describe, it } from 'mocha' | ||
import { expect } from 'chai' | ||
|
||
import { | ||
fetchOrigin, | ||
__Rewire__ as mock, | ||
__ResetDependency__ as unmock | ||
} from '../src/origin' | ||
|
||
const origin = { | ||
github: { | ||
hostname: 'github.com', | ||
url: 'https://github.com/user/repo' | ||
}, | ||
gitlab: { | ||
hostname: 'gitlab.com', | ||
url: 'https://gitlab.com/user/repo' | ||
}, | ||
bitbucket: { | ||
hostname: 'bitbucket.org', | ||
url: 'https://bitbucket.org/user/repo' | ||
} | ||
} | ||
|
||
const TEST_DATA = [ | ||
{ | ||
remote: 'https://github.com/user/repo', | ||
expected: origin.github | ||
}, | ||
{ | ||
remote: 'https://github.com:8080/user/repo', | ||
expected: origin.github | ||
}, | ||
{ | ||
remote: '[email protected]:user/repo.git', | ||
expected: origin.github | ||
}, | ||
{ | ||
remote: 'https://gitlab.com/user/repo', | ||
expected: origin.gitlab | ||
}, | ||
{ | ||
remote: '[email protected]:user/repo.git', | ||
expected: origin.gitlab | ||
}, | ||
{ | ||
remote: 'https://bitbucket.org/user/repo', | ||
expected: origin.bitbucket | ||
}, | ||
{ | ||
remote: '[email protected]:user/repo.git', | ||
expected: origin.bitbucket | ||
} | ||
] | ||
|
||
describe('fetchOrigin', () => { | ||
for (let test of TEST_DATA) { | ||
it(`parses ${test.remote}`, async () => { | ||
mock('cmd', () => test.remote) | ||
expect(await fetchOrigin('origin')).to.include(test.expected) | ||
unmock('cmd') | ||
}) | ||
} | ||
|
||
it('throws an error', done => { | ||
mock('cmd', () => '') | ||
fetchOrigin('origin').catch(() => done()) | ||
unmock('cmd') | ||
}) | ||
}) |