From eb07d1e4ce33e25f2385415f52c5bc47c572f282 Mon Sep 17 00:00:00 2001 From: Avi Haiat Date: Sun, 19 Jun 2016 18:11:36 +0300 Subject: [PATCH] feat(test): Unit test for bumpFiles --- lib/versionHelper.js | 7 ++++--- test/assets/bower.json | 19 +++++++++++++++++++ test/assets/package.json | 6 +++--- test/mocha/versionHelper.spec.js | 11 +++++++++++ 4 files changed, 37 insertions(+), 6 deletions(-) create mode 100644 test/assets/bower.json diff --git a/lib/versionHelper.js b/lib/versionHelper.js index ee21e18..08bcb83 100644 --- a/lib/versionHelper.js +++ b/lib/versionHelper.js @@ -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; }; @@ -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]); diff --git a/test/assets/bower.json b/test/assets/bower.json new file mode 100644 index 0000000..fef1a25 --- /dev/null +++ b/test/assets/bower.json @@ -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 +} diff --git a/test/assets/package.json b/test/assets/package.json index ef4d311..fda38f6 100644 --- a/test/assets/package.json +++ b/test/assets/package.json @@ -1,5 +1,5 @@ { - "name": "dummy", - "version": "1.3.2", - "description": "A dummy package" + "name": "dummy", + "version": "2.4.11", + "description": "A dummy package" } \ No newline at end of file diff --git a/test/mocha/versionHelper.spec.js b/test/mocha/versionHelper.spec.js index 26789e2..6e7b090 100644 --- a/test/mocha/versionHelper.spec.js +++ b/test/mocha/versionHelper.spec.js @@ -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); + }); + }); + });