-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathversion-commit-nodetest.js
174 lines (139 loc) · 4.33 KB
/
version-commit-nodetest.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
'use strict';
var assert = require('../../../helpers/assert');
var gitRepoInfo = require('git-repo-info');
describe('the version-commit data generator', function() {
var DataGenerator;
var cwd;
before(function() {
DataGenerator = require('../../../../lib/data-generators/version-commit');
gitRepoInfo._changeGitDir('dotgit');
});
beforeEach(function() {
cwd = process.cwd();
});
afterEach(function() {
process.chdir(cwd);
});
describe('#generate', function() {
describe('with partial commit data', function() {
before(function() {
gitRepoInfo._changeGitDir('dotgit-branch-only');
});
after(function() {
gitRepoInfo._changeGitDir('dotgit');
});
it('only adds `+revision` if it can be read', function() {
process.chdir('tests/fixtures/repo');
var plugin = {
stubConfig: {
versionFile: 'package.json'
},
readConfig: function(key) { return this.stubConfig[key]; },
log: function() {}
};
var subject = new DataGenerator({
plugin: plugin
});
return assert.isFulfilled(subject.generate())
.then(function(data) {
var path = gitRepoInfo._findRepo();
assert.equal(data.revisionKey, '3.2.1');
});
});
it('logs a warning if no git sha found', function() {
process.chdir('tests/fixtures/repo');
var expectedMessage = /missing git commit sha/i;
var plugin = {
stubConfig: {
versionFile: 'package.json'
},
readConfig: function(key) { return this.stubConfig[key]; },
log: function(message) {
assert.ok(message.match(expectedMessage));
}
};
var subject = new DataGenerator({
plugin: plugin
});
return assert.isFulfilled(subject.generate())
})
});
it('concatenates the package version and the git commit hash', function() {
process.chdir('tests/fixtures/repo');
var plugin = {
stubConfig: {
versionFile: 'package.json'
},
readConfig: function(key) { return this.stubConfig[key]; }
};
var subject = new DataGenerator({
plugin: plugin
});
return assert.isFulfilled(subject.generate())
.then(function(data) {
assert.equal(data.revisionKey, '3.2.1+41d41f08');
});
});
it('has version source file option', function() {
process.chdir('tests/fixtures/repo');
var plugin = {
stubConfig: {
versionFile: 'version.json'
},
readConfig: function(key) { return this.stubConfig[key]; }
};
var subject = new DataGenerator({
plugin: plugin
});
return assert.isFulfilled(subject.generate())
.then(function(data) {
assert.equal(data.revisionKey, '1.2.3+41d41f08');
});
});
it('returns a timestamp', function() {
process.chdir('tests/fixtures/repo');
var plugin = {
stubConfig: {
versionFile: 'package.json'
},
readConfig: function(key) { return this.stubConfig[key]; }
};
var subject = new DataGenerator({
plugin: plugin
});
return assert.isFulfilled(subject.generate())
.then(function(data) {
assert.isNotNull(data.timestamp);
});
});
it('rejects if no repository found', function() {
process.chdir('tests/fixtures/not-a-repo');
var plugin = {
stubConfig: {
versionFile: 'package.json'
},
readConfig: function(key) { return this.stubConfig[key]; }
};
var subject = new DataGenerator({
plugin: plugin
});
return assert.isRejected(subject.generate())
.then(function(error) {
assert.equal(error, 'Could not find git repository');
});
});
it('rejects when the version source file doesn\'t exist', function() {
process.chdir('tests/fixtures/repo');
var plugin = {
stubConfig: {
versionFile: 'tests/fixtures/missing-version.json'
},
readConfig: function(key) { return this.stubConfig[key]; }
};
var subject = new DataGenerator({
plugin: plugin
});
return assert.isRejected(subject.generate());
});
});
});