From 0d2717b32ed9657f13dbff03b6554226e2aa88d5 Mon Sep 17 00:00:00 2001 From: Alexandre Beaudoin Date: Tue, 9 Feb 2016 20:15:27 -0500 Subject: [PATCH] [WIP] New e2e test folder style. Update dependencies. --- CHANGELOG.md | 12 +- Gruntfile.js | 15 +- lib/api.js | 30 +-- lib/cmd.js | 26 +-- lib/fileManagement.js | 34 ++-- lib/fileSystem.js | 14 +- lib/readConfig.js | 13 +- package.json | 14 +- test/e2e/e2e.test.js | 273 +++++++++++++++++++++++++++ test/e2e/e2eData.test.js | 201 ++++++++++++++++++++ test/unit/.jshintrc | 14 -- test/unit/lib/api.test.js | 64 ++++--- test/unit/lib/cmd.test.js | 10 +- test/unit/lib/fileManagement.test.js | 4 +- test/unit/lib/fileSystem.test.js | 25 +-- test/unit/lib/readConfig.test.js | 4 +- 16 files changed, 617 insertions(+), 136 deletions(-) create mode 100644 test/e2e/e2e.test.js create mode 100644 test/e2e/e2eData.test.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d82527..3aec4c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,11 +1,15 @@ # Changelog +## 0.3.2 - 2015-12-24 + +- Fix cInstall.option.default.folder not impacting the cInstall.folder paths. + ## 0.3.1 - 2015-11-01 - Add support for coveralls.io for test coverage report. - Remove useless dependencies. - Switch blanket.js for istanbul.js as coverage test reporter. -- Update .travis.iml file to stop use legacy version of Travis CI. +- Update .travis.iml file to stop use legacy version of TravisCI. - Add test against Node.js v5. ## 0.3.0 - 2015-09-15 @@ -14,7 +18,7 @@ - Accelerate the execution of the tool on an empty value of the field `cInstall` in the `bower.json` file. - Update dependencies. - Fix a possible error when using name with glob star. -- Deprecated the use of `automatic` in the api (was already mark as deprecated in the cmd module). +- Deprecated the use of `automatic` in the API (was already mark as deprecated in the cmd module). - Better deprecation throw, by using the Node.js `util` module. - Start using version 1.4.x of q instead of version 2.x.x because it wasn't updated since 2014. @@ -71,9 +75,9 @@ ## 0.0.3 - 2014-10-27 -- Add option to get minimised version of bower dependencies. +- Add option to get minimized version of bower dependencies. - Add option to set a default folder for minimized files. -- Repair the CLI commands call. Before the CLI section was call as soon as we require the clean-bower-installer module, now it not (as intended). +- Repair the CLI commands call. Before the CLI section was called as soon as we require the clean-bower-installer module, now it is not (as intended). ## 0.0.2 - 2014-10-08 diff --git a/Gruntfile.js b/Gruntfile.js index cc749a4..ca5417f 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1,7 +1,7 @@ "use strict"; module.exports = function(grunt) { - grunt.initConfig({ + grunt.config.init({ pkg: grunt.file.readJSON("package.json"), setup: { "testDir": ".testFolder" @@ -56,7 +56,16 @@ module.exports = function(grunt) { quiet: false, clearRequireCache: false }, - src: ["test/unit/**/*.js"] + src: ["test/unit/**/*.test.js"] + }, + e2e: { + options: { + reporter: "spec", + captureFile: "<%= setup.testDir %>/unitResults.txt", + quiet: false, + clearRequireCache: false + }, + src: ["test/e2e/**/*.test.js"] } }, run: { @@ -125,7 +134,7 @@ module.exports = function(grunt) { grunt.registerTask("codeQualityCheckup", ["jshint:dev"]); // Run the useful development tests - grunt.registerTask("test", ["run:runTests", "unit", "coverage"]); + grunt.registerTask("test", ["run:runTests", "coverage"]); // Run the action to test before committing grunt.registerTask("preCommit", ["jshint:prod", "test"]); diff --git a/lib/api.js b/lib/api.js index ce70bae..8b00074 100644 --- a/lib/api.js +++ b/lib/api.js @@ -1,6 +1,6 @@ "use strict"; -var q = require("q"), +var Q = require("q"), cmd = require("./cmd"), cnf = require("./readConfig"), util = require("util"); @@ -8,7 +8,7 @@ var q = require("q"), /** * Call cmd.js command using promise * - * @param promise {Promise} + * @param promise {Promise} * @param cmd {Function} * @param option {Object} */ @@ -27,7 +27,7 @@ function callCmd(promise, cmd, option) { cnf.read(option).then( function (config) { if (config === "Nothing to do!") { - promise.resolve("Nothing to do!"); + promise.resolve(config); } else { cmd(config).then( function (res) { @@ -54,10 +54,10 @@ module.exports = { * Execute the automatic * * @param [option] {Object} - * @returns {Promise} + * @returns {Promise} */ automatic: util.deprecate(function (option) { - var deferred = q.defer(); + var deferred = Q.defer(); callCmd(deferred, cmd.automatic, option); @@ -67,10 +67,10 @@ module.exports = { * Execute the install * * @param [option] {Object} - * @returns {Promise} + * @returns {Promise} */ install: function (option) { - var deferred = q.defer(); + var deferred = Q.defer(); callCmd(deferred, cmd.install, option); @@ -80,10 +80,10 @@ module.exports = { * Execute the update * * @param [option] {Object} - * @returns {Promise} + * @returns {Promise} */ update: function (option) { - var deferred = q.defer(); + var deferred = Q.defer(); callCmd(deferred, cmd.update, option); @@ -93,10 +93,10 @@ module.exports = { * Simply run the clean-bower-installer without bower call * * @param [option] {Object} - * @returns {Promise} + * @returns {Promise} */ run: function (option) { - var deferred = q.defer(); + var deferred = Q.defer(); callCmd(deferred, cmd.run, option); @@ -106,10 +106,10 @@ module.exports = { * Run the clean-bower-installer with the min option, without bower call * * @param [option] {Object} - * @returns {Promise} + * @returns {Promise} */ runMin: function (option) { - var deferred = q.defer(); + var deferred = Q.defer(); try { option = option || {option: {min: {}}}; @@ -130,10 +130,10 @@ module.exports = { * Run the clean-bower-installer with the min and the renameMin option, without bower call * * @param [option] {Object} - * @returns {Promise} + * @returns {Promise} */ runMinR: function (option) { - var deferred = q.defer(); + var deferred = Q.defer(); try { option = option || {option: {}}; diff --git a/lib/cmd.js b/lib/cmd.js index 47affab..45abde9 100644 --- a/lib/cmd.js +++ b/lib/cmd.js @@ -1,6 +1,6 @@ "use strict"; -var q = require("q"), +var Q = require("q"), fileManagement = require("./fileManagement"), exec = require("child_process").exec, path = require("path"), @@ -12,10 +12,10 @@ var q = require("q"), * * @param config {{}} * @param command (String} - * @returns {Promise} + * @returns {Promise} */ function callBower(config, command) { - var deferred = q.defer(); + var deferred = Q.defer(); /* Bower install done the update if the file already exist so in the case of not knowing which one to use (install or update) * install will do both.*/ @@ -53,7 +53,7 @@ function callBower(config, command) { * * @param err {String} * @param cnf {{}} - * @param promise {Promise} + * @param promise {Promise} */ function bowerError(err, cnf, promise) { if(err === "ENOENT") { @@ -67,7 +67,7 @@ function bowerError(err, cnf, promise) { * Call the file management module * * @param config {{}} - * @param promise {Promise} + * @param promise {Promise} */ function callFileManagement(config, promise) { var fm; @@ -92,10 +92,10 @@ module.exports = { /** * Execute the automatic * - * @returns {Promise} + * @returns {Promise} */ automatic: function(config) { - var deferred = q.defer(); + var deferred = Q.defer(); if (config && config.hasOwnProperty("cwd")) { callBower(config, "automatic").then( @@ -115,10 +115,10 @@ module.exports = { /** * Execute the install * - * @returns {Promise} + * @returns {Promise} */ install: function(config) { - var deferred = q.defer(); + var deferred = Q.defer(); if (config && config.hasOwnProperty("cwd")) { callBower(config, "install").then( @@ -138,10 +138,10 @@ module.exports = { /** * Execute the update * - * @returns {Promise} + * @returns {Promise} */ update: function(config) { - var deferred = q.defer(); + var deferred = Q.defer(); if (config && config.hasOwnProperty("cwd")) { callBower(config, "update").then( @@ -161,10 +161,10 @@ module.exports = { /** * Simply run the clean-bower-installer without bower call * - * @returns {Promise} + * @returns {Promise} */ run: function(config) { - var deferred = q.defer(); + var deferred = Q.defer(); if (config && config.hasOwnProperty("cwd")) { fs.stat(path.join(config.cwd, "bower.json"), function(err) { diff --git a/lib/fileManagement.js b/lib/fileManagement.js index 8b9a9d0..baffcd5 100644 --- a/lib/fileManagement.js +++ b/lib/fileManagement.js @@ -1,7 +1,7 @@ "use strict"; var fs = require("./fileSystem"), - q = require("q"), + Q = require("q"), path = require("path"), glob = require("glob"), regex = { @@ -19,10 +19,10 @@ var fs = require("./fileSystem"), * @param libName {String} * @param [depth] {Number} * @param [localCache] {Array} - * @returns {Promise} + * @returns {Promise} */ function arrayOfGlob(globs, bowerFileFolder, libName, depth, localCache) { - var deferred = q.defer(), + var deferred = Q.defer(), length = globs.length; depth = depth || 0; @@ -88,7 +88,7 @@ FileObj.prototype = { * @param libFolder {String} * @param uncleanList {{ignore: Array, move: Array}} * @param that {FileObj} - * @returns {Promise} + * @returns {Promise} */ getList: function(libs, libName, libFolder, uncleanList, that) { return that.enumeratePackages(libs, libName, libFolder).then( @@ -107,7 +107,7 @@ FileObj.prototype = { * @param localCache {{}} * @param uncleanList {{ignore: Array, move: Array}} * @param that {FileObj} - * @returns {Promise} + * @returns {Promise} */ enumeratePackages: function(fileNameAndExt, libName, libFolder, localCache, uncleanList, that) { return arrayOfGlob([fileNameAndExt], that.bowerFileFolder, libName, 0, localCache).then( @@ -135,7 +135,7 @@ FileObj.prototype = { ignore: [], move: [] }, - defer = q.defer(), + defer = Q.defer(), promises = [], src = this.source, that = this, @@ -151,7 +151,7 @@ FileObj.prototype = { } } - q.all(promises).then( + Q.all(promises).then( function() { defer.resolve(that.clean(uncleanList)); }, @@ -173,7 +173,7 @@ FileObj.prototype = { */ enumeratePackages: function(pkgs, libName, libFolder) { var uncleanList = {ignore: [], move: []}, - defer = q.defer(), + defer = Q.defer(), promises = [], promise = this.promise; @@ -216,7 +216,7 @@ FileObj.prototype = { } } - q.all(promises).then( + Q.all(promises).then( function() { defer.resolve(uncleanList); }, @@ -265,13 +265,13 @@ FileObj.prototype = { // The specified file folder is global unCleanList[action].push({ "from": f, - "to": path.join(this.cwd, fileFolder.substr(1), thisFile + path.extname(f)) + "to": path.join(this.cwd, this.defFolder, fileFolder.substr(1), thisFile + path.extname(f)) }); } else if (regex.startWithSlash.test(libFolder)) { // The specified lib folder is global unCleanList[action].push({ "from": f, - "to": path.join(this.cwd, libFolder.substr(1), fileFolder, thisFile + path.extname(f)) + "to": path.join(this.cwd, this.defFolder, libFolder.substr(1), fileFolder, thisFile + path.extname(f)) }); } else { var df; @@ -332,7 +332,7 @@ FileObj.prototype = { * @returns {Promise} */ deleteBowerComponents: function() { - var deferred = q.defer(); + var deferred = Q.defer(); fs.rmdirRQ(this.bowerFileFolder).then( // Pass @@ -355,7 +355,7 @@ FileObj.prototype = { * @returns {Promise} */ run: function() { - var deferred = q.defer(), + var deferred = Q.defer(), that = this; this.getList().then( @@ -371,7 +371,7 @@ FileObj.prototype = { promises.push(fs.copyQ(list[i].from, list[i].to)); } - q.all(promises).then( + Q.all(promises).then( function() { if (that.isVerbose) { deferred.resolve(that.listBackup); @@ -397,7 +397,7 @@ FileObj.prototype = { * @returns {Promise} */ runAndRemove: function() { - var deferred = q.defer(), + var deferred = Q.defer(), pointer = this; this.run().then( @@ -431,7 +431,7 @@ FileObj.prototype = { * @returns {Promise} */ function moveFiles(config) { - var deferred = q.defer(), + var deferred = Q.defer(), list = new FileObj(config); list.run().then( @@ -454,7 +454,7 @@ function moveFiles(config) { * @returns {Promise} */ function moveFilesAndRemove(config) { - var deferred = q.defer(), + var deferred = Q.defer(), list = new FileObj(config); list.runAndRemove().then( diff --git a/lib/fileSystem.js b/lib/fileSystem.js index 090168e..b1cc8eb 100644 --- a/lib/fileSystem.js +++ b/lib/fileSystem.js @@ -1,7 +1,7 @@ "use strict"; var fs = require("fs"), - q = require("q"), + Q = require("q"), path = require("path"), osSep = process.platform === "win32" ? "\\" : "/"; @@ -47,10 +47,10 @@ fs.mkdirp = function(filePath, mode, callback, position) { * * @param dirPath {String} * @param mode {Number} - * @returns {Promise} + * @returns {Promise} */ fs.mkdirpQ = function(dirPath, mode) { - var deferred = q.defer(); + var deferred = Q.defer(); fs.mkdirp(dirPath, mode, function(err) { if (err) { @@ -100,10 +100,10 @@ fs.copy = function(from, to, callback) { * * @param from {String} * @param to {String} - * @returns {Promise} + * @returns {Promise} */ fs.copyQ = function(from, to) { - var deferred = q.defer(); + var deferred = Q.defer(); fs.copy(from, to, function(err) { if (err) { @@ -167,10 +167,10 @@ fs.rmdirR = function(path, callback) { * Delete folder and his content using promise * * @param path {String} - * @returns {Promise} + * @returns {Promise} */ fs.rmdirRQ = function(path) { - var deferred = q.defer(); + var deferred = Q.defer(); fs.rmdirR(path, function(err) { if (err) { diff --git a/lib/readConfig.js b/lib/readConfig.js index 738b24e..93bde0b 100644 --- a/lib/readConfig.js +++ b/lib/readConfig.js @@ -1,17 +1,17 @@ "use strict"; var fs = require("fs"), - q = require("q"), + Q = require("q"), path = require("path"); /** * Read the bower.json file * * @param cwd {String} - * @returns {Promise} + * @returns {Promise} */ function getBowerJson(cwd) { - var deferred = q.defer(), + var deferred = Q.defer(), bp = path.join(cwd, "bower.json"); fs.exists(bp, function(exist) { @@ -144,12 +144,12 @@ Config.prototype = { * Read the configuration * * @param [option] {{}} - * @returns {Promise} + * @returns {Promise} */ function read(option) { option = option || {}; var cwd = option.cwd || "", - deferred = q.defer(); + deferred = Q.defer(); var folder = path.join(process.cwd(), cwd); @@ -171,9 +171,6 @@ function read(option) { deferred.reject("Can't found the 'cInstall' object in the bower.json file."); } - // Done to remove Intellij warning - bowerJson.cInstall = bowerJson.cInstall || {}; - if (Object.keys(bowerJson.cInstall).length === 0) { deferred.resolve("Nothing to do!"); } diff --git a/package.json b/package.json index 211fbde..f12fc4e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "clean-bower-installer", - "version": "0.3.1", + "version": "0.3.2", "description": "Tool to install pre-selected bower dependencies", "keywords": [ "bower", @@ -23,21 +23,21 @@ "dependencies": { "cli": "0.x.x", "colors": "1.1.x", - "glob": "5.x.x", + "glob": "6.x.x", "q": "1.x.x" }, "devDependencies": { "bower": "latest", "chai": "3.x.x", - "coveralls": "^2.11.4", + "coveralls": "2.11.x", "fs-extra": "latest", "grunt": "0.4.x", - "grunt-contrib-jshint": "0.11.x", - "grunt-mocha-istanbul": "^3.0.1", + "grunt-contrib-jshint": "0.12.x", + "grunt-mocha-istanbul": "3.0.x", "grunt-mocha-test": "0.12.x", "grunt-run": "0.5.x", - "istanbul": "^0.4.0", - "mocha": "2.3.x" + "istanbul": "0.4.x", + "mocha": "2.4.x" }, "scripts": { "test": "grunt unit" diff --git a/test/e2e/e2e.test.js b/test/e2e/e2e.test.js new file mode 100644 index 0000000..2230d97 --- /dev/null +++ b/test/e2e/e2e.test.js @@ -0,0 +1,273 @@ +var chai = require("chai"), + expect = chai.expect, + describe = require("mocha/lib/mocha.js").describe, + it = require("mocha/lib/mocha.js").it, + beforeEach = require("mocha/lib/mocha.js").beforeEach, + fs = require("fs-extra"), + path = require("path"), + assert = require('assert'), + testFolders = require("./e2eData.test"), + exec = require("child_process").exec; + +var cbi = require("../../."); + +function verifyFileExist(path) { + try { + fs.statSync(path); + } catch (e) { + return false; + } + + return true; +} + +function verifyFileContent(path, content) { + if (verifyFileExist(path)) { + return fs.readFileSync(file, {encoding: "UTF8"}) === content; + } else { + return false; + } +} + +function verifyFileContentJSON(path, content) { + if (verifyFileExist(path)) { + return assert.deepEqual(JSON.parse(fs.readFileSync(file, {encoding: "UTF8"})), content); + } else { + return false; + } +} + +function e2eTestEnvironmentCreation(obj) { + //Create Folders + for (var folder in obj) { + if (obj.hasOwnProperty(folder)) { + if (!verifyFileExist(path.join(__dirname, folder))) { + console.log("Create folder " + folder); + fs.mkdirSync(path.join(__dirname, folder)); + } + + for (var file in obj[folder]) { + if (obj[folder].hasOwnProperty(file)) { + if (file === "bower.json") { + obj[folder][file].name = folder; + if (!verifyFileExist(path.join(__dirname, folder, file))) { + console.log("Create file " + file + " in " + folder); + fs.writeFileSync(path.join(__dirname, folder, file), JSON.stringify(obj[folder][file].content)); + } + } else { + if (!verifyFileExist(path.join(__dirname, folder, file))) { + console.log("Create file " + file + " in " + folder); + fs.mkdirSync(path.join(__dirname, folder, file)); + } + } + } + } + } + } +} + +var cwd = path.join(__dirname, "..", "..", testFolders.folder); + +describe("Test file without file type folder", function() { + beforeEach(function(done) { + testFolders.test0.bowerJson.name = "test0"; + fs.remove(cwd, function(err) { + if (err) { + done(err); + } else { + fs.ensureDir(cwd, function(err) { + if (err) { + done(err); + } else { + fs.writeFile(path.join(cwd, "bower.json"), JSON.stringify(testFolders.test0.bowerJson), function(err) { + done(err); + }); + } + }); + } + }); + }); + + // TODO old test #00 + it("API", function(done) { + this.timeout(10000); + + cbi.install({cwd: cwd}).then( + function() { + expect(verifyFileExist(path.join(cwd, "bower_components/angular"))).equal(true); + expect(verifyFileExist(path.join(cwd, "dest/angular.js"))).equal(true); + done(); + }, + function(err) { + done(err); + } + ); + }); + + // TODO old test #07 + it("CLI", function(done) { + this.timeout(10000); + + exec("node ../../bin/clean-bower-installer -i --bower=\"../../.testFolder/tmp\"", function(err) { + if (err) { + done(err); + } else { + expect(verifyFileExist(path.join(cwd, "bower_components/angular"))).equal(true); + expect(verifyFileExist(path.join(cwd, "dest/angular.js"))).equal(true); + done(); + } + }); + }); +}); + +//describe("Test the verbose function at true", function() { +// beforeEach(function(done) { +// fs.remove(cwd, function(err) { +// if (err) { +// done(err); +// } else { +// fs.write(path.join(cwd, "bower.json"), testFolders.test1["bower.json"], function(err){ +// done(err); +// }); +// } +// }); +// }); +// +// it("API", function() { +// //TODO TEST that! +// }); +// +// it("CLI", function() { +// +// }); +//}); +// +//describe("Test the verbose function at false", function() { +// it("API", function() { +// +// }); +// +// it("CLI", function() { +// +// }); +//}); +// +//describe("Test the update method", function() { +// it("API", function() { +// +// }); +// +// it("CLI", function() { +// +// }); +//}); +// +//describe("Test the run method", function() { +// it("API", function() { +// +// }); +// +// it("CLI", function() { +// +// }); +//}); +// +//describe("Test the runMin method", function() { +// it("API", function() { +// +// }); +// +// it("CLI", function() { +// +// }); +//}); +// +//describe("Test the runMinR method", function() { +// it("API", function() { +// +// }); +// +// it("CLI", function() { +// +// }); +//}); +// +//describe("Test the removeAfter argument", function() { +// it("API", function() { +// +// }); +// +// it("CLI", function() { +// +// }); +//}); +// +//describe("Test the verbose override", function() { +// //it("", function(){ +// // +// //}); +// +// it("CLI", function() { +// +// }); +//}); +// +//describe("Test the file ignore", function() { +// it("API", function() { +// +// }); +// +// //it("", function(){ +// // +// //}); +//}); +// +//describe("Test without option", function() { +// it("API", function() { +// +// }); +// +// //it("", function(){ +// // +// //}); +//}); +// +//describe("Test the runMin method with default.minFolder", function() { +// it("API", function() { +// +// }); +// +// //it("", function(){ +// // +// //}); +//}); +// +//describe("Test the runMinR method", function() { +// //it("", function(){ +// // +// //}); +// +// it("CLI", function() { +// +// }); +//}); +// +//describe("Test the runMin method with default.minFolder", function() { +// it("API", function() { +// +// }); +// +// //it("", function(){ +// // +// //}); +//}); +// +////describe("", function() { +//// it("", function(){ +//// +//// }); +//// +//// it("", function(){ +//// +//// }); +////}); diff --git a/test/e2e/e2eData.test.js b/test/e2e/e2eData.test.js new file mode 100644 index 0000000..70af215 --- /dev/null +++ b/test/e2e/e2eData.test.js @@ -0,0 +1,201 @@ +var angularBower = { + "name": "", + "dependencies": { + "angular": "~1.3.20" + }, + "cInstall": { + "option": { + "default": { + "folder": "dest" + }, + "verbose": false + }, + "folder": {}, + "source": { + "angular": { + "angular.js": "angular.js" + } + } + } +}; + +var angularBower2 = { + "name": "", + "dependencies": { + "angular": "~1.3.0" + }, + "cInstall": { + "option": { + "default": { + "folder": "temp" + }, + "verbose": true + }, + "folder": {}, + "source": { + "angular": { + "angular.js": "angular.js" + } + } + } +}; + +var angularBower3 = { + "name": "", + "dependencies": { + "angular": "~1.3.0" + }, + "cInstall": { + "option": { + "default": { + "folder": "dest" + }, + "removeAfter": true + }, + "source": { + "angular": { + "angular.js": "angular.js" + } + } + } +}; + +var angularBower4 = { + "name": "", + "dependencies": { + "angular": "~1.3.0" + }, + "cInstall": { + "source": { + "angular": { + "angular.js": "angular.js" + } + } + } +}; + +var angularBower5 = { + "name": "", + "dependencies": { + "angular": "~1.3.0" + }, + "cInstall": { + "option": { + "default": { + "folder": "dest_Min" + } + }, + "source": { + "angular": { + "angular.js": "angular.js" + } + } + } +}; + +var angularBower6 = { + "name": "", + "dependencies": { + "angular": "~1.3.0" + }, + "cInstall": { + "option": { + "default": { + "folder": "dest_Min" + }, + "min": { + "get": true, + "rename": false + } + }, + "source": { + "angular": { + "angular.js": "angular.js" + } + } + } +}; + +var angularBower7 = { + "name": "", + "dependencies": { + "angular": "~1.3.0" + }, + "cInstall": { + "option": { + "default": { + "folder": "dest_Min" + }, + "min": { + "get": true, + "rename": true + } + }, + "source": { + "angular": { + "angular.js": "angular.js" + } + } + } +}; + +var bootstrapBower = { + "name": "", + "dependencies": { + "bootstrap": "~3.2.0" + }, + "cInstall": { + "folder": { + "js": "js/vendor/", + "css": "css/", + "otf, eot, svg, ttf, woff": "fonts/" + }, + "option": { + "default": { + "folder": "dest" + }, + "removeAfter": true + }, + "source": { + "bootstrap": { + "!": [ + "dist/fonts/*.svg" + ], + "glyphicons-halflings-regular.*": "dist/fonts/*", + "bootstrap.js": "dist/js/bootstrap.js", + "bootstrap.css": "dist/css/bootstrap.css", + "bootstrap.min.css": "dist/css/bootstrap.min.css" + } + } + } +}; + +var testFolders = { + "test0": { + bowerJson: angularBower + }, + "test1": { + bowerJson: angularBower2 + }, + "test2": { + bowerJson: angularBower3 + }, + "test3": { + bowerJson: bootstrapBower + }, + "test4": { + bowerJson: angularBower4 + }, + "test5": { + bowerJson: angularBower5 + }, + "test6": { + bowerJson: angularBower6 + }, + "test7": { + bowerJson: angularBower7 + }, + folder: ".testFolder/tmp" +}; + +module.exports = testFolders; diff --git a/test/unit/.jshintrc b/test/unit/.jshintrc index 5c8488f..fa3aba7 100644 --- a/test/unit/.jshintrc +++ b/test/unit/.jshintrc @@ -63,19 +63,5 @@ "wsh": false, "yui": false, "globals": { - "Notification": false, - "angular": false, - "describe": false, - "xdescribe": false, - "ddescribe": false, - "it": false, - "xit": false, - "iit": false, - "beforeEach": false, - "afterEach": false, - "before": false, - "after": false, - "pending": false, - "spyOn": false } } diff --git a/test/unit/lib/api.test.js b/test/unit/lib/api.test.js index e0c4730..1f8e173 100644 --- a/test/unit/lib/api.test.js +++ b/test/unit/lib/api.test.js @@ -2,30 +2,32 @@ var chai = require("chai"), expect = chai.expect, + describe = require("mocha/lib/mocha.js").describe, + it = require("mocha/lib/mocha.js").it, api = require("./../../../lib/api"); /** * Test /lib/api.js */ -describe("api", function () { +describe("api", function() { /** * Test the method "automatic" from the module api.js */ - describe("automatic", function () { + describe("automatic", function() { /** * Without Config object as configuration */ - it("wrong options", function (done) { + it("wrong options", function(done) { api.automatic("this is a wrong option").then( - function () { + function() { done("String pass as a accepted option but we want an object."); }, - function (err) { + function(err) { try { if (typeof err === "string" || err instanceof String) { - expect(err).to.contain("No bower.json file found in"); + expect(err).to.match(/No bower\.json file found in.*/); } else { - expect(err).to.be.an.instanceof(TypeError); + expect(err instanceof TypeError).to.equal(true); } done(); } catch (e) { @@ -44,7 +46,7 @@ describe("api", function () { done("This test is not suppose to pass, remove any bower.json file contained in the folder " + __dirname); }, function(e) { - expect(e).to.contain("No bower.json file found in"); + expect(e).to.match(/No bower\.json file found in.*/); done(); } ); @@ -74,15 +76,15 @@ describe("api", function () { */ it("wrong options", function(done) { api.install("this is a wrong option").then( - function () { + function() { done("String pass as a accepted option but we want an object."); }, - function (err) { + function(err) { try { if (typeof err === "string" || err instanceof String) { - expect(err).to.contain("No bower.json file found in"); + expect(err).to.match(/No bower\.json file found in.*/); } else { - expect(err).to.be.an.instanceof(TypeError); + expect(err instanceof TypeError).to.equal(true); } done(); } catch (e) { @@ -101,7 +103,7 @@ describe("api", function () { done("This test is not suppose to pass, remove any bower.json file contained in the folder " + __dirname); }, function(e) { - expect(e).to.contain("No bower.json file found in"); + expect(e).to.match(/No bower\.json file found in.*/); done(); } ); @@ -131,15 +133,15 @@ describe("api", function () { */ it("wrong options", function(done) { api.update("this is a wrong option").then( - function () { + function() { done("String pass as a accepted option but we want an object."); }, - function (err) { + function(err) { try { if (typeof err === "string" || err instanceof String) { - expect(err).to.contain("No bower.json file found in"); + expect(err).to.match(/^No bower\.json file found in.*/); } else { - expect(err).to.be.an.instanceof(TypeError); + expect(err instanceof TypeError).to.equal(true); } done(); } catch (e) { @@ -158,7 +160,7 @@ describe("api", function () { done("This test is not suppose to pass, remove any bower.json file contained in the folder " + __dirname); }, function(e) { - expect(e).to.contain("No bower.json file found in"); + expect(e).to.match(/No bower\.json file found in.*/); done(); } ); @@ -188,15 +190,15 @@ describe("api", function () { */ it("wrong options", function(done) { api.run("this is a wrong option").then( - function () { + function() { done("String pass as a accepted option but we want an object."); }, - function (err) { + function(err) { try { if (typeof err === "string" || err instanceof String) { - expect(err).to.contain("No bower.json file found in"); + expect(err).to.match(/^No bower\.json file found in.*/); } else { - expect(err).to.be.an.instanceof(TypeError); + expect(err instanceof TypeError).to.equal(true); } done(); } catch (e) { @@ -215,7 +217,7 @@ describe("api", function () { done("This test is not suppose to pass, remove any bower.json file contained in the folder " + __dirname); }, function(e) { - expect(e).to.contain("No bower.json file found in"); + expect(e).to.match(/^No bower\.json file found in.*/); done(); } ); @@ -245,12 +247,12 @@ describe("api", function () { */ it("wrong options", function(done) { api.runMin("this is a wrong option").then( - function () { + function() { done("String pass as a accepted option but we want an object."); }, - function (err) { + function(err) { try { - expect(err).to.be.an.instanceof(TypeError); + expect(err instanceof TypeError).to.equal(true); done(); } catch (e) { done(e); @@ -268,7 +270,7 @@ describe("api", function () { done("This test is not suppose to pass, remove any bower.json file contained in the folder " + __dirname); }, function(e) { - expect(e).to.contain("No bower.json file found in"); + expect(e).to.match(/^No bower\.json file found in.*/); done(); } ); @@ -298,12 +300,12 @@ describe("api", function () { */ it("wrong options", function(done) { api.runMinR("this is a wrong option").then( - function () { + function() { done("String pass as a accepted option but we want an object."); }, - function (err) { + function(err) { try { - expect(err).to.be.an.instanceof(TypeError); + expect(err instanceof TypeError).to.equal(true); done(); } catch (e) { done(e); @@ -321,7 +323,7 @@ describe("api", function () { done("This test is not suppose to pass, remove any bower.json file contained in the folder " + __dirname); }, function(e) { - expect(e).to.contain("No bower.json file found in"); + expect(e).to.match(/^No bower\.json file found in.*/); done(); } ); diff --git a/test/unit/lib/cmd.test.js b/test/unit/lib/cmd.test.js index 48ba036..59c63fd 100644 --- a/test/unit/lib/cmd.test.js +++ b/test/unit/lib/cmd.test.js @@ -2,6 +2,8 @@ var chai = require("chai"), expect = chai.expect, + describe = require("mocha/lib/mocha.js").describe, + it = require("mocha/lib/mocha.js").it, path = require("path"), cmd = require("./../../../lib/cmd"); @@ -58,7 +60,7 @@ describe("cmd", function() { function() { done("The script is not suppose to run with no bower.json file."); }, function(e) { - expect(e).to.contain("There is no bower.json file in"); + expect(e).to.match(/There is no bower\.json file in.*/); done(); } ); @@ -111,7 +113,7 @@ describe("cmd", function() { function() { done("The script is not suppose to run with no bower.json file."); }, function(e) { - expect(e).to.contain("There is no bower.json file in"); + expect(e).to.match(/There is no bower\.json file in.*/); done(); } ); @@ -164,7 +166,7 @@ describe("cmd", function() { function() { done("The script is not suppose to run with no bower.json file."); }, function(e) { - expect(e).to.contain("There is no bower.json file in"); + expect(e).to.match(/There is no bower\.json file in.*/); done(); } ); @@ -217,7 +219,7 @@ describe("cmd", function() { function() { done("The script is not suppose to run with no bower.json file."); }, function(e) { - expect(e).to.contain("There is no bower.json file in"); + expect(e).to.match(/There is no bower\.json file in.*/); done(); } ); diff --git a/test/unit/lib/fileManagement.test.js b/test/unit/lib/fileManagement.test.js index afac779..870fb9d 100644 --- a/test/unit/lib/fileManagement.test.js +++ b/test/unit/lib/fileManagement.test.js @@ -1,6 +1,8 @@ "use strict"; -var path = require("path"), +var describe = require("mocha/lib/mocha.js").describe, + it = require("mocha/lib/mocha.js").it, + path = require("path"), exec = require("child_process").exec, config = require("./../../../lib/readConfig"), fileManagement = require("./../../../lib/fileManagement"); diff --git a/test/unit/lib/fileSystem.test.js b/test/unit/lib/fileSystem.test.js index d558c13..a292675 100644 --- a/test/unit/lib/fileSystem.test.js +++ b/test/unit/lib/fileSystem.test.js @@ -2,8 +2,11 @@ var chai = require("chai"), expect = chai.expect, + describe = require("mocha/lib/mocha.js").describe, + it = require("mocha/lib/mocha.js").it, path = require("path"), - fileSystem = require("./../../../lib/fileSystem"); + fileSystem = require("./../../../lib/fileSystem"), + after = require("mocha/lib/mocha.js").after; // Legacy support var nodeVersion = process.versions.node.split("."); @@ -21,9 +24,9 @@ describe("fileSystem", function() { it("mkdirp", function(done) { var toCreate = path.join(tempFolder, "mkdirp/dept1/dept2"); fileSystem.mkdirp(toCreate, 511, function() { - expect(fileSystem.statSync(path.join(tempFolder, "mkdirp")).isDirectory()).to.be.true; - expect(fileSystem.statSync(path.join(tempFolder, "mkdirp/dept1")).isDirectory()).to.be.true; - expect(fileSystem.statSync(path.join(tempFolder, "mkdirp/dept1/dept2")).isDirectory()).to.be.true; + expect(fileSystem.statSync(path.join(tempFolder, "mkdirp")).isDirectory()).to.equal(true); + expect(fileSystem.statSync(path.join(tempFolder, "mkdirp/dept1")).isDirectory()).to.equal(true); + expect(fileSystem.statSync(path.join(tempFolder, "mkdirp/dept1/dept2")).isDirectory()).to.equal(true); done(); }); }); @@ -35,9 +38,9 @@ describe("fileSystem", function() { var toCreate = path.join(tempFolder, "mkdirpQ/dept1/dept2"); fileSystem.mkdirpQ(toCreate, 511).then( function() { - expect(fileSystem.statSync(path.join(tempFolder, "mkdirpQ")).isDirectory()).to.be.true; - expect(fileSystem.statSync(path.join(tempFolder, "mkdirpQ/dept1")).isDirectory()).to.be.true; - expect(fileSystem.statSync(path.join(tempFolder, "mkdirpQ/dept1/dept2")).isDirectory()).to.be.true; + expect(fileSystem.statSync(path.join(tempFolder, "mkdirpQ")).isDirectory()).to.equal(true); + expect(fileSystem.statSync(path.join(tempFolder, "mkdirpQ/dept1")).isDirectory()).to.equal(true); + expect(fileSystem.statSync(path.join(tempFolder, "mkdirpQ/dept1/dept2")).isDirectory()).to.equal(true); done(); }, function(e) { @@ -51,7 +54,7 @@ describe("fileSystem", function() { */ it("copy", function(done) { fileSystem.copy(__filename, path.join(tempFolder, "copy.js"), function() { - expect(fileSystem.statSync(path.join(tempFolder, "copy.js")).isFile()).to.be.true; + expect(fileSystem.statSync(path.join(tempFolder, "copy.js")).isFile()).to.equal(true); expect(fileSystem.readFileSync(path.join(tempFolder, "copy.js"), "utf8")).to.equal(fileSystem.readFileSync(__filename, "utf8")); done(); }); @@ -63,7 +66,7 @@ describe("fileSystem", function() { it("copyQ", function(done) { fileSystem.copyQ(__filename, path.join(tempFolder, "copyQ.js")).then( function() { - expect(fileSystem.statSync(path.join(tempFolder, "copyQ.js")).isFile()).to.be.true; + expect(fileSystem.statSync(path.join(tempFolder, "copyQ.js")).isFile()).to.equal(true); expect(fileSystem.readFileSync(path.join(tempFolder, "copyQ.js"), "utf8")).to.equal(fileSystem.readFileSync(__filename, "utf8")); done(); }, @@ -89,7 +92,7 @@ describe("fileSystem", function() { done("not suppose to pass because the folder were suppose to be deleted"); } catch (e) { if (legacy) { - expect(e).to.be.an.instanceof(TypeError); + expect(e instanceof TypeError).to.equal(true); } else { expect(e.code).to.equal("ENOENT"); } @@ -117,7 +120,7 @@ describe("fileSystem", function() { done("not suppose to pass because the folder were suppose to be deleted"); } catch (e) { if (legacy) { - expect(e).to.be.an.instanceof(TypeError); + expect(e instanceof TypeError).to.equal(true); } else { expect(e.code).to.equal("ENOENT"); } diff --git a/test/unit/lib/readConfig.test.js b/test/unit/lib/readConfig.test.js index 5e36320..5c855dd 100644 --- a/test/unit/lib/readConfig.test.js +++ b/test/unit/lib/readConfig.test.js @@ -2,6 +2,8 @@ var chai = require("chai"), expect = chai.expect, + describe = require("mocha/lib/mocha.js").describe, + it = require("mocha/lib/mocha.js").it, path = require("path"), config = require("./../../../lib/readConfig"); @@ -98,7 +100,7 @@ describe("readConfig", function() { config.read({cwd: ".temp/under/"}).then( function(conf) { try { - expect(conf).to.be.deep.equal(expected); + expect(conf).to.eql(expected); done(); } catch(e) { done(e);