Skip to content

Commit f8b98b5

Browse files
committed
Move test origins to separate file
1 parent a6ae95e commit f8b98b5

File tree

4 files changed

+39
-64
lines changed

4 files changed

+39
-64
lines changed

test/commits.js

Lines changed: 14 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3,65 +3,44 @@ import { expect } from 'chai'
33
import { readFile } from 'fs-extra'
44
import { join } from 'path'
55

6+
import origins from './data/origins'
67
import commits from './data/commits'
78
import { __get__ } from '../src/commits'
89

910
const parseCommits = __get__('parseCommits')
10-
// const parseCommit = __get__('parseCommit')
11-
// const getTag = __get__('getTag')
12-
// const getSubject = __get__('getSubject')
13-
// const getStats = __get__('getStats')
1411
const getFixes = __get__('getFixes')
1512
const getMerge = __get__('getMerge')
16-
// const getCommitLink = __get__('getCommitLink')
17-
// const getIssueLink = __get__('getIssueLink')
18-
// const getPullLink = __get__('getPullLink')
19-
20-
const origin = {
21-
github: {
22-
hostname: 'github.com',
23-
url: 'https://github.com/user/repo'
24-
},
25-
gitlab: {
26-
hostname: 'gitlab.com',
27-
url: 'https://gitlab.com/user/repo'
28-
},
29-
bitbucket: {
30-
hostname: 'bitbucket.org',
31-
url: 'https://bitbucket.org/user/repo'
32-
}
33-
}
3413

3514
describe('parseCommits', () => {
3615
it('parses commits', async () => {
3716
const gitLog = await readFile(join(__dirname, 'data', 'git-log.txt'), 'utf-8')
38-
expect(parseCommits(gitLog, origin.github)).to.deep.equal(commits)
17+
expect(parseCommits(gitLog, origins.github)).to.deep.equal(commits)
3918
})
4019
})
4120

