Skip to content

Commit

Permalink
feat(test): Unit test for bumpFiles
Browse files Browse the repository at this point in the history
  • Loading branch information
thaiat committed Jun 19, 2016
1 parent ae7a938 commit eb07d1e
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 6 deletions.
7 changes: 4 additions & 3 deletions lib/versionHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ var bump = function(currentVersion, bumpType) {
var getOutputFile = function(filename, outputDir) {
var outputFile = filename;
if (outputDir) {
outputFile = path.join(outputDir, path.basename(filename) + path.extname(filename));
outputFile = path.join(outputDir, path.basename(filename));
}
return outputFile;
};
Expand All @@ -61,16 +61,17 @@ var bumpFiles = function(files, version, outputDir) {
var jsonBump = Promise.map(jsonFiles, (file) => {

var json = fileHelper.readJsonFile(file);

json.version = version;
return Promise.fromCallback(function(cb) {
fs.writeFile(getOutputFile(file), JSON.stringify(json, null, 4), cb);
fs.writeFile(getOutputFile(file, outputDir), JSON.stringify(json, null, 4), cb);
});
});
var xmlBump = Promise.map(xmlFiles, (file) => {
var xml = new XML(String(fileHelper.readTextFile(file)));
xml.attribute('version').setValue(version);
return Promise.fromCallback(function(cb) {
fs.writeFile(getOutputFile(file), xml.toXMLString(), cb);
fs.writeFile(getOutputFile(file, outputDir), xml.toXMLString(), cb);
});
});
return Promise.all([xmlBump, jsonBump]);
Expand Down
19 changes: 19 additions & 0 deletions test/assets/bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "dummy",
"version": "1.4.3",
"description": "A dummy package",
"keywords": [
"motion",
"physics",
"particles"
],
"license": "MIT",
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"test",
"tests"
],
"private": true
}
6 changes: 3 additions & 3 deletions test/assets/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "dummy",
"version": "1.3.2",
"description": "A dummy package"
"name": "dummy",
"version": "2.4.11",
"description": "A dummy package"
}
11 changes: 11 additions & 0 deletions test/mocha/versionHelper.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,15 @@ describe('versionHelper', () => {
});
});

describe.only('bumpFiles()', () => {

it('should succeed', (done) => {
versionHelper.bumpFiles(['./test/assets/package.json', './test/assets/bower.json', './test/assets/config.xml'], '2.4.11', './test/results')
.then(res => {
done();
})
.catch(done);
});
});

});

0 comments on commit eb07d1e

Please sign in to comment.