UNPKG

2.87 kBJavaScriptView Raw
1import { describe, it, before, after } from 'mocha';
2import chai from 'chai';
3import chaiAsPromised from 'chai-as-promised';
4import sinon from 'sinon';
5import GitHubApi from 'github';
6import { nextVersion, lastMergedPullRequestNumber } from './../lib/update.js';
7
8chai.use(chaiAsPromised);
9
10const expect = chai.expect;
11
12describe('nextVersion', () => {
13 describe('minor', () => {
14 it('version change success', done => {
15 expect(nextVersion({ from: '0.0.0', to: 'minor' }))
16 .to
17 .eventually
18 .equal('0.1.0')
19 .notify(done);
20 });
21 });
22
23 describe('major', () => {
24 it('version change success', done => {
25 expect(nextVersion({ from: '0.0.0', to: 'major' }))
26 .to
27 .eventually
28 .equal('1.0.0')
29 .notify(done);
30 });
31 });
32
33 describe('github', () => {
34 const opt = {
35 github: GitHubApi(),
36 token: process.env.GITHUB_TOKEN,
37 owner: 'ksespinola',
38 repo: 'package-version-test',
39 number: 3
40 };
41
42 describe('major', () => {
43 before(() => {
44 sinon
45 .stub(opt.github.pullRequests, "getAll")
46 .yieldsAsync(
47 null,
48 [{ merged_at: null, number: 4 }, { merged_at: "2017-01-12T19:32:48Z", number: 3 }]
49 )
50
51 sinon
52 .stub(opt.github.issues, "getIssueLabels")
53 .yieldsAsync(
54 null,
55 [{ name: 'major' }, { name: 'foo' }]
56 );
57 });
58
59 after(() => {
60 opt.github.issues.getIssueLabels.restore();
61 opt.github.pullRequests.getAll.restore();
62 });
63
64 it('version change success', done => {
65 expect(nextVersion({ from: '0.0.0', to: 'github', opt }))
66 .to
67 .eventually
68 .equal('1.0.0')
69 .notify(done);
70 });
71 });
72
73
74 describe('minor', () => {
75 before(() => {
76 sinon
77 .stub(opt.github.pullRequests, "getAll")
78 .yieldsAsync(
79 null,
80 [{ merged_at: null, number: 4 }, { merged_at: "2017-01-12T19:32:48Z", number: 3 }]
81 )
82
83 sinon
84 .stub(opt.github.issues, "getIssueLabels")
85 .yieldsAsync(
86 null,
87 [{ name: 'minor' }, { name: 'foo' }]
88 );
89 });
90
91 after(() => {
92 opt.github.issues.getIssueLabels.restore();
93 opt.github.pullRequests.getAll.restore();
94 });
95
96 it('version change success', done => {
97 expect(nextVersion({ from: '0.0.0', to: 'github', opt }))
98 .to
99 .eventually
100 .equal('0.1.0')
101 .notify(done);
102 });
103 });
104 });
105});
106
107describe('lastMergedPullRequest', () => {
108 it('first merged pull request number', () => {
109 expect(
110 lastMergedPullRequestNumber(
111 [{ merged_at: null, number: 4 }, { merged_at: "2017-01-12T19:32:48Z", number: 3 }]
112 )
113 ).to.equal(3)
114 });
115});