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: '[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')
})
})

0 comments on commit f50dced

Please sign in to comment.