UNPKG

3.28 kBJavaScriptView Raw
1'use strict'
2
3/* eslint-disable no-unused-expressions */
4
5const chai = require('chai')
6const mocha = require(`mocha`)
7const transform = require('./transform')
8
9const expect = chai.expect
10
11const beforeEach = mocha.beforeEach
12const describe = mocha.describe
13const it = mocha.it
14
15/*
16 The contents of `gitTags` is generated by the `git-raw-commits` package, which runs the following command:
17
18 git log --format=%B%n-hash-%n%H%n-gitTags-%n%d%n-committerDate-%n%ci
19
20 That command returns a list of log entries with output in the following form per commit:
21
22 -hash-
23 e26c9a71a638ef9d4e12c2512fcdf813399559a1
24 -gitTags-
25 (tag: 1.1.8)
26 -committerDate-
27 2017-05-29 13:42:41 -0500
28 1.1.8
29
30 The value of `gitTags` is the line between `-gitTags-` and `-committerDate-`.
31*/
32
33describe('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})