4221
describe('getFixes', () => {
4322
it('returns null with no fixes', () => {
4423
const message = 'Commit message with no fixes'
45-
expect(getFixes(message, origin.github)).to.equal(null)
24+
expect(getFixes(message, origins.github)).to.equal(null)
4625
})
4726

4827
it('parses a single fix', () => {
4928
const message = 'Commit that fixes #12'
50-
expect(getFixes(message, origin.github)).to.deep.equal([
29+
expect(getFixes(message, origins.github)).to.deep.equal([
5130
{ id: '12', href: 'https://github.com/user/repo/issues/12' }
5231
])
5332
})
5433

5534
it('parses fix in commit notes', () => {
5635
const message = 'Commit message\n\nCloses #8'
57-
expect(getFixes(message, origin.github)).to.deep.equal([
36+
expect(getFixes(message, origins.github)).to.deep.equal([
5837
{ id: '8', href: 'https://github.com/user/repo/issues/8' }
5938
])
6039
})
6140

6241
it('parses multiple fixes', () => {
6342
const message = 'Commit message\n\nFixes #1, fix #2, resolved #3, closes #4'
64-
expect(getFixes(message, origin.github)).to.deep.equal([
43+
expect(getFixes(message, origins.github)).to.deep.equal([
6544
{ id: '1', href: 'https://github.com/user/repo/issues/1' },
6645
{ id: '2', href: 'https://github.com/user/repo/issues/2' },
6746
{ id: '3', href: 'https://github.com/user/repo/issues/3' },
@@ -71,14 +50,14 @@ describe('getFixes', () => {
7150

7251
it('parses fixes by issue URL', () => {
7352
const message = 'Commit message\n\nFixes https://github.com/user/repo/issues/1'
74-
expect(getFixes(message, origin.github)).to.deep.equal([
53+
expect(getFixes(message, origins.github)).to.deep.equal([
7554
{ id: '1', href: 'https://github.com/user/repo/issues/1' }
7655
])
7756
})
7857

7958
it('parses external repo issues', () => {
8059
const message = 'Commit message\n\nFixes https://github.com/other-user/external-repo/issues/1'
81-
expect(getFixes(message, origin.github)).to.deep.equal([
60+
expect(getFixes(message, origins.github)).to.deep.equal([
8261
{ id: '1', href: 'https://github.com/other-user/external-repo/issues/1' }
8362
])
8463
})
@@ -87,13 +66,13 @@ describe('getFixes', () => {
8766
describe('getMerge', () => {
8867
it('returns null on fail', () => {
8968
const message = 'Not a merge commit'
90-
expect(getMerge(message, origin.github)).to.equal(null)
69+
expect(getMerge(message, origins.github)).to.equal(null)
9170
})
9271

9372
describe('GitHub', () => {
9473
it('parses a merge', () => {
9574
const message = 'Merge pull request #3 from repo/branch\n\nPull request title'
96-
expect(getMerge(message, origin.github)).to.deep.equal({
75+
expect(getMerge(message, origins.github)).to.deep.equal({
9776
id: '3',
9877
message: 'Pull request title',
9978
href: 'https://github.com/user/repo/pull/3'
@@ -102,7 +81,7 @@ describe('getMerge', () => {
10281

10382
it('parses a squash merge', () => {
10483
const message = 'Update dependencies to enable Greenkeeper 🌴 (#10)\n\n* chore(package): update dependencies'
105-
expect(getMerge(message, origin.github)).to.deep.equal({
84+
expect(getMerge(message, origins.github)).to.deep.equal({
10685
id: '10',
10786
message: 'Update dependencies to enable Greenkeeper 🌴',
10887
href: 'https://github.com/user/repo/pull/10'
@@ -111,14 +90,14 @@ describe('getMerge', () => {
11190

11291
it('does not parse a not-quite squash merge', () => {
11392
const message = 'Update dependencies to enable Greenkeeper 🌴 (#10)\n\nSomething that isnt a squashed commit'
114-
expect(getMerge(message, origin.github)).to.equal(null)
93+
expect(getMerge(message, origins.github)).to.equal(null)
11594
})
11695
})
11796

11897
describe('GitLab', () => {
11998
it('parses a merge', () => {
12099
const message = 'Merge branch \'branch\' into \'master\'\n\nMemoize GitLab logger to reduce open file descriptors\n\nCloses gitlab-ee#3664\n\nSee merge request !15007'
121-
expect(getMerge(message, origin.gitlab)).to.deep.equal({
100+
expect(getMerge(message, origins.gitlab)).to.deep.equal({
122101
id: '15007',
123102
message: 'Memoize GitLab logger to reduce open file descriptors',
124103
href: 'https://gitlab.com/user/repo/merge_requests/15007'
@@ -129,7 +108,7 @@ describe('getMerge', () => {
129108
describe('BitBucket', () => {
130109
it('parses a merge', () => {
131110
const message = 'Merged in eshvedai/fix-schema-issue (pull request #4518)\n\nfix(component): re-export createSchema from editor-core\n\nApproved-by: Scott Sidwell <ssidwell@atlassian.com>'
132-
expect(getMerge(message, origin.bitbucket)).to.deep.equal({
111+
expect(getMerge(message, origins.bitbucket)).to.deep.equal({
133112
id: '4518',
134113
message: 'fix(component): re-export createSchema from editor-core',
135114
href: 'https://bitbucket.org/user/repo/pull-requests/4518'

test/data/origins.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export default {
2+
github: {
3+
hostname: 'github.com',
4+
url: 'https://github.com/user/repo'
5+
},
6+
gitlab: {
7+
hostname: 'gitlab.com',
8+
url: 'https://gitlab.com/user/repo'
9+
},
10+
bitbucket: {
11+
hostname: 'bitbucket.org',
12+
url: 'https://bitbucket.org/user/repo'
13+
}
14+
}

test/origin.js

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,41 @@
11
import { describe, it } from 'mocha'
22
import { expect } from 'chai'
33

4+
import origins from './data/origins'
45
import {
56
fetchOrigin,
67
__Rewire__ as mock,
78
__ResetDependency__ as unmock
89
} from '../src/origin'
910

10-
const origin = {
11-
github: {
12-
hostname: 'github.com',
13-
url: 'https://github.com/user/repo'
14-
},
15-
gitlab: {
16-
hostname: 'gitlab.com',
17-
url: 'https://gitlab.com/user/repo'
18-
},
19-
bitbucket: {
20-
hostname: 'bitbucket.org',
21-
url: 'https://bitbucket.org/user/repo'
22-
}
23-
}
24-
2511
const TEST_DATA = [
2612
{
2713
remote: 'https://github.com/user/repo',
28-
expected: origin.github
14+
expected: origins.github
2915
},
3016
{
3117
remote: 'https://github.com:8080/user/repo',
32-
expected: origin.github
18+
expected: origins.github
3319
},
3420
{
3521
remote: 'git@github.com:user/repo.git',
36-
expected: origin.github
22+
expected: origins.github
3723
},
3824
{
3925
remote: 'https://gitlab.com/user/repo',
40-
expected: origin.gitlab
26+
expected: origins.gitlab
4127
},
4228
{
4329
remote: 'git@gitlab.com:user/repo.git',
44-
expected: origin.gitlab
30+
expected: origins.gitlab
4531
},
4632
{
4733
remote: 'https://bitbucket.org/user/repo',
48-
expected: origin.bitbucket
34+
expected: origins.bitbucket
4935
},
5036
{
5137
remote: 'git@bitbucket.org:user/repo.git',
52-
expected: origin.bitbucket
38+
expected: origins.bitbucket
5339
}
5440
]
5541

test/releases.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
11
import { describe, it } from 'mocha'
22
import { expect } from 'chai'
33

4+
import origins from './data/origins'
45
import commits from './data/commits'
56
import releases from './data/releases'
67
import { parseReleases } from '../src/releases'
78

8-
const origin = {
9-
hostname: 'github.com',
10-
url: 'https://github.com/user/repo'
11-
}
12-
139
describe('parseReleases', () => {
1410
it('parses releases', () => {
15-
expect(parseReleases(commits, origin, null, false)).to.deep.equal(releases)
11+
expect(parseReleases(commits, origins.github, null, false)).to.deep.equal(releases)
1612
})
1713

1814
it('supports a package version override', () => {
19-
const result = parseReleases(commits, origin, 'v3.0.0', false)
15+
const result = parseReleases(commits, origins.github, 'v3.0.0', false)
2016
expect(result).to.be.an('array')
2117
expect(result[0]).to.have.property('tag', 'v3.0.0')
2218
})

0 commit comments

Comments
 (0)