Skip to content

Commit

Permalink
Add origin tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cookpete committed Nov 7, 2017
1 parent 9b956d5 commit f50dced
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions test/origin.js
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: 'git@github.com:user/repo.git',
expected: origin.github
},
{
remote: 'https://gitlab.com/user/repo',
expected: origin.gitlab
},
{
remote: 'git@gitlab.com:user/repo.git',
expected: origin.gitlab
},
{
remote: 'https://bitbucket.org/user/repo',
expected: origin.bitbucket
},
{
remote: 'git@bitbucket.org: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')
})
})

0 comments on commit f50dced

Please sign in to comment.