From 81a13af8352e9503a67d2c5284a1e814b20445d8 Mon Sep 17 00:00:00 2001 From: Caleb Sattgast Date: Mon, 5 Dec 2016 15:50:34 -0800 Subject: [PATCH 1/8] add some code to my lab project --- code.js | 1 + 1 file changed, 1 insertion(+) create mode 100644 code.js diff --git a/code.js b/code.js new file mode 100644 index 0000000..ad9a93a --- /dev/null +++ b/code.js @@ -0,0 +1 @@ +'use strict'; From afd41261fa254ba83c14fee9afd8aaa01a8a8d2a Mon Sep 17 00:00:00 2001 From: Caleb Sattgast Date: Tue, 6 Dec 2016 11:35:11 -0800 Subject: [PATCH 2/8] set up functions to print welcome message, define name as cli user inputted argument --- code.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/code.js b/code.js index ad9a93a..8fdb1f3 100644 --- a/code.js +++ b/code.js @@ -1 +1,9 @@ 'use strict'; + +const greeting = require('./lib/greeting.js'); + +// set name as user inputed command line argument following 'node' and filename +var name = process.argv[process.argv.length - 1]; + +greeting.welcome(name); +greeting.farewell(name); From 7f39426bcf43a151e305c2bc1f610cf3ec1dfeab Mon Sep 17 00:00:00 2001 From: Caleb Sattgast Date: Tue, 6 Dec 2016 11:35:32 -0800 Subject: [PATCH 3/8] add eslintrc file --- .eslintrc | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 .eslintrc diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..8dc6807 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,21 @@ +{ + "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" +} From ac82fd5bba3592bf91252947e51f8297dda123ee Mon Sep 17 00:00:00 2001 From: Caleb Sattgast Date: Tue, 6 Dec 2016 11:36:17 -0800 Subject: [PATCH 4/8] build out greeting message app functionality --- lib/greeting.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 lib/greeting.js diff --git a/lib/greeting.js b/lib/greeting.js new file mode 100644 index 0000000..000e7f3 --- /dev/null +++ b/lib/greeting.js @@ -0,0 +1,16 @@ +'use strict'; + +module.exports = exports = {}; + +exports.welcome = function(name) { + if (/[^a-z]/i.test(name)) throw new Error('non-alphabetical characters not allowed, or no name provided'); + var welcomeMessage = `Hello and welcome, ${name}! Glad you can be here!`; + console.log(welcomeMessage); + return welcomeMessage; +}; + +exports.farewell = function(name) { + var farewellMessage = `Glad you could stay for a while, ${name}! Bye and see you next time!`; + console.log(farewellMessage); + return farewellMessage; +}; From 8297227e51743a9a488aded8a1ed92747b4e82bc Mon Sep 17 00:00:00 2001 From: Caleb Sattgast Date: Tue, 6 Dec 2016 11:36:43 -0800 Subject: [PATCH 5/8] build out basic tests --- test/greeting-test.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 test/greeting-test.js diff --git a/test/greeting-test.js b/test/greeting-test.js new file mode 100644 index 0000000..b9625ad --- /dev/null +++ b/test/greeting-test.js @@ -0,0 +1,17 @@ +'use strict'; + +const greeting = require('../lib/greeting.js'); + +const assert = require('assert'); + +describe('Greeting', function() { + it('should print a greeting message customized with the user\'s inputted name.', function() { + var result = greeting.welcome('Caleb'); + assert.ok(result === 'Hello and welcome, Caleb! Glad you can be here!', 'greeting not printed as expected'); + }); + it('should throw an error indicating a missing name or unexpected charater', function() { + assert.throws(function() { + greeting.welcome(); + }, 'error not thrown'); + }); +}); From 2f32fc2ad1a99379c974d5b8e4b5c50d48ce5173 Mon Sep 17 00:00:00 2001 From: Caleb Sattgast Date: Tue, 6 Dec 2016 11:52:50 -0800 Subject: [PATCH 6/8] rename code.js to greet.js --- code.js => greet.js | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename code.js => greet.js (100%) diff --git a/code.js b/greet.js similarity index 100% rename from code.js rename to greet.js From 8dbd5e2a3ad9dc10d938cd48d42551955b5c99c1 Mon Sep 17 00:00:00 2001 From: Caleb Sattgast Date: Tue, 6 Dec 2016 11:53:45 -0800 Subject: [PATCH 7/8] add error handling for empty name exception --- lib/greeting.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/greeting.js b/lib/greeting.js index 000e7f3..e074964 100644 --- a/lib/greeting.js +++ b/lib/greeting.js @@ -4,6 +4,7 @@ module.exports = exports = {}; exports.welcome = function(name) { if (/[^a-z]/i.test(name)) throw new Error('non-alphabetical characters not allowed, or no name provided'); + if (arguments.length === 0) throw new Error('no name provided'); var welcomeMessage = `Hello and welcome, ${name}! Glad you can be here!`; console.log(welcomeMessage); return welcomeMessage; From 0b25e84d494f95b8d320ea80024da187b1f39cc1 Mon Sep 17 00:00:00 2001 From: Caleb Sattgast Date: Tue, 6 Dec 2016 13:23:17 -0800 Subject: [PATCH 8/8] add nested describe statement for welcome function --- test/greeting-test.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/test/greeting-test.js b/test/greeting-test.js index b9625ad..35cb231 100644 --- a/test/greeting-test.js +++ b/test/greeting-test.js @@ -5,13 +5,15 @@ const greeting = require('../lib/greeting.js'); const assert = require('assert'); describe('Greeting', function() { - it('should print a greeting message customized with the user\'s inputted name.', function() { - var result = greeting.welcome('Caleb'); - assert.ok(result === 'Hello and welcome, Caleb! Glad you can be here!', 'greeting not printed as expected'); - }); - it('should throw an error indicating a missing name or unexpected charater', function() { - assert.throws(function() { - greeting.welcome(); - }, 'error not thrown'); + describe('#welcome', function() { + it('should print a greeting message customized with the user\'s inputted name.', function() { + var result = greeting.welcome('Caleb'); + assert.ok(result === 'Hello and welcome, Caleb! Glad you can be here!', 'greeting not printed as expected'); + }); + it('should throw an error indicating a missing name or unexpected charater', function() { + assert.throws(function() { + greeting.welcome(); + }, 'error not thrown'); + }); }); });