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/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/gulpfile.js b/gulpfile.js new file mode 100644 index 0000000..ae7b76e --- /dev/null +++ b/gulpfile.js @@ -0,0 +1,78 @@ +const gulp = require('gulp'); +const mocha = require('gulp-mocha'); +const lint = require('gulp-eslint'); +const merge = require('merge-stream'); + +const gulpFiles = { + testFilesSrc: './test/greet-test.js', + greetSrc: './greet.js' +} + +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(gulpFiles.greetSrc) + .pipe(lint(opts)) + .pipe(lint.format()); + var greetTest = gulp.src(gulpFiles.testFilesSrc) + .pipe(lint(opts)) + .pipe(lint.format()); + + return merge(greet, greetTest); +}) + +gulp.task('tests', () => { + return gulp.src(gulpFiles.testFilesSrc, {read: false}) + .pipe(mocha({reporter: 'nyan'})); +}) + +gulp.task('watch', () => { + gulp.watch(gulpFiles.testFilesSrc, ['linter', 'tests']); + gulp.watch(gulpFiles.greetSrc, ['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 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'); + }); +});