diff --git a/tim/.gitignore b/tim/.gitignore new file mode 100644 index 0000000..3c3629e --- /dev/null +++ b/tim/.gitignore @@ -0,0 +1 @@ +node_modules diff --git a/tim/gulpfile.js b/tim/gulpfile.js new file mode 100644 index 0000000..ad674db --- /dev/null +++ b/tim/gulpfile.js @@ -0,0 +1,30 @@ +var gulp = require('gulp'); +var jshint = require('gulp-jshint'); +var mocha = require('gulp-mocha'); +var appFiles = ['index.js', 'lib/**/*.js', 'bin/**/*.js' ]; +var testFiles = ['test/**/*.js']; + +gulp.task('watch', function() { + gulp.watch(['lib/**', 'test/**', 'gulpfile.js'], ['default']); +}); + +gulp.task('jshint:test', function() { + return gulp.src(testFiles) + .pipe(jshint.reporter('default')); +}); + +gulp.task('jshint:greet', function() { + return gulp.src(testFiles) + .pipe(jshint.reporter('default')); +}); + +// To implement mocha test +gulp.task('mocha:test', function() { + return gulp.src('./test/*.js', {read: false}) + + .pipe(mocha({reporter: 'nyan'})); +}); + +gulp.task('mocha', ['mocha:test']); +gulp.task('jshint', ['jshint:test', 'jshint:greet']); +gulp.task('default', ['jshint', 'mocha']); diff --git a/tim/lib/greet.js b/tim/lib/greet.js new file mode 100644 index 0000000..36d07c0 --- /dev/null +++ b/tim/lib/greet.js @@ -0,0 +1,9 @@ + +exports.greeting = function(name) { + console.log(arguments); + name = name || process.argv[2]; + return 'word ' + name + '!'; +}; + +console.log(exports.greeting("tim")); + diff --git a/tim/myPref.jshintrc b/tim/myPref.jshintrc new file mode 100644 index 0000000..b645297 --- /dev/null +++ b/tim/myPref.jshintrc @@ -0,0 +1,4 @@ +{ + "node": true, + "predef": ["describe", "it", "before", "after"] +} diff --git a/tim/package.json b/tim/package.json new file mode 100644 index 0000000..1666186 --- /dev/null +++ b/tim/package.json @@ -0,0 +1,29 @@ +{ + "name": "greet", + "version": "0.1.0", + "description": "A super awesome app used greet people!", + "main": "index.js", + "scripts": { + "test": "./node_modules/gulp/bin/gulp.js" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/timcmiller/simple-test-and-modular-patterns.git" + }, + "keywords": [ + "greet" + ], + "author": "Tim Miller", + "license": "MIT", + "bugs": { + "url": "https://github.com/timcmiller/simple-test-and-modular-patterns/issues" + }, + "homepage": "https://github.com/timcmiller/simple-test-and-modular-patterns#readme", + "devDependencies": { + "chai": "3.4.0", + "gulp": "^3.9.0", + "gulp-jshint": "^1.11.2", + "gulp-mocha": "^2.1.3", + "mocha": "2.3.3" + } +} diff --git a/tim/test/test_greet.js b/tim/test/test_greet.js new file mode 100644 index 0000000..26afb73 --- /dev/null +++ b/tim/test/test_greet.js @@ -0,0 +1,28 @@ +#!/usr/bin/env node +var expect = require('chai').expect; +var greet = require(__dirname + '/../lib/greet'); + +describe('the greet function', function() { + + it('should greet someone by name', function() { + expect(greet.greeting('tim')).to.eql('word tim!'); + }); + + describe('calling this funciton through node', function() { + + before(function() { + this.backup = process.argv; + process.argv = ['node', 'myfile', 'test name']; + + }); + + after(function() { + process.argv = this.backup; + }); + + it('should pull from process.argv', function() { + expect(greet.greeting()).eql('word test name!'); + }); + }); + +});