From 4364a11871822f97c1400c129494f35d7f9e0ead Mon Sep 17 00:00:00 2001 From: Adam Stelle Date: Tue, 13 Sep 2016 15:17:26 -0700 Subject: [PATCH 1/3] Complete assignment & bonus --- lab-adam/.eslintrc | 24 +++++++++++ lab-adam/.gitignore | 86 +++++++++++++++++++++++++++++++++++++ lab-adam/app.js | 6 +++ lab-adam/gulpfile.js | 27 ++++++++++++ lab-adam/lib/greet.js | 11 +++++ lab-adam/package.json | 23 ++++++++++ lab-adam/test/greet-test.js | 25 +++++++++++ 7 files changed, 202 insertions(+) create mode 100644 lab-adam/.eslintrc create mode 100644 lab-adam/.gitignore create mode 100644 lab-adam/app.js create mode 100644 lab-adam/gulpfile.js create mode 100644 lab-adam/lib/greet.js create mode 100644 lab-adam/package.json create mode 100644 lab-adam/test/greet-test.js diff --git a/lab-adam/.eslintrc b/lab-adam/.eslintrc new file mode 100644 index 0000000..86e3575 --- /dev/null +++ b/lab-adam/.eslintrc @@ -0,0 +1,24 @@ +{ + "rules": { + "comma-dangle": ["error", "always-multiline"], + "no-console": "off", + "indent": [ "error", 2 ], + "quotes": [ "error", "single" ], + "semi": ["error", "always"], + "linebreak-style": [ "error", "unix" ] + }, + "env": { + "es6": true, + "node": true, + "mocha": true, + "jasmine": true + }, + "globals": { + }, + "ecmaFeatures": { + "modules": true, + "experimentalObjectRestSpread": true, + "impliedStrict": true + }, + "extends": "eslint:recommended" +} diff --git a/lab-adam/.gitignore b/lab-adam/.gitignore new file mode 100644 index 0000000..54e2fac --- /dev/null +++ b/lab-adam/.gitignore @@ -0,0 +1,86 @@ +# Created by https://www.gitignore.io/api/node,osx,linux + +### Node ### +# Logs +logs +*.log +npm-debug.log* + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (http://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules +jspm_packages + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Optional REPL history +.node_repl_history + + +### OSX ### +*.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + + +### Linux ### +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* diff --git a/lab-adam/app.js b/lab-adam/app.js new file mode 100644 index 0000000..e9692cc --- /dev/null +++ b/lab-adam/app.js @@ -0,0 +1,6 @@ +'use strict'; + +var greetings = require('./lib/greet.js'); +var name = process.argv[2]; + +console.log(greetings.greet(name)); diff --git a/lab-adam/gulpfile.js b/lab-adam/gulpfile.js new file mode 100644 index 0000000..2f3f309 --- /dev/null +++ b/lab-adam/gulpfile.js @@ -0,0 +1,27 @@ +'use strict'; + +const gulp = require('gulp'); +const eslint = require('gulp-eslint'); +const mocha = require('gulp-mocha'); + +gulp.task('test', function() { + gulp.src('./test/*-test.js', {read: false}) + .pipe(mocha({reporter: 'nyan'})); +}); + +gulp.task('lint', function(){ + return gulp.src(['**/*.js','!node_modules/**']) + .pipe(eslint()) + .pipe(eslint.format()) + .pipe(eslint.failAfterError()); +}); + +gulp.task('dev', function() { + gulp.watch(['**/*.js', '!node_modules/**'],['test', 'lint']); +}); + +gulp.task('moduletracker', function() { + gulp.watch(['node_modules/**'],[function(){ + console.log('You added or changed your modules!'); + }]); +}); diff --git a/lab-adam/lib/greet.js b/lab-adam/lib/greet.js new file mode 100644 index 0000000..134cb09 --- /dev/null +++ b/lab-adam/lib/greet.js @@ -0,0 +1,11 @@ +'use strict'; +exports = module.exports = {}; + +exports.greet = function(name){ + if (arguments.length === 0 || arguments[0] === undefined) throw new Error('missing a name'); + return 'hello ' + name ; +}; + +exports.sayGoodbye = function(){ + return('Seeya'); +}; diff --git a/lab-adam/package.json b/lab-adam/package.json new file mode 100644 index 0000000..76dc5f4 --- /dev/null +++ b/lab-adam/package.json @@ -0,0 +1,23 @@ +{ + "name": "day1", + "version": "1.0.0", + "description": "", + "main": "index.js", + "directories": { + "test": "test" + }, + "dependencies": {}, + "devDependencies": { + "fs": "0.0.1-security", + "gulp": "3.9.1", + "gulp-changed": "1.3.2", + "gulp-eslint": "3.0.1", + "gulp-mocha": "3.0.1", + "mocha": "3.0.2" + }, + "scripts": { + "test": "mocha" + }, + "author": "", + "license": "ISC" +} diff --git a/lab-adam/test/greet-test.js b/lab-adam/test/greet-test.js new file mode 100644 index 0000000..97968af --- /dev/null +++ b/lab-adam/test/greet-test.js @@ -0,0 +1,25 @@ +'use strict'; +const greetings = require ('../lib/greet'); +const assert = require('assert'); + +describe('testing module greet', function(){ + describe('testing #sayHello()', function(){ + it('should return "name" when passed "name"', function(){ + let result = greetings.greet('name'); + assert.ok(result === 'hello name', 'was not hello name'); + }); + + it('should throw a missing a name error if given no argument', function(){ + assert.throws(function() { + greetings.greet(); + }, 'shoulda thrown that err'); + }); + + // Run test using following syntax: "env.Name=[name] mocha" + it('should process an input from CLI', function() { + var name = process.env.NAME; + let result = greetings.greet(name); + assert.ok(result === 'hello ' + name, 'did not take CLI input'); + }); + }); +}); From 657fca9d85249db01beb6b946dfe4764e45040c3 Mon Sep 17 00:00:00 2001 From: Adam Stelle Date: Tue, 13 Sep 2016 15:22:50 -0700 Subject: [PATCH 2/3] added default gulp command --- lab-adam/gulpfile.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lab-adam/gulpfile.js b/lab-adam/gulpfile.js index 2f3f309..98df844 100644 --- a/lab-adam/gulpfile.js +++ b/lab-adam/gulpfile.js @@ -20,7 +20,8 @@ gulp.task('dev', function() { gulp.watch(['**/*.js', '!node_modules/**'],['test', 'lint']); }); -gulp.task('moduletracker', function() { +gulp.task('default', function() { + console.log('Now tracking all updates & additions to your node modules...'); gulp.watch(['node_modules/**'],[function(){ console.log('You added or changed your modules!'); }]); From aa70de94326bee82ed924285b2299c6f0bca3aa2 Mon Sep 17 00:00:00 2001 From: Adam Stelle Date: Tue, 13 Sep 2016 15:32:54 -0700 Subject: [PATCH 3/3] Hardcoded process.argv[2] into mocha for testing --- lab-adam/test/greet-test.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lab-adam/test/greet-test.js b/lab-adam/test/greet-test.js index 97968af..3e50e73 100644 --- a/lab-adam/test/greet-test.js +++ b/lab-adam/test/greet-test.js @@ -14,10 +14,9 @@ describe('testing module greet', function(){ greetings.greet(); }, 'shoulda thrown that err'); }); - - // Run test using following syntax: "env.Name=[name] mocha" + it('should process an input from CLI', function() { - var name = process.env.NAME; + var name = process.argv[2] = 'adam'; let result = greetings.greet(name); assert.ok(result === 'hello ' + name, 'did not take CLI input'); });