From 11ccb8ad1ba44e77c6aa7fddbbbbc2c0bc42d06a Mon Sep 17 00:00:00 2001 From: Stefanie Hansen Date: Mon, 9 May 2016 18:13:17 -0700 Subject: [PATCH 1/4] Completed the assignment, the method within greet.js now greets via command line and tests pass --- .gitignore | 1 + greet.js | 11 +++++++++++ test/greet-test.js | 16 ++++++++++++++++ 3 files changed, 28 insertions(+) create mode 100644 .gitignore create mode 100755 greet.js create mode 100644 test/greet-test.js diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3c3629e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules diff --git a/greet.js b/greet.js new file mode 100755 index 0000000..75de9ef --- /dev/null +++ b/greet.js @@ -0,0 +1,11 @@ +(function() { + exports = module.exports = {}; + exports.greet = function(name) { + return 'Hello ' + name; + }; + + if (!module.parent) { + console.log(exports.greet(process.argv.slice(2))); + }; + +})(); diff --git a/test/greet-test.js b/test/greet-test.js new file mode 100644 index 0000000..a1140e6 --- /dev/null +++ b/test/greet-test.js @@ -0,0 +1,16 @@ +const chai = require('chai'); +const expect = chai.expect; +const greeting = require('../greet.js'); + +describe('Greeting test', () => { + it('should return a greeting with the name passed', () => { + expect(greeting.greet('Stefanie')).to.eql('Hello Stefanie'); + }) +}) + +describe('Greeting test via command line utility', () => { + it('should return a greeting with the name passed in the command line', () => { + process.argv = ['node', 'Users/Stefanie/cf/401/class-01/stefanie-hansen/greet.js', 'Stefanie']; + expect(greeting.greet(process.argv.slice(2))).to.eql('Hello Stefanie'); + }) +}) From b0c1bcbe60eb9927513e21b76909a33eaafffb30 Mon Sep 17 00:00:00 2001 From: Stefanie Hansen Date: Tue, 10 May 2016 18:49:03 -0700 Subject: [PATCH 2/4] added gulpfile with tasks as well as package.json --- greet.js | 16 ++++------- gulpfile.js | 72 ++++++++++++++++++++++++++++++++++++++++++++++ package.json | 30 +++++++++++++++++++ test/greet-test.js | 25 ++++++++-------- 4 files changed, 121 insertions(+), 22 deletions(-) create mode 100644 gulpfile.js create mode 100644 package.json diff --git a/greet.js b/greet.js index 75de9ef..82807c1 100755 --- a/greet.js +++ b/greet.js @@ -1,11 +1,7 @@ -(function() { - exports = module.exports = {}; - exports.greet = function(name) { - return 'Hello ' + name; - }; +'use strict'; - if (!module.parent) { - console.log(exports.greet(process.argv.slice(2))); - }; - -})(); +const greet = module.exports = function() { + let name = process.argv[2] || 'friend'; + return 'Hello ' + name; +}; +console.log(greet()); diff --git a/gulpfile.js b/gulpfile.js new file mode 100644 index 0000000..7f393e1 --- /dev/null +++ b/gulpfile.js @@ -0,0 +1,72 @@ +const gulp = require('gulp'); +const mocha = require('gulp-mocha'); +const lint = require('gulp-eslint'); +const merge = require('merge-stream') +const opts = { + 'extends': 'eslint:recommended', + 'ecmaFeatures': { + 'modules': true + }, + 'rules': { + 'no-alert': 0, + 'no-bitwise': 0, + 'camelcase': 1, + 'no-console': 1, + 'curly': 1, + 'eqeqeq': 0, + 'no-eq-null': 0, + 'guard-for-in': 1, + 'no-empty': 1, + 'no-use-before-define': 0, + 'no-obj-calls': 2, + 'no-unused-vars': 0, + 'new-cap': 1, + 'no-shadow': 0, + 'strict': 1, + 'no-invalid-regexp': 2, + 'comma-dangle': 2, + 'no-undef': 1, + 'no-new': 1, + 'no-extra-semi': 1, + 'no-debugger': 2, + 'no-caller': 1, + 'semi': 1, + 'quotes': 0, + 'no-unreachable': 2 + }, + + 'globals': { + '$': false + }, + + 'env': { + 'node': true, + 'es6': true + } + + } + +gulp.task('linter' , () => { + var greet = gulp.src('./greet.js') + .pipe(lint(opts)) + .pipe(lint.format()); + var greetTest = gulp.src('./test/greet-test.js') + .pipe(lint(opts)) + .pipe(lint.format()); + + return merge(greet, greetTest); +}) + +gulp.task('tests', () => { + return gulp.src('./test/greet-test.js', {read: false}) + .pipe(mocha({reporter: 'nyan'})); +}) + +gulp.task('watch', () => { + gulp.watch('./test/greet-test.js', ['linter', 'tests']); + gulp.watch('./greet.js', ['linter', 'tests']); +}) + +gulp.task('default', ['watch', 'linter', 'tests'], () => { + console.log('All tasks completed successfully') +}); diff --git a/package.json b/package.json new file mode 100644 index 0000000..19cf5cc --- /dev/null +++ b/package.json @@ -0,0 +1,30 @@ +{ + "name": "stefanie-hansen", + "version": "1.0.0", + "description": "##To Submit this Assignment * fork this repository * write all of your code in a folder containing your name * push to your repository * submit a pull request to this repository * submit a link to your PR in canvas", + "main": "greet.js", + "directories": { + "test": "test" + }, + "devDependencies": { + "chai": "^3.5.0", + "gulp": "^3.9.1", + "gulp-eslint": "^2.0.0", + "gulp-mocha": "^2.2.0", + "merge-stream": "^1.0.0", + "mocha": "^2.4.5" + }, + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/stefuhnee/simple_modular_patterns_and_tests.git" + }, + "author": "", + "license": "ISC", + "bugs": { + "url": "https://github.com/stefuhnee/simple_modular_patterns_and_tests/issues" + }, + "homepage": "https://github.com/stefuhnee/simple_modular_patterns_and_tests#readme" +} diff --git a/test/greet-test.js b/test/greet-test.js index a1140e6..8500be4 100644 --- a/test/greet-test.js +++ b/test/greet-test.js @@ -1,16 +1,17 @@ -const chai = require('chai'); -const expect = chai.expect; -const greeting = require('../greet.js'); +'use strict'; + +const expect = require('chai').expect; +const greet = require('../greet.js'); describe('Greeting test', () => { - it('should return a greeting with the name passed', () => { - expect(greeting.greet('Stefanie')).to.eql('Hello Stefanie'); - }) -}) + it('should return a greeting with friend if no argument given', function() { + expect(greet()).to.eql('Hello friend'); + }); +}); -describe('Greeting test via command line utility', () => { - it('should return a greeting with the name passed in the command line', () => { +describe('Greeting test via command line utility', function() { + it('should return a greeting with the name passed in the command line', function() { process.argv = ['node', 'Users/Stefanie/cf/401/class-01/stefanie-hansen/greet.js', 'Stefanie']; - expect(greeting.greet(process.argv.slice(2))).to.eql('Hello Stefanie'); - }) -}) + expect(greet(process.argv[2])).to.eql('Hello Stefanie'); + }); +}); From e96592827eae5c13696fada49d731454954f6067 Mon Sep 17 00:00:00 2001 From: Stefanie Hansen Date: Tue, 10 May 2016 19:09:36 -0700 Subject: [PATCH 3/4] deleted everything but gulpfile.js and package.json per the assignment instructions --- .gitignore | 1 - README.md | 27 --------------------------- greet.js | 7 ------- test/greet-test.js | 17 ----------------- 4 files changed, 52 deletions(-) delete mode 100644 .gitignore delete mode 100644 README.md delete mode 100755 greet.js delete mode 100644 test/greet-test.js diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 3c3629e..0000000 --- a/.gitignore +++ /dev/null @@ -1 +0,0 @@ -node_modules diff --git a/README.md b/README.md deleted file mode 100644 index d71702f..0000000 --- a/README.md +++ /dev/null @@ -1,27 +0,0 @@ -#Simple Modular and Test Patterns - -##To Submit this Assignment - * fork this repository - * write all of your code in a folder containing your name - * push to your repository - * submit a pull request to this repository - * submit a link to your PR in canvas - -##Description: -This assignment will have you create a simple Javascript object that will be exported using the Node modular pattern we went over in class. -Your object should have a function named 'greet' that takes a name as a parameter and returns the string 'hello ' + name - -You should have at least one test that verifies the output of the function. - -Your submission should be a link to your pull request. - -##Bonus: -For an extra point, create a command line utility that will be run using node greet.js 'some name' and will pass the input contained in that argument to the greet function and output the result to the screen. - -For a second bonus point, write a test that makes sure that the arguments are being processed. - -##Rubric: - * Proper Styling: 2pts - * Proper Submission: 2pts - * Mocha/Chai Test: 3pts - * Use of Modular Pattern/design of greet object/function: 3pts diff --git a/greet.js b/greet.js deleted file mode 100755 index 82807c1..0000000 --- a/greet.js +++ /dev/null @@ -1,7 +0,0 @@ -'use strict'; - -const greet = module.exports = function() { - let name = process.argv[2] || 'friend'; - return 'Hello ' + name; -}; -console.log(greet()); diff --git a/test/greet-test.js b/test/greet-test.js deleted file mode 100644 index 8500be4..0000000 --- a/test/greet-test.js +++ /dev/null @@ -1,17 +0,0 @@ -'use strict'; - -const expect = require('chai').expect; -const greet = require('../greet.js'); - -describe('Greeting test', () => { - it('should return a greeting with friend if no argument given', function() { - expect(greet()).to.eql('Hello friend'); - }); -}); - -describe('Greeting test via command line utility', function() { - it('should return a greeting with the name passed in the command line', function() { - process.argv = ['node', 'Users/Stefanie/cf/401/class-01/stefanie-hansen/greet.js', 'Stefanie']; - expect(greet(process.argv[2])).to.eql('Hello Stefanie'); - }); -}); From 7058bd197e4951e660b8096388c85bf7e218f4b0 Mon Sep 17 00:00:00 2001 From: Stefanie Hansen Date: Wed, 11 May 2016 09:23:52 -0700 Subject: [PATCH 4/4] changes filepaths to properties on an object for the gulpfile --- .gitignore | 2 ++ gulpfile.js | 20 +++++++++++++------- test/greet-test.js | 17 +++++++++++++++++ 3 files changed, 32 insertions(+), 7 deletions(-) create mode 100644 .gitignore create mode 100644 test/greet-test.js diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..68b21f0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/node_modules +.DS_Store diff --git a/gulpfile.js b/gulpfile.js index 7f393e1..ae7b76e 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,7 +1,13 @@ const gulp = require('gulp'); const mocha = require('gulp-mocha'); const lint = require('gulp-eslint'); -const merge = require('merge-stream') +const merge = require('merge-stream'); + +const gulpFiles = { + testFilesSrc: './test/greet-test.js', + greetSrc: './greet.js' +} + const opts = { 'extends': 'eslint:recommended', 'ecmaFeatures': { @@ -43,14 +49,14 @@ const opts = { 'node': true, 'es6': true } - } + gulp.task('linter' , () => { - var greet = gulp.src('./greet.js') + var greet = gulp.src(gulpFiles.greetSrc) .pipe(lint(opts)) .pipe(lint.format()); - var greetTest = gulp.src('./test/greet-test.js') + var greetTest = gulp.src(gulpFiles.testFilesSrc) .pipe(lint(opts)) .pipe(lint.format()); @@ -58,13 +64,13 @@ gulp.task('linter' , () => { }) gulp.task('tests', () => { - return gulp.src('./test/greet-test.js', {read: false}) + return gulp.src(gulpFiles.testFilesSrc, {read: false}) .pipe(mocha({reporter: 'nyan'})); }) gulp.task('watch', () => { - gulp.watch('./test/greet-test.js', ['linter', 'tests']); - gulp.watch('./greet.js', ['linter', 'tests']); + gulp.watch(gulpFiles.testFilesSrc, ['linter', 'tests']); + gulp.watch(gulpFiles.greetSrc, ['linter', 'tests']); }) gulp.task('default', ['watch', 'linter', 'tests'], () => { diff --git a/test/greet-test.js b/test/greet-test.js new file mode 100644 index 0000000..8500be4 --- /dev/null +++ b/test/greet-test.js @@ -0,0 +1,17 @@ +'use strict'; + +const expect = require('chai').expect; +const greet = require('../greet.js'); + +describe('Greeting test', () => { + it('should return a greeting with friend if no argument given', function() { + expect(greet()).to.eql('Hello friend'); + }); +}); + +describe('Greeting test via command line utility', function() { + it('should return a greeting with the name passed in the command line', function() { + process.argv = ['node', 'Users/Stefanie/cf/401/class-01/stefanie-hansen/greet.js', 'Stefanie']; + expect(greet(process.argv[2])).to.eql('Hello Stefanie'); + }); +});