Skip to content

Commit

Permalink
Return revisionData object from generators
Browse files Browse the repository at this point in the history
  • Loading branch information
achambers committed Aug 31, 2015
1 parent 915ffc7 commit 280bf35
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 39 deletions.
10 changes: 5 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ module.exports = {

this.log('creating revision data using `' + type + '`');
return dataGenerator.generate()
.then(function(revisionKey) {
self.log('generated revision ata for revision: `' + revisionKey + '`');
return revisionKey;
.then(function(data) {
self.log('generated revision data for revision: `' + data.revisionKey + '`');
return data;
})
.then(function(revisionKey) {
return { revisionKey: revisionKey };
.then(function(data) {
return { revisionData: data };
})
.catch(this._errorMessage.bind(this));
},
Expand Down
5 changes: 4 additions & 1 deletion lib/data-generators/file-hash.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ module.exports = CoreObject.extend({

return readFile(filePath)
.then(function(contents) {
return md5Hash(contents.toString());
return {
revisionKey: md5Hash(contents.toString()),
timestamp: new Date().toISOString()
};
})
}
});
Expand Down
5 changes: 4 additions & 1 deletion lib/data-generators/git-tag-commit.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ module.exports = CoreObject.extend({
return Promise.reject('Could not build revision with tag `' + tag + '` and commit hash `' + sha + '`');
}

return Promise.resolve(info.tag + '+' + sha);
return Promise.resolve({
revisionKey: info.tag + '+' + sha,
timestamp: new Date().toISOString()
});
}
});
5 changes: 4 additions & 1 deletion lib/data-generators/version-commit.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ module.exports = CoreObject.extend({
return Promise.reject('Could not build revision with version `' + json.version + '` and commit hash `' + sha + '`');
}

return json.version + '+' + sha;
return {
revisionKey: json.version + '+' + sha,
timestamp: new Date().toISOString()
};
});
}
});
5 changes: 3 additions & 2 deletions tests/unit/index-nodetest.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ describe('the index', function() {
});

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

return assert.isFulfilled(plugin.didBuild(context))
.then(function(result) {
assert.equal(result.revisionKey, 'ae1569f72495012cd5e8588e0f2f5d49');
assert.equal(result.revisionData.revisionKey, 'ae1569f72495012cd5e8588e0f2f5d49');
assert.isNotNull(result.revisionData.timestamp);
});
});
});
Expand Down
43 changes: 28 additions & 15 deletions tests/unit/lib/data-generators/file-hash-nodetest.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,37 @@ describe('the file-hash data generator', function() {
});

describe('#generate', function() {
it('generates a hash of the supplied index file', function() {
var plugin = {
stubConfig: {
distDir: 'tests/fixtures',
distFiles: ['index.html'],
filePattern: 'index.html'
},
readConfig: function(key) { return this.stubConfig[key]; }
};
describe('revisionData', function() {
var subject;

var subject = new DataGenerator({
plugin: plugin
});
before(function() {
var plugin = {
stubConfig: {
distDir: 'tests/fixtures',
distFiles: ['index.html'],
filePattern: 'index.html'
},
readConfig: function(key) { return this.stubConfig[key]; }
};

return assert.isFulfilled(subject.generate())
.then(function(hash) {
assert.equal(hash, 'ae1569f72495012cd5e8588e0f2f5d49');
subject = new DataGenerator({
plugin: plugin
});
});

it('includes the revisonKey', function() {
return assert.isFulfilled(subject.generate())
.then(function(revisionData) {
assert.equal(revisionData.revisionKey, 'ae1569f72495012cd5e8588e0f2f5d49');
});
});

it('includes a timestamp', function() {
return assert.isFulfilled(subject.generate())
.then(function(revisionData) {
assert.isNotNull(revisionData.timestamp);
});
});
});

it('rejects when the filePattern doesn\'t exist in distFiles', function() {
Expand Down
15 changes: 13 additions & 2 deletions tests/unit/lib/data-generators/git-tag-commit-nodetest.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,19 @@ describe('the git-tag-commit data generator', function() {
var subject = new DataGenerator();

return assert.isFulfilled(subject.generate())
.then(function(revision) {
assert.equal(revision, '2.3.4+41d41f08');
.then(function(data) {
assert.equal(data.revisionKey, '2.3.4+41d41f08');
});
});

it('returns a timestamp', function() {
process.chdir('tests/fixtures/repo');

var subject = new DataGenerator();

return assert.isFulfilled(subject.generate())
.then(function(data) {
assert.isNotNull(data.timestamp);
});
});

Expand Down
44 changes: 32 additions & 12 deletions tests/unit/lib/data-generators/version-commit-nodetest.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,17 @@ describe('the version-commit data generator', function() {
});

return assert.isFulfilled(subject.generate())
.then(function(revision) {
assert.equal(revision, '3.2.1+41d41f08');
.then(function(data) {
assert.equal(data.revisionKey, '3.2.1+41d41f08');
});
});

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

var plugin = {
stubConfig: {
versionFile: 'package.json'
versionFile: 'version.json'
},
readConfig: function(key) { return this.stubConfig[key]; }
};
Expand All @@ -55,18 +55,18 @@ describe('the version-commit data generator', function() {
plugin: plugin
});

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

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

var plugin = {
stubConfig: {
versionFile: 'version.json'
versionFile: 'package.json'
},
readConfig: function(key) { return this.stubConfig[key]; }
};
Expand All @@ -76,8 +76,28 @@ describe('the version-commit data generator', function() {
});

return assert.isFulfilled(subject.generate())
.then(function(revision) {
assert.equal(revision, '1.2.3+41d41f08');
.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');
});
});

Expand Down

0 comments on commit 280bf35

Please sign in to comment.