1 | 'use strict'
|
2 |
|
3 |
|
4 |
|
5 | const chai = require('chai')
|
6 | const mocha = require(`mocha`)
|
7 | const transform = require('./transform')
|
8 |
|
9 | const expect = chai.expect
|
10 |
|
11 | const beforeEach = mocha.beforeEach
|
12 | const describe = mocha.describe
|
13 | const it = mocha.it
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 | describe('transform', function () {
|
34 | beforeEach(function () {
|
35 | this.chunk = {
|
36 | committerDate: 'June 8, 2012',
|
37 | gitTags: ''
|
38 | }
|
39 | })
|
40 |
|
41 | it('should skip semantic version matching when gitTags isn\'t a string', function (done) {
|
42 | this.chunk.gitTags = undefined
|
43 |
|
44 | transform(this.chunk, function (err, chunk) {
|
45 | if (err) {
|
46 | return done(err)
|
47 | }
|
48 | expect(chunk.version).to.be.undefined
|
49 | done()
|
50 | })
|
51 | })
|
52 |
|
53 | it('should have no version when there are no tags', function (done) {
|
54 | transform(this.chunk, function (err, chunk) {
|
55 | if (err) {
|
56 | return done(err)
|
57 | }
|
58 | expect(chunk.version).to.be.undefined
|
59 | done()
|
60 | })
|
61 | })
|
62 |
|
63 | it('should not match invalid semantic version tag', function (done) {
|
64 | this.chunk.gitTags = ' (tag: release-18)'
|
65 |
|
66 | transform(this.chunk, function (err, chunk) {
|
67 | if (err) {
|
68 | return done(err)
|
69 | }
|
70 | expect(chunk.version).to.be.undefined
|
71 | done()
|
72 | })
|
73 | })
|
74 |
|
75 | it('should match valid semantic version tag', function (done) {
|
76 | this.chunk.gitTags = ' (tag: 1.1.20)'
|
77 |
|
78 | transform(this.chunk, function (err, chunk) {
|
79 | if (err) {
|
80 | return done(err)
|
81 | }
|
82 | expect(chunk.version).to.equal('1.1.20')
|
83 | done()
|
84 | })
|
85 | })
|
86 |
|
87 | it('should match valid semantic version tag containing a leading `v`', function (done) {
|
88 | this.chunk.gitTags = ' (tag: v1.1.20)'
|
89 |
|
90 | transform(this.chunk, function (err, chunk) {
|
91 | if (err) {
|
92 | return done(err)
|
93 | }
|
94 | expect(chunk.version).to.equal('v1.1.20')
|
95 | done()
|
96 | })
|
97 | })
|
98 |
|
99 | it('should find valid semantic version tag out of many tags', function (done) {
|
100 | this.chunk.gitTags = ' (HEAD -> master, tag: something, tag: 1.1.20, origin/master, origin/HEAD)'
|
101 |
|
102 | transform(this.chunk, function (err, chunk) {
|
103 | if (err) {
|
104 | return done(err)
|
105 | }
|
106 | expect(chunk.version).to.equal('1.1.20')
|
107 | done()
|
108 | })
|
109 | })
|
110 |
|
111 | it('should match first semantic version tag when there are multiple valid tags', function (done) {
|
112 | this.chunk.gitTags = ' (tag: 1.1.19, tag: 1.1.20)'
|
113 |
|
114 | transform(this.chunk, function (err, chunk) {
|
115 | if (err) {
|
116 | return done(err)
|
117 | }
|
118 | expect(chunk.version).to.equal('1.1.19')
|
119 | done()
|
120 | })
|
121 | })
|
122 |
|
123 | it('should format date', function (done) {
|
124 | transform(this.chunk, function (err, chunk) {
|
125 | if (err) {
|
126 | return done(err)
|
127 | }
|
128 | expect(chunk.committerDate).to.equal('2012-06-08')
|
129 | done()
|
130 | })
|
131 | })
|
132 | })
|