From edf26b627f3abb7ab75e3349ab3c5426966be8bb Mon Sep 17 00:00:00 2001 From: Dana Kulp Date: Mon, 13 Feb 2017 13:48:12 -0800 Subject: [PATCH 01/11] Creating file structure --- index.js | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 index.js diff --git a/index.js b/index.js new file mode 100644 index 0000000..e69de29 From 261c4c0ba1c7a547f6786ff9be6ea25b5314e36b Mon Sep 17 00:00:00 2001 From: Dana Kulp Date: Mon, 13 Feb 2017 13:55:06 -0800 Subject: [PATCH 02/11] Wrote simple script in lib directory for testing. --- lib/howdy.js | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 lib/howdy.js diff --git a/lib/howdy.js b/lib/howdy.js new file mode 100644 index 0000000..f59d5df --- /dev/null +++ b/lib/howdy.js @@ -0,0 +1,7 @@ +'use strict'; + +module.exports = exports = {}; + +exports.greeting = function(name) { + return `hello ${name}`; +} From 6fc6ea54bcbd7ef021a9b5281b0db61da4668760 Mon Sep 17 00:00:00 2001 From: Dana Kulp Date: Mon, 13 Feb 2017 14:05:48 -0800 Subject: [PATCH 03/11] Wrote entry point script in index.js --- index.js | 5 +++++ lib/howdy.js | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index e69de29..ee03c18 100644 --- a/index.js +++ b/index.js @@ -0,0 +1,5 @@ +'use strict'; + +const welcome = require('./lib/howdy.js'); + +welcome.greeting('Dana'); diff --git a/lib/howdy.js b/lib/howdy.js index f59d5df..ab651e3 100644 --- a/lib/howdy.js +++ b/lib/howdy.js @@ -4,4 +4,4 @@ module.exports = exports = {}; exports.greeting = function(name) { return `hello ${name}`; -} +}; From dbcce0a127e88a99f86828093205f2e96c5dcd4a Mon Sep 17 00:00:00 2001 From: Dana Kulp Date: Mon, 13 Feb 2017 14:50:51 -0800 Subject: [PATCH 04/11] Simple script passed testing. Working on process.argv to accept input from terminal node command. --- lib/howdy.js | 4 ++++ test/howdy-test.js | 13 +++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 test/howdy-test.js diff --git a/lib/howdy.js b/lib/howdy.js index ab651e3..1ef0b77 100644 --- a/lib/howdy.js +++ b/lib/howdy.js @@ -2,6 +2,10 @@ module.exports = exports = {}; +console.log('process.argv' + process.argv); +console.log('[2]' + process.argv[2]); + exports.greeting = function(name) { + if (arguments.length === 0) throw new Error('no name given'); return `hello ${name}`; }; diff --git a/test/howdy-test.js b/test/howdy-test.js new file mode 100644 index 0000000..0a063c9 --- /dev/null +++ b/test/howdy-test.js @@ -0,0 +1,13 @@ +'use strict'; + +const assert = require('assert'); +const howdy = require('../lib/howdy.js') + +describe('Howdy Module', function() { + describe('#greeting', function() { + it('should return hello Dana', function() { + var printout = howdy.greeting('Dana'); + assert.ok(printout === 'hello Dana', 'not equal to hello Dana'); + }); + }); +}); From 17a9fa2eed172bfd652d35020513504094909994 Mon Sep 17 00:00:00 2001 From: Dana Kulp Date: Mon, 13 Feb 2017 15:09:42 -0800 Subject: [PATCH 05/11] Input is logging to console. --- index.js | 4 +++- lib/howdy.js | 3 --- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index ee03c18..cacd71a 100644 --- a/index.js +++ b/index.js @@ -2,4 +2,6 @@ const welcome = require('./lib/howdy.js'); -welcome.greeting('Dana'); +if (process.argv.length > 2) welcome.greeting('Dana'); + +console.log(process.argv[2]); diff --git a/lib/howdy.js b/lib/howdy.js index 1ef0b77..e541a72 100644 --- a/lib/howdy.js +++ b/lib/howdy.js @@ -2,9 +2,6 @@ module.exports = exports = {}; -console.log('process.argv' + process.argv); -console.log('[2]' + process.argv[2]); - exports.greeting = function(name) { if (arguments.length === 0) throw new Error('no name given'); return `hello ${name}`; From 535291ba59fae520324dc25264339845bc1b9a3f Mon Sep 17 00:00:00 2001 From: Dana Kulp Date: Mon, 13 Feb 2017 15:29:11 -0800 Subject: [PATCH 06/11] Updated test to include reference to command line argument input. --- index.js | 4 ++-- lib/howdy.js | 1 + test/howdy-test.js | 6 +++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index cacd71a..e3fb4b0 100644 --- a/index.js +++ b/index.js @@ -2,6 +2,6 @@ const welcome = require('./lib/howdy.js'); -if (process.argv.length > 2) welcome.greeting('Dana'); +if (process.argv.length < 2) throw new Error('please enter a name!'); -console.log(process.argv[2]); +welcome.greeting(process.argv[2]); diff --git a/lib/howdy.js b/lib/howdy.js index e541a72..e6dac91 100644 --- a/lib/howdy.js +++ b/lib/howdy.js @@ -4,5 +4,6 @@ module.exports = exports = {}; exports.greeting = function(name) { if (arguments.length === 0) throw new Error('no name given'); + console.log(`What's up, ${name}?!`); return `hello ${name}`; }; diff --git a/test/howdy-test.js b/test/howdy-test.js index 0a063c9..26541ec 100644 --- a/test/howdy-test.js +++ b/test/howdy-test.js @@ -5,9 +5,9 @@ const howdy = require('../lib/howdy.js') describe('Howdy Module', function() { describe('#greeting', function() { - it('should return hello Dana', function() { - var printout = howdy.greeting('Dana'); - assert.ok(printout === 'hello Dana', 'not equal to hello Dana'); + it(`should return hello ${process.argv[2]}`, function() { + var printout = howdy.greeting(process.argv[2]); + assert.ok(printout === `hello ${process.argv[2]}`, 'not equal to hello Dana'); }); }); }); From 37c76116327154be0e93541b2764370486146f22 Mon Sep 17 00:00:00 2001 From: Dana Kulp Date: Mon, 13 Feb 2017 15:50:23 -0800 Subject: [PATCH 07/11] Testing out process.argv properties to determine how to handle multiple inputs --- index.js | 3 +++ lib/howdy.js | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/index.js b/index.js index e3fb4b0..27599bc 100644 --- a/index.js +++ b/index.js @@ -3,5 +3,8 @@ const welcome = require('./lib/howdy.js'); if (process.argv.length < 2) throw new Error('please enter a name!'); +console.log(process.argv[2]); +console.log(process.argv[2].length); +// if (process.argv.length > 3) welcome.multipleGreetings(process.argv); welcome.greeting(process.argv[2]); diff --git a/lib/howdy.js b/lib/howdy.js index e6dac91..d8ab6d8 100644 --- a/lib/howdy.js +++ b/lib/howdy.js @@ -7,3 +7,9 @@ exports.greeting = function(name) { console.log(`What's up, ${name}?!`); return `hello ${name}`; }; + +exports.multipleGreetings = function(processARGV) { + // if (arguments.length < 4) throw new Error('use greeting function'); + var names = processARGV.slice(2); + console.log(names); +} From f82092b200ce836e83d95c1a432a8ebc311f284c Mon Sep 17 00:00:00 2001 From: Dana Kulp Date: Mon, 13 Feb 2017 16:08:05 -0800 Subject: [PATCH 08/11] I feel like I learned a fair amount about the argv property of the process object from the docs and from playing around with console logs. --- index.js | 10 ++++++---- lib/howdy.js | 7 +++---- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index 27599bc..9792e33 100644 --- a/index.js +++ b/index.js @@ -3,8 +3,10 @@ const welcome = require('./lib/howdy.js'); if (process.argv.length < 2) throw new Error('please enter a name!'); -console.log(process.argv[2]); -console.log(process.argv[2].length); -// if (process.argv.length > 3) welcome.multipleGreetings(process.argv); +// console.log(process.argv); +// console.log(process.argv[2]); +// console.log(process.argv[3]); +console.log(process.argv.length); +if (process.argv.length === 3) welcome.greeting(process.argv[2]); -welcome.greeting(process.argv[2]); +if (process.argv.length > 3) welcome.multipleGreetings(process.argv); diff --git a/lib/howdy.js b/lib/howdy.js index d8ab6d8..2a57ea9 100644 --- a/lib/howdy.js +++ b/lib/howdy.js @@ -8,8 +8,7 @@ exports.greeting = function(name) { return `hello ${name}`; }; -exports.multipleGreetings = function(processARGV) { - // if (arguments.length < 4) throw new Error('use greeting function'); - var names = processARGV.slice(2); - console.log(names); +exports.multipleGreetings = function(termInput) { + var names = termInput.slice(2).join(', '); + console.log(`Hey there ${names}`); } From 55e2db754ff0b775fb6f405880685bfa74ec17dd Mon Sep 17 00:00:00 2001 From: Dana Kulp Date: Mon, 13 Feb 2017 16:20:27 -0800 Subject: [PATCH 09/11] One test written for each method. Passing both. --- index.js | 5 +---- lib/howdy.js | 5 +++-- test/howdy-test.js | 8 +++++++- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index 9792e33..df0d476 100644 --- a/index.js +++ b/index.js @@ -3,10 +3,7 @@ const welcome = require('./lib/howdy.js'); if (process.argv.length < 2) throw new Error('please enter a name!'); -// console.log(process.argv); -// console.log(process.argv[2]); -// console.log(process.argv[3]); -console.log(process.argv.length); + if (process.argv.length === 3) welcome.greeting(process.argv[2]); if (process.argv.length > 3) welcome.multipleGreetings(process.argv); diff --git a/lib/howdy.js b/lib/howdy.js index 2a57ea9..6523d46 100644 --- a/lib/howdy.js +++ b/lib/howdy.js @@ -9,6 +9,7 @@ exports.greeting = function(name) { }; exports.multipleGreetings = function(termInput) { - var names = termInput.slice(2).join(', '); + var names = termInput.slice(2).join(' and '); console.log(`Hey there ${names}`); -} + return `Hey there ${names}`; +}; diff --git a/test/howdy-test.js b/test/howdy-test.js index 26541ec..e6f22b2 100644 --- a/test/howdy-test.js +++ b/test/howdy-test.js @@ -7,7 +7,13 @@ describe('Howdy Module', function() { describe('#greeting', function() { it(`should return hello ${process.argv[2]}`, function() { var printout = howdy.greeting(process.argv[2]); - assert.ok(printout === `hello ${process.argv[2]}`, 'not equal to hello Dana'); + assert.ok(printout === `hello ${process.argv[2]}`, 'incorrect result'); + }); + }); + describe('#multipleGreetings', function() { + it(`should return all names entered in command line`, function() { + var printout = howdy.multipleGreetings(process.argv); + assert.ok(printout === `Hey there ${process.argv.slice(2).join(' and ')}`, 'not quite right'); }); }); }); From bbe1e6554931dae2f980d8c8baeeab1dda6d89f9 Mon Sep 17 00:00:00 2001 From: Dana Kulp Date: Mon, 13 Feb 2017 17:28:34 -0800 Subject: [PATCH 10/11] Not quite satisfied with the way I'm formatting the string output but it's working for now... --- index.js | 2 +- lib/howdy.js | 11 ++++++++--- test/howdy-test.js | 10 ++++++---- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index df0d476..6102f36 100644 --- a/index.js +++ b/index.js @@ -2,7 +2,7 @@ const welcome = require('./lib/howdy.js'); -if (process.argv.length < 2) throw new Error('please enter a name!'); +if (process.argv.length < 3) throw new Error('please enter a name!'); if (process.argv.length === 3) welcome.greeting(process.argv[2]); diff --git a/lib/howdy.js b/lib/howdy.js index 6523d46..4441aef 100644 --- a/lib/howdy.js +++ b/lib/howdy.js @@ -9,7 +9,12 @@ exports.greeting = function(name) { }; exports.multipleGreetings = function(termInput) { - var names = termInput.slice(2).join(' and '); - console.log(`Hey there ${names}`); - return `Hey there ${names}`; + let names = termInput.slice(2); + let logMessage = " "; + logMessage += names.slice(0, -1).join(', '); + logMessage += (' and '); + logMessage += names.slice(-1).join(''); + logMessage += ('!'); + console.log(`Hey there ${logMessage}`); + return `Hey there ${logMessage}`; }; diff --git a/test/howdy-test.js b/test/howdy-test.js index e6f22b2..29a016f 100644 --- a/test/howdy-test.js +++ b/test/howdy-test.js @@ -1,19 +1,21 @@ 'use strict'; const assert = require('assert'); -const howdy = require('../lib/howdy.js') +const howdy = require('../lib/howdy.js'); +// const hackyMessageVariable = howdy.multipleGreetings.logMessage; +// console.log(hackyMessageVariable); describe('Howdy Module', function() { describe('#greeting', function() { it(`should return hello ${process.argv[2]}`, function() { - var printout = howdy.greeting(process.argv[2]); + let printout = howdy.greeting(process.argv[2]); assert.ok(printout === `hello ${process.argv[2]}`, 'incorrect result'); }); }); describe('#multipleGreetings', function() { it(`should return all names entered in command line`, function() { - var printout = howdy.multipleGreetings(process.argv); - assert.ok(printout === `Hey there ${process.argv.slice(2).join(' and ')}`, 'not quite right'); + let printout = howdy.multipleGreetings(process.argv); + assert.ok(printout === `Hey there ${hackyMessageVariable}`, 'not quite right'); }); }); }); From 0f7d7579128e4c88f0107731a77874fcf142e0f3 Mon Sep 17 00:00:00 2001 From: Dana Kulp Date: Mon, 13 Feb 2017 17:48:19 -0800 Subject: [PATCH 11/11] Added test for empty input. --- test/howdy-test.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/howdy-test.js b/test/howdy-test.js index 29a016f..557d9fe 100644 --- a/test/howdy-test.js +++ b/test/howdy-test.js @@ -12,6 +12,13 @@ describe('Howdy Module', function() { assert.ok(printout === `hello ${process.argv[2]}`, 'incorrect result'); }); }); + describe('#greeting', function() { + it('Should result in error from missing input', function() { + assert.throws(function() { + howdy.greeting(); + }, 'Error not thrown for empty input'); + }); + }); describe('#multipleGreetings', function() { it(`should return all names entered in command line`, function() { let printout = howdy.multipleGreetings(process.argv);