From c2f9ecbb09c4c2ddec0ecf8b9ac0ecf10049f737 Mon Sep 17 00:00:00 2001 From: Freyskeyd Date: Fri, 30 Aug 2013 17:28:09 +0200 Subject: [PATCH] advanced test --- doctor/index.js | 102 ++++++++------- doctor/templates/somefile.js | 1 - install/index.js | 233 +++++++++++++++++------------------ test/test-_lib.js | 14 +-- test/test-doctor.js | 13 ++ test/test-down.js | 10 ++ test/test-install.js | 34 +++++ test/test-migrate.js | 10 ++ test/test-pool.js | 22 ++++ test/test-register.js | 16 +-- test/test-setup.js | 6 +- test/test-unregister.js | 21 ++++ test/test-up.js | 10 ++ 13 files changed, 299 insertions(+), 193 deletions(-) delete mode 100644 doctor/templates/somefile.js diff --git a/doctor/index.js b/doctor/index.js index 84ff617..c54baf3 100644 --- a/doctor/index.js +++ b/doctor/index.js @@ -1,51 +1,49 @@ 'use strict'; -var util = require('util'), +var util = require('util'), laraCFG = require('../_lib'), - _ = new laraCFG(), - yeoman = require('yeoman-generator'); + _ = new laraCFG(), + yeoman = require('yeoman-generator'); /** * Init YoLara CFG */ _.init(); - - var DoctorGenerator = module.exports = function DoctorGenerator(args, options, config) { - // By calling `NamedBase` here, we get the argument to the subgenerator call - // as `this.name`. - - - yeoman.generators.Base.apply(this, arguments); - /** - * Arguments - */ - this.argument('group', { type: String, required: false }); - this.argument('name', { type: String, required: false }); - - if (options.hasOwnProperty('verbose') && options.verbose) { - this.verbose = true; - } else { - this.verbose = false; + // By calling `NamedBase` here, we get the argument to the subgenerator call + // as `this.name`. + + yeoman.generators.Base.apply(this, arguments); + /** + * Arguments + */ + this.argument('group', { type: String, required: false }); + this.argument('name', { type: String, required: false }); + + if (options.hasOwnProperty('verbose') && options.verbose) { + this.verbose = true; + } else { + this.verbose = false; + } + + this.composer = false; + + this.logging = function (message, needed) { + if (this.verbose || needed) { + console.log(message); } - - this.composer = false; - - this.logging = function (message, needed) { - if (this.verbose || needed) { - console.log(message); - } - }; - this.info = function (message, force) { - if (this.verbose || force) { - this.log.info(message); - } - }; - this.conflict = function (message, force) { - if (this.verbose || force) { - this.log.conflict(message); - } - }; + }; + this.info = function (message, force) { + if (this.verbose || force) { + this.log.info(message); + } + }; + this.conflict = function (message, force) { + if (this.verbose || force) { + this.log.conflict(message); + } + }; + this.log.write('bisous'); }; util.inherits(DoctorGenerator, yeoman.generators.Base); @@ -53,17 +51,17 @@ util.inherits(DoctorGenerator, yeoman.generators.Base); DoctorGenerator.prototype.help = function help() { - var helpMessage = - '\n Usage:' + - '\n yo laravel:doctor [options]'.cyan + - '\n' + - '\n Options:' + - '\n --help '.cyan + '# Print this message' + - '\n --verbose '.cyan + '# More information'+ - '\n --all '.cyan + '# For all directory listed in all group'+ - '\n --group GROUPNAME '.cyan +'# For a particular group\n'; - - return helpMessage; + var helpMessage = + '\n Usage:' + + '\n yo laravel:doctor [options]'.cyan + + '\n' + + '\n Options:' + + '\n --help '.cyan + '# Print this message' + + '\n --verbose '.cyan + '# More information'+ + '\n --all '.cyan + '# For all directory listed in all group'+ + '\n --group GROUPNAME '.cyan +'# For a particular group\n'; + + return helpMessage; }; /** @@ -71,7 +69,7 @@ DoctorGenerator.prototype.help = function help() { * @return nil */ DoctorGenerator.prototype.existance = function existance() { - + }; /** @@ -86,7 +84,7 @@ DoctorGenerator.prototype.composerDiagnose = function composerDiagnose() { * Run migrate status * @return nil */ -DoctorGenerator.prototype.migrateStatus = function migrateStatus(){ +DoctorGenerator.prototype.migrateStatus = function migrateStatus() { }; @@ -94,6 +92,6 @@ DoctorGenerator.prototype.migrateStatus = function migrateStatus(){ * Run Grunt tests * @return nil */ -DoctorGenerator.prototype.gruntTests = function gruntTests(){ +DoctorGenerator.prototype.gruntTests = function gruntTests() { }; \ No newline at end of file diff --git a/doctor/templates/somefile.js b/doctor/templates/somefile.js deleted file mode 100644 index cc68fd3..0000000 --- a/doctor/templates/somefile.js +++ /dev/null @@ -1 +0,0 @@ -// This is a file copied by your subgenerator. diff --git a/install/index.js b/install/index.js index 0f1c3a4..7a8f023 100644 --- a/install/index.js +++ b/install/index.js @@ -4,151 +4,140 @@ var fs = require('fs'); var spawn = require('child_process').spawn; var rimraf = require('rimraf'); var chalk = require('chalk'); - var yeoman = require('yeoman-generator'); var InstallGenerator = module.exports = function InstallGenerator(args, options, config) { - // By calling `NamedBase` here, we get the argument to the subgenerator call - // as `this.name`. - if (!args.length) { args[0] = './'; } - yeoman.generators.NamedBase.apply(this, arguments); - - if (options.hasOwnProperty('verbose') && options.verbose) { - this.verbose = true; - } else { - this.verbose = false; + // By calling `NamedBase` here, we get the argument to the subgenerator call + // as `this.name`. + if (!args.length) { args[0] = './'; } + yeoman.generators.NamedBase.apply(this, arguments); + + if (options.hasOwnProperty('verbose') && options.verbose) { + this.verbose = true; + } else { + this.verbose = false; + } + + // TODO :: check last char is / + this.destinationRoot(this.name); + this.composer = false; + + this.logging = function (message, needed) { + if (this.verbose || needed) { + console.log(message); } - - // TODO :: check last char is / - this.destinationRoot(this.name); - this.composer = false; - - this.logging = function (message, needed) { - if (this.verbose || needed) { - console.log(message); - } - }; - this.info = function (message, force) { - if (this.verbose || force) { - this.log.info(message); - } - }; - this.conflict = function (message, force) { - if (this.verbose || force) { - this.log.conflict(message); - } - }; + }; + this.info = function (message, force) { + if (this.verbose || force) { + this.log.info(message); + } + }; + this.conflict = function (message, force) { + if (this.verbose || force) { + this.log.conflict(message); + } + }; }; - util.inherits(InstallGenerator, yeoman.generators.NamedBase); InstallGenerator.prototype.help = function help() { - var helpMessage = - chalk.white('\n Usage:') + - chalk.cyan('\n yo laravel:install DIRECTORY [options]') + - chalk.white('\n' + - '\n Options:') + - chalk.cyan('\n --help ') + chalk.white('# Print this message') + - chalk.cyan('\n --verbose ') + chalk.white('# More information\n'); + var helpMessage = + chalk.white('\n Usage:') + + chalk.cyan('\n yo laravel:install DIRECTORY [options]') + + chalk.white('\n' + + '\n Options:') + + chalk.cyan('\n --help ') + chalk.white('# Print this message') + + chalk.cyan('\n --verbose ') + chalk.white('# More information\n'); - return helpMessage; + return helpMessage; }; InstallGenerator.prototype.Clean = function clean() { - var cb = this.async(); - - - var prompts = [{ - name: 'answear', - type: 'confirm', - message: chalk.yellow('Are you sure about cleaning and installing in ') + this.name + chalk.yellow('?'), - default: 'Y' - }]; - - this.prompt(prompts, function (props) { - if (typeof props === 'undefined') {console.log('See ya'.green); - return false; - } - - if (props.answear) { - this.info('Start cleaning directory ('.cyan + this.name.cyan + ')'.cyan); - - var files = fs.readdirSync(this.name); - var self = this; - var iteratorElement = files.length; - - if (iteratorElement === 0) { - self.info('Cleaning done'.green); - cb(); - } - - var iterator = 0; - - - files.forEach(function (item) { - rimraf(self.name + item, function () { - iterator++; - self.info(item.yellow + ' Deleted'.red); - if (iterator >= iteratorElement) { self.logging('Cleaning done'.green); cb(); } - }); - }); - } else { - console.log('See ya'.green); - return false; - } - // this.logging('Check composer install'.cyan); - // this.logging('Composer is missing'.red, true); - // this.logging('Install with other method?'.yellow, true); - // this.logging('Composer has been found'.green); - // this.logging('Creating new project'); - // this.logging('Laravel has been init'); - - //cb(); - }.bind(this)); -}; + var cb = this.async(); + + var prompts = [{ + name: 'answear', + type: 'confirm', + message: chalk.yellow('Are you sure about cleaning and installing in ') + this.name + chalk.yellow('?'), + default: 'Y' + }]; + + this.prompt(prompts, function (props) { + if (typeof props === 'undefined') {console.log('See ya'.green); + return false; + } -InstallGenerator.prototype.checkComposer = function checkComposer() { - var cb = this.async(); + if (props.answear) { + this.info('Start cleaning directory ('.cyan + this.name.cyan + ')'.cyan); - this.info('Check composer install'.cyan); - var composer = spawn('composer'), - self = this; + var files = fs.readdirSync(this.name); + var self = this; + var iteratorElement = files.length; - composer.stdout.on('data', function () { - self.info('Composer has been found'.green); - self.composer = true; + if (iteratorElement === 0) { + self.info('Cleaning done'.green); cb(); - }); + } - composer.stderr.on('data', function () { - self.conflict('Composer is missing'.red, true); - // Composer doesn't exist - }); - return false; + var iterator = 0; + + + files.forEach(function (item) { + rimraf(self.name + item, function () { + iterator++; + self.info(item.yellow + ' Deleted'.red); + if (iterator >= iteratorElement) { self.logging('Cleaning done'.green); cb(); } + }); + }); + } else { + console.log('See ya'.green); + return false; + } + }.bind(this)); +}; + +InstallGenerator.prototype.checkComposer = function checkComposer() { + var cb = this.async(); + + this.info('Check composer install'.cyan); + var composer = spawn('composer'), + self = this; + + composer.stdout.on('data', function () { + self.info('Composer has been found'.green); + self.composer = true; + cb(); + }); + + composer.stderr.on('data', function () { + self.conflict('Composer is missing'.red, true); + // Composer doesn't exist + }); + return false; }; InstallGenerator.prototype.installComposer = function installComposer() { - if (this.composer) { - var composer = spawn('composer', ['create-project', 'laravel/laravel', this.name], {killSignal: 'SIGINT'}), - self = this; + if (this.composer) { + var composer = spawn('composer', ['create-project', 'laravel/laravel', '--prefer-dist', this.name], {killSignal: 'SIGINT'}), + self = this; - composer.stdout.on('data', function (data) { - self.info('composer : '.green + (data.toString().replace(/\n/g, ''))); - }); + composer.stdout.on('data', function (data) { + self.info('composer : '.green + (data.toString().replace(/\n/g, ''))); + }); - composer.stderr.on('data', function (data) { - self.conflict('Laravel error '.red + data, true); - // Composer doesn't exist - }); - composer.stderr.on('close', function (code) { - if (!code) { - self.info('Laravel installed '.green); - } else { - self.conflict('Laravel error '.red + code); - } - }); - } + composer.stderr.on('data', function (data) { + self.conflict('Laravel error '.red + data, true); + // Composer doesn't exist + }); + composer.stderr.on('close', function (code) { + if (!code) { + self.info('Laravel installed '.green); + } else { + self.conflict('Laravel error '.red + code); + } + }); + } }; \ No newline at end of file diff --git a/test/test-_lib.js b/test/test-_lib.js index 9920f93..ceb3632 100644 --- a/test/test-_lib.js +++ b/test/test-_lib.js @@ -17,12 +17,12 @@ describe('_lib', function () { _.removeCFGFile(done); }); - it('should return none empty config object after init', function (done) { + it('Should return none empty config object after init', function (done) { assert.ok(Object.getOwnPropertyNames(_.getCFG()).length > 0); done(); }); - it('should return a pool containing one path', function (done) { + it('Should return a pool containing one path', function (done) { _.addPathToPool('/usr/www/test', 'testPath', ''); _.addPathToPool('usr/www/test2', 'testPath', 'test/debug'); @@ -32,19 +32,19 @@ describe('_lib', function () { done(); }); - it('should remove a path containing in a pool', function (done) { + it('Should remove a path containing in a pool', function (done) { _.removePathFromPool('testPath2', 'test/debug'); done(); }); - it('should return a pool named test/debug', function (done) { + it('Should return a pool named test/debug', function (done) { var pool = _.poolByName('test/debug'); if (typeof pool === 'object') { done(); } }); - it('should return a path named testPath in test/debug pool', function (done) { + it('Should return a path named testPath in test/debug pool', function (done) { var path = _.pathByName('testPath', 'test/debug'); if (Object.prototype.toString.call(path) === '[object Array]') { @@ -52,7 +52,7 @@ describe('_lib', function () { } }); - it('should remove a pool named test/debug', function (done) { + it('Should remove a pool named test/debug', function (done) { _.removePool('test/debug'); var pool = _.poolByName('test/debug'); @@ -61,7 +61,7 @@ describe('_lib', function () { } }); - it('should add a pool to another pool', function (done) { + it('Should add a pool to another pool', function (done) { _.addPathToPool('~/usr/www/test3', 'testPath3', 'test/debug3/price'); _.addPathToPool('~/usr/www/test4', 'testPath4', 'test/debug3/qty'); diff --git a/test/test-doctor.js b/test/test-doctor.js index 8b638db..51e7d90 100644 --- a/test/test-doctor.js +++ b/test/test-doctor.js @@ -1,2 +1,15 @@ /*global describe, it, beforeEach */ 'use strict'; +require('should'); + +describe('doctor', function () { + it('Should return an array of invalid path', function (done) { + done(); + }); + it('Should return an array of valid path', function (done) { + done(); + }); + it('Should return status of migration for path/pool', function (done) { + done(); + }); +}); \ No newline at end of file diff --git a/test/test-down.js b/test/test-down.js index 8b638db..5eb96cf 100644 --- a/test/test-down.js +++ b/test/test-down.js @@ -1,2 +1,12 @@ /*global describe, it, beforeEach */ 'use strict'; +require('should'); + +describe('Down', function () { + it('Should return an array of valid path', function (done) { + done(); + }); + it('Should define path/pool has down', function (done) { + done(); + }); +}); \ No newline at end of file diff --git a/test/test-install.js b/test/test-install.js index 8b638db..bff9887 100644 --- a/test/test-install.js +++ b/test/test-install.js @@ -1,2 +1,36 @@ /*global describe, it, beforeEach */ 'use strict'; +require('should'); +var path = require('path'); +var helpers = require('yeoman-generator').test; + +describe('install', function () { + var laravel; + var folderName = 'APP'; + + beforeEach(function (done) { + var deps = [ + '../../app', + '../../install' + ]; + helpers.testDirectory(path.join(__dirname, folderName), function (err) { + if (err) { + done(err); + } + laravel = helpers.createGenerator('laravel:install', deps); + done(); + }); + }); + + it('Should return a correct path', function (done) { + done(); + }); + + it('Should return an existing path', function (done) { + done(); + }); + + it('Should clean the directory', function (done) { + done(); + }); +}); \ No newline at end of file diff --git a/test/test-migrate.js b/test/test-migrate.js index 8b638db..d8093e0 100644 --- a/test/test-migrate.js +++ b/test/test-migrate.js @@ -1,2 +1,12 @@ /*global describe, it, beforeEach */ 'use strict'; +require('should'); + +describe('migrate', function () { + it('Should return an array of valid path', function (done) { + done(); + }); + it('Should migrate a path/pool', function (done) { + done(); + }); +}); \ No newline at end of file diff --git a/test/test-pool.js b/test/test-pool.js index 8b638db..c5d3fcc 100644 --- a/test/test-pool.js +++ b/test/test-pool.js @@ -1,2 +1,24 @@ /*global describe, it, beforeEach */ 'use strict'; +require('should'); + +describe('pool', function () { + it('Should display a pool list', function (done) { + done(); + }); + it('Should display path list of a pool', function (done) { + done(); + }); + it('Should add a pool to another pool (Inceptionnnn)', function (done) { + done(); + }); + it('Should move a pool to another pool', function (done) { + done(); + }); + it('Should remove a path/pool from config file', function (done) { + done(); + }); + it('Should rename a path/pool', function (done) { + done(); + }); +}); \ No newline at end of file diff --git a/test/test-register.js b/test/test-register.js index 6228929..2c87195 100644 --- a/test/test-register.js +++ b/test/test-register.js @@ -11,42 +11,42 @@ describe('Register path', function () { _.init(done); }); - it('should register the current path with directory name in default pool', function (done) { + it('Should register the current path with directory name in default pool', function (done) { done(); }); - it('should register the current path with directory name in custom pool', function (done) { + it('Should register the current path with directory name in custom pool', function (done) { done(); }); - it('should register the current path with custom name in default pool', function (done) { + it('Should register the current path with custom name in default pool', function (done) { done(); }); - it('should register the current path with custom name in custom pool', function (done) { + it('Should register the current path with custom name in custom pool', function (done) { done(); }); - it('should register a path with directory name in default pool', function (done) { + it('Should register a path with directory name in default pool', function (done) { done(); }); - it('should register a path with directory name in custom pool', function (done) { + it('Should register a path with directory name in custom pool', function (done) { done(); }); - it('should register a path with custom name in default pool', function (done) { + it('Should register a path with custom name in default pool', function (done) { done(); }); - it('should register a path with custom name in custom pool', function (done) { + it('Should register a path with custom name in custom pool', function (done) { done(); }); diff --git a/test/test-setup.js b/test/test-setup.js index 955479e..927c409 100644 --- a/test/test-setup.js +++ b/test/test-setup.js @@ -10,17 +10,17 @@ describe('Setup the Yolara CFG', function () { _.init(done); }); - it('should setup a default configuration with true path', function (done) { + it('Should setup a default configuration with true path', function (done) { done(); }); - it('should setup a debug configuration with fake path', function (done) { + it('Should setup a debug configuration with fake path', function (done) { done(); }); - it('should run test with debug mode', function (done) { + it('Should run test with debug mode', function (done) { done(); }); diff --git a/test/test-unregister.js b/test/test-unregister.js index 8b638db..9026834 100644 --- a/test/test-unregister.js +++ b/test/test-unregister.js @@ -1,2 +1,23 @@ /*global describe, it, beforeEach */ 'use strict'; + +var laraCFG = require('../_lib'), + _ = {}; + +describe('Register path', function () { + + beforeEach(function (done) { + _ = new laraCFG(); + _.init(done); + }); + + it('Should unregister the current path', function (done) { + + done(); + }); + + it('Should unregister the poolpath', function (done) { + + done(); + }); +}); \ No newline at end of file diff --git a/test/test-up.js b/test/test-up.js index 8b638db..b804193 100644 --- a/test/test-up.js +++ b/test/test-up.js @@ -1,2 +1,12 @@ /*global describe, it, beforeEach */ 'use strict'; +require('should'); + +describe('Down', function () { + it('Should return an array of valid path', function (done) { + done(); + }); + it('Should define path/pool has up', function (done) { + done(); + }); +}); \ No newline at end of file