diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3c3629e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules diff --git a/greet.js b/greet.js new file mode 100755 index 0000000..75de9ef --- /dev/null +++ b/greet.js @@ -0,0 +1,11 @@ +(function() { + exports = module.exports = {}; + exports.greet = function(name) { + return 'Hello ' + name; + }; + + if (!module.parent) { + console.log(exports.greet(process.argv.slice(2))); + }; + +})(); diff --git a/test/greet-test.js b/test/greet-test.js new file mode 100644 index 0000000..a1140e6 --- /dev/null +++ b/test/greet-test.js @@ -0,0 +1,16 @@ +const chai = require('chai'); +const expect = chai.expect; +const greeting = require('../greet.js'); + +describe('Greeting test', () => { + it('should return a greeting with the name passed', () => { + expect(greeting.greet('Stefanie')).to.eql('Hello Stefanie'); + }) +}) + +describe('Greeting test via command line utility', () => { + it('should return a greeting with the name passed in the command line', () => { + process.argv = ['node', 'Users/Stefanie/cf/401/class-01/stefanie-hansen/greet.js', 'Stefanie']; + expect(greeting.greet(process.argv.slice(2))).to.eql('Hello Stefanie'); + }) +})