From b1951b1a038a02091e0ed2b7da63d22c4dc3a2d6 Mon Sep 17 00:00:00 2001 From: ohjonah Date: Mon, 17 Jul 2017 13:42:12 -0700 Subject: [PATCH 1/6] Adds Scaffolding --- .eslintignore | 5 ++ .eslintrc | 22 ++++++ .gitignore | 136 ++++++++++++++++++++++++++++++++++++ lab-jonah/index.js | 0 lab-jonah/lib/arithmetic.js | 1 + lab-jonah/lib/greet.js | 9 +++ 6 files changed, 173 insertions(+) create mode 100644 .eslintignore create mode 100644 .eslintrc create mode 100644 .gitignore create mode 100644 lab-jonah/index.js create mode 100644 lab-jonah/lib/arithmetic.js create mode 100644 lab-jonah/lib/greet.js diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..05b1cf3 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,5 @@ +**/node_modules/* +**/vendor/* +**/*.min.js +**/coverage/* +**/build/* diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..9fff93a --- /dev/null +++ b/.eslintrc @@ -0,0 +1,22 @@ + +{ + "rules": { + "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 + }, + "ecmaFeatures": { + "modules": true, + "experimentalObjectRestSpread": true, + "impliedStrict": true + }, + "extends": "eslint:recommended" +} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..345130c --- /dev/null +++ b/.gitignore @@ -0,0 +1,136 @@ +# Created by https://www.gitignore.io/api/osx,vim,node,macos,windows + +### macOS ### +*.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 + +### Node ### +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.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 + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (http://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ +jspm_packages/ + +# Typescript v1 declaration files +typings/ + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variables file +.env + + +### OSX ### + +# Icon must end with two \r + +# Thumbnails + +# Files that might appear in the root of a volume + +# Directories potentially created on remote AFP share + +### Vim ### +# swap +[._]*.s[a-v][a-z] +[._]*.sw[a-p] +[._]s[a-v][a-z] +[._]sw[a-p] +# session +Session.vim +# temporary +.netrwhist +*~ +# auto-generated tag files +tags + +### Windows ### +# Windows thumbnail cache files +Thumbs.db +ehthumbs.db +ehthumbs_vista.db + +# Folder config file +Desktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msm +*.msp + +# Windows shortcuts +*.lnk + +# End of https://www.gitignore.io/api/osx,vim,node,macos,windows diff --git a/lab-jonah/index.js b/lab-jonah/index.js new file mode 100644 index 0000000..e69de29 diff --git a/lab-jonah/lib/arithmetic.js b/lab-jonah/lib/arithmetic.js new file mode 100644 index 0000000..ad9a93a --- /dev/null +++ b/lab-jonah/lib/arithmetic.js @@ -0,0 +1 @@ +'use strict'; diff --git a/lab-jonah/lib/greet.js b/lab-jonah/lib/greet.js new file mode 100644 index 0000000..30e952e --- /dev/null +++ b/lab-jonah/lib/greet.js @@ -0,0 +1,9 @@ +'use strict'; + +module.exports = exports = {}; + +exports.greet = function(name) { + if (typeof(arguments) !== 'string') throw new Error(null); + + return `Hello ${name}!`; +}; From 3f8d1619ab37ae2af268380645b2eef8d5006fa2 Mon Sep 17 00:00:00 2001 From: ohjonah Date: Mon, 17 Jul 2017 13:44:00 -0700 Subject: [PATCH 2/6] adds add and sub functions --- lab-jonah/lib/arithmetic.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lab-jonah/lib/arithmetic.js b/lab-jonah/lib/arithmetic.js index ad9a93a..069be94 100644 --- a/lab-jonah/lib/arithmetic.js +++ b/lab-jonah/lib/arithmetic.js @@ -1 +1,11 @@ 'use strict'; + +module.exports = exports = {}; + +exports.add = function(a, b) { + return a + b; +}; + +exports.sub = function(a, b) { + return a - b; +}; From 1f5e7d2dd615117ba002817a2439a8a805bb8742 Mon Sep 17 00:00:00 2001 From: ohjonah Date: Mon, 17 Jul 2017 13:50:53 -0700 Subject: [PATCH 3/6] adds test files --- lab-jonah/test/arithmetic-test.js | 0 lab-jonah/test/greet-test.js | 0 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 lab-jonah/test/arithmetic-test.js create mode 100644 lab-jonah/test/greet-test.js diff --git a/lab-jonah/test/arithmetic-test.js b/lab-jonah/test/arithmetic-test.js new file mode 100644 index 0000000..e69de29 diff --git a/lab-jonah/test/greet-test.js b/lab-jonah/test/greet-test.js new file mode 100644 index 0000000..e69de29 From 532f7775f2703e5b38bf04a1acbcb3b63cdfa72d Mon Sep 17 00:00:00 2001 From: ohjonah Date: Mon, 17 Jul 2017 14:11:22 -0700 Subject: [PATCH 4/6] TEST 1p/1f --- lab-jonah/index.js | 4 ++++ lab-jonah/lib/arithmetic.js | 2 ++ lab-jonah/test/arithmetic-test.js | 4 ++++ lab-jonah/test/greet-test.js | 18 ++++++++++++++++++ 4 files changed, 28 insertions(+) diff --git a/lab-jonah/index.js b/lab-jonah/index.js index e69de29..d1c06dc 100644 --- a/lab-jonah/index.js +++ b/lab-jonah/index.js @@ -0,0 +1,4 @@ +'use strict'; + +const greet = require('./lib/greet.js'); +const math = require('./lib/arithmetic.js'); diff --git a/lab-jonah/lib/arithmetic.js b/lab-jonah/lib/arithmetic.js index 069be94..a327bec 100644 --- a/lab-jonah/lib/arithmetic.js +++ b/lab-jonah/lib/arithmetic.js @@ -3,9 +3,11 @@ module.exports = exports = {}; exports.add = function(a, b) { + if (typeof(arguments) !== 'number') throw new Error('not a number!'); return a + b; }; exports.sub = function(a, b) { + if (typeof(arguments) !== 'number') throw new Error('not a number!'); return a - b; }; diff --git a/lab-jonah/test/arithmetic-test.js b/lab-jonah/test/arithmetic-test.js index e69de29..5baa6f4 100644 --- a/lab-jonah/test/arithmetic-test.js +++ b/lab-jonah/test/arithmetic-test.js @@ -0,0 +1,4 @@ +// 'use strict'; +// +// const math = require('../lib/arithmetic.js'); +// const assert = require('assert'); diff --git a/lab-jonah/test/greet-test.js b/lab-jonah/test/greet-test.js index e69de29..c8036c7 100644 --- a/lab-jonah/test/greet-test.js +++ b/lab-jonah/test/greet-test.js @@ -0,0 +1,18 @@ +'use strict'; + +const greet = require('../lib/greet.js'); +const assert = require('assert'); + +describe('Greet Module', function() { + describe('#greet', function() { + it('should return Hello Jonah!', function() { + var result = greet('Jonah'); + assert.ok(result === 'Hello Jonah!', 'not equal to Hello Jonah!'); + }); + it('ERROR ERROR ERROR', function() { + assert.throws(function() { + greet(); + }, 'error not thrown'); + }); + }); +}); From 92115c03f9f845415d5d6eb0e8b65ee348e34faf Mon Sep 17 00:00:00 2001 From: ohjonah Date: Mon, 17 Jul 2017 14:45:15 -0700 Subject: [PATCH 5/6] Adds tests --- lab-jonah/index.js | 4 +++- lab-jonah/lib/arithmetic.js | 6 ++++-- lab-jonah/lib/greet.js | 6 ++---- lab-jonah/test/arithmetic-test.js | 33 +++++++++++++++++++++++++++---- lab-jonah/test/greet-test.js | 19 +++++++++--------- 5 files changed, 47 insertions(+), 21 deletions(-) diff --git a/lab-jonah/index.js b/lab-jonah/index.js index d1c06dc..908ae1f 100644 --- a/lab-jonah/index.js +++ b/lab-jonah/index.js @@ -1,4 +1,6 @@ 'use strict'; const greet = require('./lib/greet.js'); -const math = require('./lib/arithmetic.js'); +const arithmetic = require('./lib/arithmetic.js'); + +greet('Jonah'); diff --git a/lab-jonah/lib/arithmetic.js b/lab-jonah/lib/arithmetic.js index a327bec..5da77e6 100644 --- a/lab-jonah/lib/arithmetic.js +++ b/lab-jonah/lib/arithmetic.js @@ -3,11 +3,13 @@ module.exports = exports = {}; exports.add = function(a, b) { - if (typeof(arguments) !== 'number') throw new Error('not a number!'); + if (typeof arguments[0] !== 'number' || typeof arguments[1] !== 'number') throw new Error('not a number!'); + return a + b; }; exports.sub = function(a, b) { - if (typeof(arguments) !== 'number') throw new Error('not a number!'); + if (typeof arguments[0] !== 'number' || typeof arguments[1] !== 'number') throw new Error('not a number!'); + return a - b; }; diff --git a/lab-jonah/lib/greet.js b/lab-jonah/lib/greet.js index 30e952e..4744ccc 100644 --- a/lab-jonah/lib/greet.js +++ b/lab-jonah/lib/greet.js @@ -1,9 +1,7 @@ 'use strict'; -module.exports = exports = {}; - -exports.greet = function(name) { - if (typeof(arguments) !== 'string') throw new Error(null); +module.exports = function greet(name) { + if (typeof arguments[0] !== 'string') throw new Error(null); return `Hello ${name}!`; }; diff --git a/lab-jonah/test/arithmetic-test.js b/lab-jonah/test/arithmetic-test.js index 5baa6f4..f995768 100644 --- a/lab-jonah/test/arithmetic-test.js +++ b/lab-jonah/test/arithmetic-test.js @@ -1,4 +1,29 @@ -// 'use strict'; -// -// const math = require('../lib/arithmetic.js'); -// const assert = require('assert'); +'use strict'; + +const arithmetic = require('../lib/arithmetic.js'); +const assert = require('assert'); + +describe('Arithmetic Module', function() { + describe('#add', function() { + it('should return 5', function() { + var result = arithmetic.add(3, 2); + assert.ok(result === 5, 'not equal to 5'); + }); + it('should throw invalid number', function() { + assert.throws(function() { + arithmetic.add(); + }, 'error not thrown'); + }); + }); + describe('#sub', function() { + it('should return 1', function() { + var result = arithmetic.sub(3, 2); + assert.ok(result === 1, 'not equal to 1'); + }); + it('should throw invalid number', function() { + assert.throws(function() { + arithmetic.sub(); + }, 'error not thrown'); + }); + }); +}); diff --git a/lab-jonah/test/greet-test.js b/lab-jonah/test/greet-test.js index c8036c7..aebe5cc 100644 --- a/lab-jonah/test/greet-test.js +++ b/lab-jonah/test/greet-test.js @@ -4,15 +4,14 @@ const greet = require('../lib/greet.js'); const assert = require('assert'); describe('Greet Module', function() { - describe('#greet', function() { - it('should return Hello Jonah!', function() { - var result = greet('Jonah'); - assert.ok(result === 'Hello Jonah!', 'not equal to Hello Jonah!'); - }); - it('ERROR ERROR ERROR', function() { - assert.throws(function() { - greet(); - }, 'error not thrown'); - }); + it('should return Hello Jonah!', function() { + var result = greet('Jonah'); + assert.ok(result === 'Hello Jonah!', 'not equal to Hello Jonah!'); + }); + + it('should throw an invalid string error', function() { + assert.throws(function() { + greet(); + }, 'error not thrown'); }); }); From 1a66a64bb8f50f985ef31a4dd73749bb5ed8402d Mon Sep 17 00:00:00 2001 From: ohjonah Date: Mon, 17 Jul 2017 15:15:07 -0700 Subject: [PATCH 6/6] Adds README --- lab-jonah/test/greet-test.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lab-jonah/test/greet-test.js b/lab-jonah/test/greet-test.js index aebe5cc..75df108 100644 --- a/lab-jonah/test/greet-test.js +++ b/lab-jonah/test/greet-test.js @@ -4,9 +4,9 @@ const greet = require('../lib/greet.js'); const assert = require('assert'); describe('Greet Module', function() { - it('should return Hello Jonah!', function() { - var result = greet('Jonah'); - assert.ok(result === 'Hello Jonah!', 'not equal to Hello Jonah!'); + it('should return Hello World!', function() { + var result = greet('World'); + assert.ok(result === 'Hello World!', 'not equal to Hello World!'); }); it('should throw an invalid string error', function() {