├── .gitattributes ├── app ├── templates │ ├── bowerrc │ ├── _src-browser.js │ ├── _bower.json │ ├── _src-node.js │ ├── editorconfig │ ├── jshintrc │ ├── _spec-browser.js │ ├── _package.json │ ├── _index.html │ └── _spec-node.js └── index.js ├── .gitignore ├── .editorconfig ├── test ├── test-load.js ├── test-node-assert.js ├── test-browser-creation.js └── test-node-creation.js ├── .jshintrc ├── LICENSE ├── package.json └── README.md /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | -------------------------------------------------------------------------------- /app/templates/bowerrc: -------------------------------------------------------------------------------- 1 | { 2 | "directory": "bower_components" 3 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ###Yeoman### 2 | 3 | node_modules/ 4 | bower_components/ 5 | *.log 6 | 7 | build/ 8 | dist/ 9 | temp/ 10 | -------------------------------------------------------------------------------- /app/templates/_src-browser.js: -------------------------------------------------------------------------------- 1 | /*! <%= algorithm %> v0.0.0 - MIT license */ 2 | 'use strict'; 3 | 4 | var <%= algorithm %> = function () { 5 | // your code goes here 6 | } 7 | -------------------------------------------------------------------------------- /app/templates/_bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "<%= algorithm %>", 3 | "private": true, 4 | "dependencies": {<% if (environment === "browser") { %> 5 | "chai": "~1.8.0", 6 | "mocha": "~1.14.0" 7 | <% } %>}, 8 | "devDependencies": {} 9 | } 10 | -------------------------------------------------------------------------------- /app/templates/_src-node.js: -------------------------------------------------------------------------------- 1 | /*! <%= algorithm %> v0.0.0 - MIT license */ 2 | 'use strict'; 3 | 4 | var <%= algorithm %> = function () { 5 | // your code goes here 6 | } 7 | 8 | if ( typeof module !== "undefined" ) { 9 | module.exports = <%= algorithm %>; 10 | } -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # http://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | indent_style = space 6 | indent_size = 2 7 | end_of_line = lf 8 | charset = utf-8 9 | trim_trailing_whitespace = true 10 | insert_final_newline = true 11 | 12 | [*.md] 13 | trim_trailing_whitespace = false 14 | -------------------------------------------------------------------------------- /app/templates/editorconfig: -------------------------------------------------------------------------------- 1 | # http://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | indent_style = space 6 | indent_size = 2 7 | end_of_line = lf 8 | charset = utf-8 9 | trim_trailing_whitespace = true 10 | insert_final_newline = true 11 | 12 | [*.md] 13 | trim_trailing_whitespace = false 14 | -------------------------------------------------------------------------------- /test/test-load.js: -------------------------------------------------------------------------------- 1 | /*global describe, beforeEach, it*/ 2 | 'use strict'; 3 | 4 | var assert = require('assert'); 5 | 6 | describe('test generator', function () { 7 | it('can be imported without blowing up', function () { 8 | var app = require('../app'); 9 | assert(app !== undefined); 10 | }); 11 | }); 12 | -------------------------------------------------------------------------------- /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "node": true, 3 | "esnext": true, 4 | "bitwise": true, 5 | "camelcase": true, 6 | "curly": true, 7 | "eqeqeq": true, 8 | "immed": true, 9 | "indent": 2, 10 | "latedef": true, 11 | "newcap": true, 12 | "noarg": true, 13 | "quotmark": "single", 14 | "regexp": true, 15 | "undef": true, 16 | "unused": true, 17 | "strict": true, 18 | "trailing": true, 19 | "smarttabs": true, 20 | "white": true 21 | } 22 | -------------------------------------------------------------------------------- /app/templates/jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "node": true, 3 | "esnext": true, 4 | "bitwise": true, 5 | "camelcase": true, 6 | "curly": true, 7 | "eqeqeq": true, 8 | "immed": true, 9 | "indent": 2, 10 | "latedef": true, 11 | "newcap": true, 12 | "noarg": true, 13 | "quotmark": "single", 14 | "regexp": true, 15 | "undef": true, 16 | "unused": true, 17 | "strict": true, 18 | "trailing": true, 19 | "smarttabs": true, 20 | "white": true 21 | } 22 | -------------------------------------------------------------------------------- /app/templates/_spec-browser.js: -------------------------------------------------------------------------------- 1 | /* global <%= algorithm %>, describe, it, expect, should */ 2 | 3 | describe('<%= algorithm %>()', function () { 4 | 'use strict'; 5 | 6 | it('exists', function () { 7 | expect(<%= algorithm %>).to.be.a('function'); 8 | 9 | }); 10 | 11 | it('does something', function () { 12 | expect(true).to.equal(false); 13 | }); 14 | 15 | it('does something else', function () { 16 | expect(true).to.equal(false); 17 | }); 18 | 19 | // Add more assertions here 20 | }); 21 | -------------------------------------------------------------------------------- /app/templates/_package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "<%= algorithm %>", 3 | "private": true, 4 | "version": "0.0.0", 5 | "devDependencies": {<% if (environment === "Node") { %> 6 | <% switch( assertstyle ) { 7 | case "expect": %> 8 | "chai": "~1.8.0", 9 | <% break; 10 | case "should": %> 11 | "should": "^7.1.1", 12 | <% break; 13 | } %> 14 | "mocha":"2.0.1" 15 | <% } %>}, 16 | "scripts": {<% if (environment === "Node") { %> 17 | "test": "mocha ./spec/<%= file %>" 18 | <% } %>} 19 | } 20 | -------------------------------------------------------------------------------- /app/templates/_index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Mocha Spec Runner 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2014 Phillip Alexander 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "generator-test", 3 | "version": "2.0.2", 4 | "description": "Yeoman based generator that creates a simple mocha/chai TDD scaffold for solving algorithms", 5 | "keywords": [ 6 | "yeoman-generator", 7 | "algorithms", 8 | "mocha", 9 | "TDD", 10 | "chai" 11 | ], 12 | "homepage": "https://github.com/phillipalexander/generator-test", 13 | "bugs": "https://github.com/phillipalexander/generator-test/issues", 14 | "author": { 15 | "name": "Phillip Alexander", 16 | "email": "git@phillipalexander.io", 17 | "url": "https://github.com/phillipalexander" 18 | }, 19 | "main": "app/index.js", 20 | "repository": { 21 | "type": "git", 22 | "url": "git://github.com/phillipalexander/generator-test.git" 23 | }, 24 | "scripts": { 25 | "test": "mocha" 26 | }, 27 | "dependencies": { 28 | "yeoman-generator": "^0.17" 29 | }, 30 | "devDependencies": { 31 | "mocha": "~1.14.0", 32 | "chai": "~3.4.0" 33 | }, 34 | "peerDependencies": { 35 | "yo": ">=1.4.8" 36 | }, 37 | "engines": { 38 | "node": ">=0.8.0", 39 | "npm": ">=1.2.10" 40 | }, 41 | "licenses": [ 42 | { 43 | "type": "MIT" 44 | } 45 | ] 46 | } 47 | -------------------------------------------------------------------------------- /app/templates/_spec-node.js: -------------------------------------------------------------------------------- 1 | var path = require('path'); 2 | <% switch(assertstyle) { 3 | case "expect": 4 | %> 5 | var expect = require('chai').expect; 6 | <% break; 7 | case "should": 8 | %> 9 | var should = require('should'); 10 | <% break; } %> 11 | 12 | var <%= algorithm %> = require(path.join(__dirname, '..', './<%= algorithm %>.js')); 13 | 14 | describe('<%= algorithm %>()', function () { 15 | 'use strict'; 16 | 17 | it('exists', function () { 18 | <% switch( assertstyle ) { 19 | case "expect": %> 20 | expect(<%= algorithm %>).to.be.a('function'); 21 | <% break; 22 | case "should":%> 23 | (typeof <%= algorithm %>).should.not.equal('function'); 24 | <% break; } %> 25 | }); 26 | 27 | it('does something', function () { 28 | <% switch( assertstyle ) { 29 | case "expect": %> 30 | expect(true).to.equal(false); 31 | <% break; 32 | case "should":%> 33 | true.should.not.be.ok(); 34 | <% break; } %> 35 | }); 36 | 37 | it('does something else', function () { 38 | <% switch( assertstyle ) { 39 | case "expect": %> 40 | expect(true).to.equal(false); 41 | <% break; 42 | case "should":%> 43 | true.should.not.be.ok(); 44 | <% break; } %> 45 | }); 46 | 47 | // Add more assertions here 48 | }); 49 | -------------------------------------------------------------------------------- /test/test-node-assert.js: -------------------------------------------------------------------------------- 1 | /*global describe, beforeEach, it*/ 2 | 'use strict'; 3 | 4 | var path = require('path'); 5 | var fs = require('fs'); 6 | var yeoman = require('yeoman-generator'); 7 | var helpers = yeoman.test; 8 | var assert = yeoman.assert; 9 | 10 | var expectedFiles = ['package.json']; 11 | var unexpectedFiles = ['bower.json', '.bowerrc']; 12 | 13 | describe('test assertion selector', function () { 14 | 15 | it('should generate a test using should style', function (done) { 16 | helpers.run(path.join(__dirname, '../app')) 17 | .inDir(path.join(__dirname, './temp')) 18 | .withOptions({ 19 | 'skip-install': true 20 | }) 21 | .withPrompt({ 22 | 'environment': 'Node', 23 | 'algorithm': 'algorithm', 24 | 'assertstyle': 'should' 25 | }) 26 | .on('end', function () { 27 | var expected = expectedFiles.concat([ 28 | 'spec/algorithm.js', 29 | 'algorithm.js' 30 | ]); 31 | assert.file(expected); 32 | assert.noFile(unexpectedFiles); 33 | assert.fileContent('algorithm.js', /module\.exports = algorithm/); 34 | assert.fileContent('./spec/algorithm.js', /require/); 35 | assert.fileContent('package.json', /should/); 36 | assert.fileContent('./spec/algorithm.js', /should/); 37 | done(); 38 | }); 39 | }); 40 | 41 | it('should generate a test using expect style', function (done) { 42 | helpers.run(path.join(__dirname, '../app')) 43 | .inDir(path.join(__dirname, './temp')) 44 | .withOptions({ 45 | 'skip-install': true 46 | }) 47 | .withPrompt({ 48 | 'environment': 'Node', 49 | 'algorithm': 'algorithm', 50 | 'assertstyle': 'expect' 51 | }) 52 | .on('end', function () { 53 | var expected = expectedFiles.concat([ 54 | 'spec/algorithm.js', 55 | 'algorithm.js' 56 | ]); 57 | assert.file(expected); 58 | assert.noFile(unexpectedFiles); 59 | assert.fileContent('algorithm.js', /module\.exports = algorithm/); 60 | assert.fileContent('./spec/algorithm.js', /require/); 61 | assert.fileContent('package.json', /chai/); 62 | assert.fileContent('./spec/algorithm.js', /expect/); 63 | done(); 64 | }); 65 | }); 66 | }); 67 | -------------------------------------------------------------------------------- /test/test-browser-creation.js: -------------------------------------------------------------------------------- 1 | /*global describe, beforeEach, it*/ 2 | 'use strict'; 3 | 4 | var path = require('path'); 5 | var fs = require('fs'); 6 | var yeoman = require('yeoman-generator'); 7 | var helpers = yeoman.test; 8 | var assert = yeoman.assert; 9 | 10 | var expectedFiles = ['.bowerrc', 'bower.json', 'index.html']; 11 | var unexpectedFiles = ['package.json']; 12 | 13 | 14 | describe('test browser generator', function () { 15 | 16 | // ----------------------------------------------------------------------------- 17 | // Test behavior when there are not pre-existing js files. 18 | // ----------------------------------------------------------------------------- 19 | it('creates expected files when no .js files exist', function (done) { 20 | helpers.run(path.join(__dirname, '../app')) 21 | .inDir(path.join(__dirname, './temp')) 22 | .withOptions({ 23 | 'skip-install': true 24 | }) 25 | .withPrompt({ 26 | 'environment': 'browser', 27 | 'algorithm': 'algorithm' 28 | }) 29 | .on('end', function () { 30 | var expected = expectedFiles.concat([ 31 | 'spec/algorithm.js', 32 | 'algorithm.js' 33 | ]); 34 | assert.file(expected); 35 | assert.fileContent('algorithm.js', /var algorithm = function ()/); 36 | assert.fileContent('bower.json', /chai/); 37 | assert.noFileContent('./spec/algorithm.js', /require/); 38 | done(); 39 | }); 40 | }); 41 | 42 | it('leaves existing files intact when they exist', function (done) { 43 | helpers.run(path.join(__dirname, '../app')) 44 | .inDir(path.join(__dirname, './temp')) 45 | .withOptions({ 46 | 'skip-install': true 47 | }) 48 | .withPrompt({ 49 | 'environment': 'browser', 50 | 'file': 'myAlgo.js' 51 | }) 52 | .on('ready', function (generator) { 53 | var js = "var myAlgo = function () { return { method: function () {} }; };"; 54 | fs.writeFileSync(path.join(__dirname, './temp/myAlgo.js'), js); 55 | }) 56 | .on('end', function () { 57 | var expected = expectedFiles.concat([ 58 | 'spec/myAlgo.js', 59 | 'myAlgo.js' 60 | ]); 61 | assert.file(expected); 62 | assert.fileContent('myAlgo.js', /myAlgo/); 63 | assert.noFileContent('./spec/myAlgo.js', /require/); 64 | assert.fileContent('bower.json', /chai/); 65 | // doesn't work as expected; figure out a better way to do this. 66 | // eval(fs.readFileSync(path.join(__dirname, './temp/myAlgo.js'), 'utf8')); 67 | // assert.implement(myAlgo(), ['method']); 68 | done(); 69 | }); 70 | }); 71 | 72 | }); 73 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # generator-test [![Circle CI](https://circleci.com/gh/phillipalexander/generator-test.png?style=badge)](https://circleci.com/gh/phillipalexander/generator-test) 2 | 3 | A simple generator for [Yeoman](http://yeoman.io) that makes it easy to start writing [unit tests](http://en.wikipedia.org/wiki/Unit_testing) and use Test Driven Development (TDD) while you karate-chop your way through algorithm-based programming challenges. 4 | 5 | 6 | ## Introduction 7 | 8 | ### What's Yeoman? 9 | 10 | From wikipedia: 11 | > Yeoman is an open source client-side development stack, consisting of tools and frameworks intended to help developers quickly build high quality web applications. Yeoman runs as a command-line interface written in Node.js which combines several functions into one place, such as generating a starter template, managing dependencies, running unit tests, providing a local development server, and optimizing production code for deployment. 12 | 13 | ### Generators 14 | 15 | After installing Yeoman, you'll use generators to scaffold out specific types of applications. A generator is basically a plugin that can be run with the `yo` command to scaffold complete projects or useful parts. Examining the architectures that popular (well-built) generators produce is a fantastic way to learn how well-established software engineers think about structuring their applications. There are generators that help you scaffold out applications built in [Angular](https://github.com/DaftMonk/generator-angular-fullstack), [Backbone](https://github.com/yeoman/generator-backbone), as [Chrome Extentions](https://github.com/yeoman/generator-chrome-extension), and pretty much [anything else you can imagine](http://yeoman.io/generators/). 16 | 17 | ## Installation 18 | 19 | ### Yeoman 20 | 21 | 22 | Install Yeoman with, 23 | 24 | ``` 25 | $ npm install -g yo 26 | ``` 27 | 28 | ### Generator-Test 29 | 30 | 31 | Then install generator-test from npm: 32 | 33 | ``` 34 | $ npm install -g generator-test 35 | ``` 36 | 37 | cd to (or create) your project directory, then initiate the generator: 38 | 39 | ``` 40 | $ yo test 41 | ``` 42 | 43 | ### Usage 44 | 45 | When invoked, this generator gives the option of creating a testing scaffold designed to be run in the browser, or one designed to be run with Node. 46 | 47 | #### Browser 48 | 49 | If you select 'browser' when prompted, A simple mocha/chai TDD scaffold for your algorithm solution with the following folder structure will be created: 50 | 51 | ``` bash 52 | solution 53 | ├── bower.json 54 | ├── bower_components 55 | │   ├── chai 56 | │   └── mocha 57 | ├── index.html 58 | ├── spec 59 | │   └── algorithm.js 60 | └── algorithm.js 61 | ``` 62 | 63 | After runnning the generator in browser mode, run the tests by opening `index.html`. 64 | 65 | #### Node 66 | 67 | If you select 'Node' when prompted, you will be prompted to choose the assert style to use: expect or should. A simple mocha/{chai.expect|should.js} TDD scaffold for your algorithm solution with the following folder structure will be created: 68 | 69 | ``` bash 70 | solution 71 | ├── node_modules 72 | │   └── {chai|should} 73 | ├── package.json 74 | ├── spec 75 | │   └── algorithm.js 76 | └── algorithm.js 77 | ``` 78 | 79 | After running the generator in Node mode, run the tests via `npm test`. 80 | 81 | ### Wrapping Up 82 | 83 | If the current working directory already contains any JavaScript files, then you'll be asked which of them you wish to write tests for. If there are no js files present, a starter file will be generated for you. 84 | 85 | Write additional tests in the file created in the `/spec` dir, and your algorithm in the file in the current dir. 86 | 87 | 88 | ## License 89 | 90 | [MIT License](http://en.wikipedia.org/wiki/MIT_License) 91 | -------------------------------------------------------------------------------- /app/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | var util = require('util'); 3 | var path = require('path'); 4 | var yeoman = require('yeoman-generator'); 5 | var fs = require('fs'); 6 | 7 | 8 | var TestGenerator = module.exports = function TestGenerator(args, options, config) { 9 | yeoman.generators.Base.apply(this, arguments); 10 | 11 | this.argument('appname', { type: String, required: false }); 12 | this.appname = this.appname || path.basename(process.cwd()); 13 | this.appname = this._.camelize(this._.slugify(this._.humanize(this.appname))); 14 | 15 | this.on('end', function () { 16 | // this.installDependencies({ skipInstall: options['skip-install'] }); 17 | this.installDependencies({ 18 | npm: this.environment === 'Node' ? true : false, 19 | bower: this.environment === 'browser' ? true : false, 20 | skipInstall: options['skip-install'], 21 | callback: function() { 22 | console.log('Everything is ready!'); 23 | } 24 | }); 25 | }); 26 | 27 | 28 | this.pkg = JSON.parse(this.readFileAsString(path.join(__dirname, '../package.json'))); 29 | }; 30 | 31 | util.inherits(TestGenerator, yeoman.generators.Base); 32 | 33 | TestGenerator.prototype.askFor = function askFor() { 34 | var cb = this.async(); 35 | 36 | // have Yeoman greet the user. 37 | console.log(this.yeoman); 38 | 39 | var allFiles = fs.readdirSync(process.cwd()); 40 | var prompts = []; 41 | 42 | var jsFiles = allFiles.filter( function( file ) { 43 | return file.substr(file.length - 3) === '.js'; 44 | }); 45 | 46 | prompts.push({ 47 | type: 'list', 48 | name: 'environment', 49 | message: 'Do you want to test your algorithm in the browser or with Node?', 50 | choices: ['Node', 'browser'], 51 | default: 'browser' 52 | }); 53 | 54 | prompts.push({ 55 | when: function(answers) { return answers.environment === 'Node'; }, 56 | type: 'list', 57 | name: 'assertstyle', 58 | message: 'Which assertion style do you want to use?', 59 | choices: ['expect', 'should'], 60 | default: 'expect' 61 | }); 62 | 63 | if (jsFiles.length === 0) { 64 | prompts.push({ 65 | name: 'algorithm', 66 | message: 'Please enter a name for the algorithm you\'d like to test', 67 | default: this.appname 68 | }); 69 | } else { 70 | prompts.push({ 71 | type: 'list', 72 | name: 'file', 73 | message: 'Hey, I found js files in this directory. Which one contains the algorithm you\'d like to test?', 74 | choices: jsFiles 75 | }); 76 | } 77 | 78 | this.prompt(prompts, function (response) { 79 | this.file = response.file || response.algorithm + '.js'; 80 | this.algorithm = response.algorithm || response.file.split('.')[0]; 81 | this.environment = response.environment || 'browser'; 82 | this.assertstyle = response.assertstyle || "expect"; 83 | cb(); 84 | }.bind(this)); 85 | }; 86 | 87 | TestGenerator.prototype.app = function projectFiles() { 88 | var fileExists = fs.existsSync(path.resolve(process.cwd(), this.file)); 89 | 90 | // scaffold out the tests based on env 91 | if (this.environment === 'Node') { 92 | this.template('_spec-node.js', 'spec/' + this.file); 93 | this.template('_package.json', 'package.json'); 94 | } else if (this.environment === 'browser') { 95 | this.template('_index.html', 'index.html'); 96 | this.template('_spec-browser.js', 'spec/' + this.file); 97 | this.template('_bower.json', 'bower.json'); 98 | this.copy('bowerrc', '.bowerrc'); 99 | } 100 | 101 | // Create the src file if one doesn't already exist 102 | if (!fileExists) { 103 | this.template((this.environment === 'Node' ? '_src-node.js' : '_src-browser.js'), this.file); 104 | } 105 | 106 | // this.copy('editorconfig', '.editorconfig'); 107 | // this.copy('jshintrc', '.jshintrc'); 108 | }; 109 | -------------------------------------------------------------------------------- /test/test-node-creation.js: -------------------------------------------------------------------------------- 1 | /*global describe, beforeEach, it*/ 2 | 'use strict'; 3 | 4 | var path = require('path'); 5 | var fs = require('fs'); 6 | var yeoman = require('yeoman-generator'); 7 | var helpers = yeoman.test; 8 | var assert = yeoman.assert; 9 | 10 | var expectedFiles = ['package.json']; 11 | var unexpectedFiles = ['bower.json', '.bowerrc']; 12 | 13 | describe('test node generator', function () { 14 | 15 | // ----------------------------------------------------------------------------- 16 | // Test behavior when there are not pre-existing js files. 17 | // ----------------------------------------------------------------------------- 18 | it('creates expected files when no .js files exist', function (done) { 19 | helpers.run(path.join(__dirname, '../app')) 20 | .inDir(path.join(__dirname, './temp')) 21 | .withOptions({ 22 | 'skip-install': true 23 | }) 24 | .withPrompt({ 25 | 'environment': 'Node', 26 | 'algorithm': 'algorithm', 27 | 'assertstyle': 'expect' 28 | }) 29 | .on('end', function () { 30 | var expected = expectedFiles.concat([ 31 | 'spec/algorithm.js', 32 | 'algorithm.js' 33 | ]); 34 | assert.file(expected); 35 | assert.noFile(unexpectedFiles); 36 | assert.fileContent('algorithm.js', /module\.exports = algorithm/); 37 | assert.fileContent('./spec/algorithm.js', /require/); 38 | assert.fileContent('package.json', /chai/); 39 | assert.fileContent('package.json', /devDependencies/); 40 | done(); 41 | }); 42 | }); 43 | 44 | it('leaves existing files intact when they exist', function (done) { 45 | helpers.run(path.join(__dirname, '../app')) 46 | .inDir(path.join(__dirname, './temp')) 47 | .withOptions({ 48 | 'skip-install': true 49 | }) 50 | .withPrompt({ 51 | 'environment': 'Node', 52 | 'file': 'myAlgo.js', 53 | 'assertstyle': 'expect' 54 | }) 55 | .on('ready', function (generator) { 56 | var js = "var myAlgo = function () { return { method: function () {} }; }; module.exports = myAlgo;"; 57 | fs.writeFileSync(path.join(__dirname, './temp/myAlgo.js'), js); 58 | }) 59 | .on('end', function () { 60 | var expected = expectedFiles.concat([ 61 | 'spec/myAlgo.js', 62 | 'myAlgo.js' 63 | ]); 64 | assert.file(expected); 65 | assert.noFile(unexpectedFiles); 66 | assert.fileContent('myAlgo.js', /myAlgo/); 67 | assert.fileContent('./spec/myAlgo.js', /require/); 68 | assert.fileContent('package.json', /chai/); 69 | assert.fileContent('package.json', /devDependencies/); 70 | assert.implement(require('./temp/myAlgo.js')(), ['method']); 71 | done(); 72 | }); 73 | }); 74 | 75 | it('runs the generated test file in node using npm test + expect style assertions', function (done) { 76 | helpers.run(path.join(__dirname, '../app')) 77 | .inDir(path.join(__dirname, './temp')) 78 | .withOptions({ 79 | 'skip-install': true 80 | }) 81 | .withPrompt({ 82 | 'environment': 'Node', 83 | 'file': 'myAlgo.js', 84 | 'assertstyle': 'expect' 85 | }) 86 | .on('ready', function (generator) { 87 | var js = "var myAlgo = function () { return { method: function () {} }; }; module.exports = myAlgo;"; 88 | fs.writeFileSync(path.join(__dirname, './temp/myAlgo.js'), js); 89 | }) 90 | .on('end', function () { 91 | var expected = expectedFiles.concat([ 92 | 'spec/myAlgo.js', 93 | 'myAlgo.js' 94 | ]); 95 | assert.fileContent('package.json', /test/); 96 | done(); 97 | }); 98 | }); 99 | 100 | it('runs the generated test file in node using npm test + should style assertions', function (done) { 101 | helpers.run(path.join(__dirname, '../app')) 102 | .inDir(path.join(__dirname, './temp')) 103 | .withOptions({ 104 | 'skip-install': true 105 | }) 106 | .withPrompt({ 107 | 'environment': 'Node', 108 | 'file': 'myAlgo.js', 109 | 'assertstyle': 'should' 110 | }) 111 | .on('ready', function (generator) { 112 | var js = "var myAlgo = function () { return { method: function () {} }; }; module.exports = myAlgo;"; 113 | fs.writeFileSync(path.join(__dirname, './temp/myAlgo.js'), js); 114 | }) 115 | .on('end', function () { 116 | var expected = expectedFiles.concat([ 117 | 'spec/myAlgo.js', 118 | 'myAlgo.js' 119 | ]); 120 | assert.fileContent('package.json', /test/); 121 | done(); 122 | }); 123 | }); 124 | 125 | }); 126 | --------------------------------------------------------------------------------