diff --git a/index.js b/index.js new file mode 100644 index 0000000..be7302a --- /dev/null +++ b/index.js @@ -0,0 +1,5 @@ +'use strict'; + +const greeting = require('./lib/greet.js'); + +greeting.greet(process.argv[2]); diff --git a/lib/greet.js b/lib/greet.js new file mode 100644 index 0000000..82ac030 --- /dev/null +++ b/lib/greet.js @@ -0,0 +1,11 @@ +'use strict'; + +module.exports = exports = {}; + +exports.greet = function(name) { + console.log(`hello ${name}`); + if (!arguments.length) throw new Error('name not provided'); + return `hello ${name}!`; +}; + +console.log('hello', process.argv[2]); diff --git a/test/greet-test.js b/test/greet-test.js new file mode 100644 index 0000000..47c6e5b --- /dev/null +++ b/test/greet-test.js @@ -0,0 +1,19 @@ +'use strict'; + +const greeting = require('../lib/greet.js'); +const assert = require('assert'); + +describe('Greeting Module', function() { + describe('#greet', function() { + it('should return hello and name if input in command line', function() { + var inputName = process.argv[2]; + let result = greeting.greet(inputName); + assert.ok(result === `hello ${inputName}!`, 'but not equal to hello and input name.'); + }); + it('should throw an undefined if name argument is not passed in command line', function() { + assert.throws(function() { + greeting.greet(); + }, 'error not thrown'); + }); + }); +});