Skip to content

Commit 280bf35

Browse files
committed
Return revisionData object from generators
1 parent 915ffc7 commit 280bf35

File tree

8 files changed

+93
-39
lines changed

8 files changed

+93
-39
lines changed

index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ module.exports = {
3232

3333
this.log('creating revision data using `' + type + '`');
3434
return dataGenerator.generate()
35-
.then(function(revisionKey) {
36-
self.log('generated revision ata for revision: `' + revisionKey + '`');
37-
return revisionKey;
35+
.then(function(data) {
36+
self.log('generated revision data for revision: `' + data.revisionKey + '`');
37+
return data;
3838
})
39-
.then(function(revisionKey) {
40-
return { revisionKey: revisionKey };
39+
.then(function(data) {
40+
return { revisionData: data };
4141
})
4242
.catch(this._errorMessage.bind(this));
4343
},

lib/data-generators/file-hash.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ module.exports = CoreObject.extend({
2929

3030
return readFile(filePath)
3131
.then(function(contents) {
32-
return md5Hash(contents.toString());
32+
return {
33+
revisionKey: md5Hash(contents.toString()),
34+
timestamp: new Date().toISOString()
35+
};
3336
})
3437
}
3538
});

lib/data-generators/git-tag-commit.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ module.exports = CoreObject.extend({
1818
return Promise.reject('Could not build revision with tag `' + tag + '` and commit hash `' + sha + '`');
1919
}
2020

21-
return Promise.resolve(info.tag + '+' + sha);
21+
return Promise.resolve({
22+
revisionKey: info.tag + '+' + sha,
23+
timestamp: new Date().toISOString()
24+
});
2225
}
2326
});

lib/data-generators/version-commit.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ module.exports = CoreObject.extend({
3131
return Promise.reject('Could not build revision with version `' + json.version + '` and commit hash `' + sha + '`');
3232
}
3333

34-
return json.version + '+' + sha;
34+
return {
35+
revisionKey: json.version + '+' + sha,
36+
timestamp: new Date().toISOString()
37+
};
3538
});
3639
}
3740
});

tests/unit/index-nodetest.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ describe('the index', function() {
102102
});
103103

