From 01aec6b5020d6597e4e2e9941af027759689a632 Mon Sep 17 00:00:00 2001 From: Nikko Pisciotti Date: Mon, 13 Feb 2017 13:25:20 -0800 Subject: [PATCH 1/4] created all necessary files --- lab-nikko/index.js | 0 lab-nikko/lib/greet.js | 0 lab-nikko/test/greet-test.js | 0 3 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 lab-nikko/index.js create mode 100644 lab-nikko/lib/greet.js create mode 100644 lab-nikko/test/greet-test.js diff --git a/lab-nikko/index.js b/lab-nikko/index.js new file mode 100644 index 0000000..e69de29 diff --git a/lab-nikko/lib/greet.js b/lab-nikko/lib/greet.js new file mode 100644 index 0000000..e69de29 diff --git a/lab-nikko/test/greet-test.js b/lab-nikko/test/greet-test.js new file mode 100644 index 0000000..e69de29 From 2552cb2c0a2be979d759e17aa1e817807661a572 Mon Sep 17 00:00:00 2001 From: Nikko Pisciotti Date: Mon, 13 Feb 2017 14:37:06 -0800 Subject: [PATCH 2/4] created two tests for my greet.js module using assert in node.js --- lab-nikko/index.js | 6 ++++++ lab-nikko/lib/greet.js | 12 ++++++++++++ lab-nikko/test/greet-test.js | 19 +++++++++++++++++++ 3 files changed, 37 insertions(+) diff --git a/lab-nikko/index.js b/lab-nikko/index.js index e69de29..3d49125 100644 --- a/lab-nikko/index.js +++ b/lab-nikko/index.js @@ -0,0 +1,6 @@ +'use strict'; + +const greet = require('./lib/greet.js'); + +greet.greeting('Nikko'); +greet.goodbye(); diff --git a/lab-nikko/lib/greet.js b/lab-nikko/lib/greet.js index e69de29..63708af 100644 --- a/lab-nikko/lib/greet.js +++ b/lab-nikko/lib/greet.js @@ -0,0 +1,12 @@ +'use strict'; + +module.exports = exports = {}; + +exports.greeting = function(name) { + if(arguments.length === 0) throw new Error('No name name given, please input a name!'); + return `Hello ${name}, pleasure to meet you`; +}; + +exports.goodbye = function() { + return 'thanks for stopping by!'; +}; diff --git a/lab-nikko/test/greet-test.js b/lab-nikko/test/greet-test.js index e69de29..23454c1 100644 --- a/lab-nikko/test/greet-test.js +++ b/lab-nikko/test/greet-test.js @@ -0,0 +1,19 @@ +'use strict'; + +const greet = require('../lib/greet.js'); +const assert = require('assert'); + +describe('Greet Module', function() { + describe('#greeting', function(){ + it('function should return Hello Nikko, pleasure to meet you', function(){ + var output = greet.greeting('Nikko'); + assert.ok(output === 'Hello Nikko, pleasure to meet you', 'Output does not match - fail'); + }); + }); + describe('#goodbye', function() { + it('function should log: thanks for stopping by!', function() { + var goodbye = greet.goodbye(); + assert.ok(goodbye === 'thanks for stopping by!', 'Output does not match - fail'); + }); + }); +}); From 8b7f44c5cffe600da74b1666561049c7802641d5 Mon Sep 17 00:00:00 2001 From: Nikko Pisciotti Date: Mon, 13 Feb 2017 15:05:36 -0800 Subject: [PATCH 3/4] added the ability to pass a third argument in the command line into the index.js file, this also reflects in my test files --- lab-nikko/index.js | 5 ++++- lab-nikko/lib/greet.js | 2 ++ lab-nikko/test/greet-test.js | 4 ++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lab-nikko/index.js b/lab-nikko/index.js index 3d49125..9814c45 100644 --- a/lab-nikko/index.js +++ b/lab-nikko/index.js @@ -2,5 +2,8 @@ const greet = require('./lib/greet.js'); -greet.greeting('Nikko'); +if(process.argv[2]) var name = process.argv[2]; +if(process.argv[2] === undefined) var name = 'Carne Asuhdude'; + +greet.greeting(name); greet.goodbye(); diff --git a/lab-nikko/lib/greet.js b/lab-nikko/lib/greet.js index 63708af..404056b 100644 --- a/lab-nikko/lib/greet.js +++ b/lab-nikko/lib/greet.js @@ -4,9 +4,11 @@ module.exports = exports = {}; exports.greeting = function(name) { if(arguments.length === 0) throw new Error('No name name given, please input a name!'); + console.log(`Hello ${name}, pleasure to meet you`); return `Hello ${name}, pleasure to meet you`; }; exports.goodbye = function() { + console.log('thanks for stopping by!'); return 'thanks for stopping by!'; }; diff --git a/lab-nikko/test/greet-test.js b/lab-nikko/test/greet-test.js index 23454c1..fbfbd4d 100644 --- a/lab-nikko/test/greet-test.js +++ b/lab-nikko/test/greet-test.js @@ -6,8 +6,8 @@ const assert = require('assert'); describe('Greet Module', function() { describe('#greeting', function(){ it('function should return Hello Nikko, pleasure to meet you', function(){ - var output = greet.greeting('Nikko'); - assert.ok(output === 'Hello Nikko, pleasure to meet you', 'Output does not match - fail'); + var output = greet.greeting(process.argv[2]); + assert.ok(output === `Hello ${process.argv[2]}, pleasure to meet you`, 'Output does not match - fail'); }); }); describe('#goodbye', function() { From 8cdebd9c8be59fb02543df4fb28275c1a0444396 Mon Sep 17 00:00:00 2001 From: Nikko Pisciotti Date: Mon, 13 Feb 2017 15:36:10 -0800 Subject: [PATCH 4/4] cleaned up code, and hardcoded var name = 'Nikko' in greet-test.js --- lab-nikko/test/greet-test.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lab-nikko/test/greet-test.js b/lab-nikko/test/greet-test.js index fbfbd4d..d408b91 100644 --- a/lab-nikko/test/greet-test.js +++ b/lab-nikko/test/greet-test.js @@ -3,11 +3,13 @@ const greet = require('../lib/greet.js'); const assert = require('assert'); +var name = 'Nikko'; + describe('Greet Module', function() { describe('#greeting', function(){ - it('function should return Hello Nikko, pleasure to meet you', function(){ - var output = greet.greeting(process.argv[2]); - assert.ok(output === `Hello ${process.argv[2]}, pleasure to meet you`, 'Output does not match - fail'); + it(`function should return Hello ${name}, pleasure to meet you`, function(){ + var output = greet.greeting(name); + assert.ok(output === `Hello ${name}, pleasure to meet you`, 'Output does not match - fail'); }); }); describe('#goodbye', function() {