104104
describe('didBuild hook', function() {
105-
it('returns the revisionKey', function() {
105+
it('returns the revisionData', function() {
106106
var plugin = subject.createDeployPlugin({
107107
name: 'revision-data'
108108
});
@@ -128,7 +128,8 @@ describe('the index', function() {
128128

129129
return assert.isFulfilled(plugin.didBuild(context))
130130
.then(function(result) {
131-
assert.equal(result.revisionKey, 'ae1569f72495012cd5e8588e0f2f5d49');
131+
assert.equal(result.revisionData.revisionKey, 'ae1569f72495012cd5e8588e0f2f5d49');
132+
assert.isNotNull(result.revisionData.timestamp);
132133
});
133134
});
134135
});

tests/unit/lib/data-generators/file-hash-nodetest.js

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,37 @@ describe('the file-hash data generator', function() {
1010
});
1111

1212
describe('#generate', function() {
13-
it('generates a hash of the supplied index file', function() {
14-
var plugin = {
15-
stubConfig: {
16-
distDir: 'tests/fixtures',
17-
distFiles: ['index.html'],
18-
filePattern: 'index.html'
19-
},
20-
readConfig: function(key) { return this.stubConfig[key]; }
21-
};
13+
describe('revisionData', function() {
14+
var subject;
2215

23-
var subject = new DataGenerator({
24-
plugin: plugin
25-
});
16+
before(function() {
17+
var plugin = {
18+
stubConfig: {
19+
distDir: 'tests/fixtures',
20+
distFiles: ['index.html'],
21+
filePattern: 'index.html'
22+
},
23+
readConfig: function(key) { return this.stubConfig[key]; }
24+
};
2625

27-
return assert.isFulfilled(subject.generate())
28-
.then(function(hash) {
29-
assert.equal(hash, 'ae1569f72495012cd5e8588e0f2f5d49');
26+
subject = new DataGenerator({
27+
plugin: plugin
3028
});
29+
});
30+
31+
it('includes the revisonKey', function() {
32+
return assert.isFulfilled(subject.generate())
33+
.then(function(revisionData) {
34+
assert.equal(revisionData.revisionKey, 'ae1569f72495012cd5e8588e0f2f5d49');
35+
});
36+
});
37+
38+
it('includes a timestamp', function() {
39+
return assert.isFulfilled(subject.generate())
40+
.then(function(revisionData) {
41+
assert.isNotNull(revisionData.timestamp);
42+
});
43+
});
3144
});
3245

3346
it('rejects when the filePattern doesn\'t exist in distFiles', function() {

tests/unit/lib/data-generators/git-tag-commit-nodetest.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,19 @@ describe('the git-tag-commit data generator', function() {
2727
var subject = new DataGenerator();
2828

2929
return assert.isFulfilled(subject.generate())
30-
.then(function(revision) {
31-
assert.equal(revision, '2.3.4+41d41f08');
30+
.then(function(data) {
31+
assert.equal(data.revisionKey, '2.3.4+41d41f08');
32+
});
33+
});
34+
35+
it('returns a timestamp', function() {
36+
process.chdir('tests/fixtures/repo');
37+
38+
var subject = new DataGenerator();
39+
40+
return assert.isFulfilled(subject.generate())
41+
.then(function(data) {
42+
assert.isNotNull(data.timestamp);
3243
});
3344
});
3445

tests/unit/lib/data-generators/version-commit-nodetest.js

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,17 @@ describe('the version-commit data generator', function() {
3636
});
3737

3838
return assert.isFulfilled(subject.generate())
39-
.then(function(revision) {
40-
assert.equal(revision, '3.2.1+41d41f08');
39+
.then(function(data) {
40+
assert.equal(data.revisionKey, '3.2.1+41d41f08');
4141
});
4242
});
4343

44-
it('rejects if no repository found', function() {
45-
process.chdir('tests/fixtures/not-a-repo');
44+
it('has version source file option', function() {
45+
process.chdir('tests/fixtures/repo');
4646

4747
var plugin = {
4848
stubConfig: {
49-
versionFile: 'package.json'
49+
versionFile: 'version.json'
5050
},
5151
readConfig: function(key) { return this.stubConfig[key]; }
5252
};
@@ -55,18 +55,18 @@ describe('the version-commit data generator', function() {
5555
plugin: plugin
5656
});
5757

58-
return assert.isRejected(subject.generate())
59-
.then(function(error) {
60-
assert.equal(error, 'Could not find git repository');
58+
return assert.isFulfilled(subject.generate())
59+
.then(function(data) {
60+
assert.equal(data.revisionKey, '1.2.3+41d41f08');
6161
});
6262
});
6363

64-
it('has version source file option', function() {
64+
it('returns a timestamp', function() {
6565
process.chdir('tests/fixtures/repo');
6666

6767
var plugin = {
6868
stubConfig: {
69-
versionFile: 'version.json'
69+
versionFile: 'package.json'
7070
},
7171
readConfig: function(key) { return this.stubConfig[key]; }
7272
};
@@ -76,8 +76,28 @@ describe('the version-commit data generator', function() {
7676
});
7777

7878
return assert.isFulfilled(subject.generate())
79-
.then(function(revision) {
80-
assert.equal(revision, '1.2.3+41d41f08');
79+
.then(function(data) {
80+
assert.isNotNull(data.timestamp);
81+
});
82+
});
83+
84+
it('rejects if no repository found', function() {
85+
process.chdir('tests/fixtures/not-a-repo');
86+
87+
var plugin = {
88+
stubConfig: {
89+
versionFile: 'package.json'
90+
},
91+
readConfig: function(key) { return this.stubConfig[key]; }
92+
};
93+
94+
var subject = new DataGenerator({
95+
plugin: plugin
96+
});
97+
98+
return assert.isRejected(subject.generate())
99+
.then(function(error) {
100+
assert.equal(error, 'Could not find git repository');
81101
});
82102
});
83103

0 commit comments

Comments
 (0)