Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -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"
}
7 changes: 7 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

const greet = require('./lib/greet.js');
var name = process.argv[2];
// console.log(process.argv);

greet.sayHi(name);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Glad to see you found process.argv[2] to work on the bonus!

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that you also have a saySeeYaLater( ) in greet.js you'll want to make sure you also invoke that function here in index.js.

19 changes: 19 additions & 0 deletions lib/greet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'use strict';

module.exports = exports = {};
var name = process.argv[2];

exports.sayHi = function(name) {
if(arguments.length === 0) throw new Error('name not provided');
console.log(`Hi ${name}!`);
return `Hi ${name}!`;
};

exports.saySeeYaLater = function(petName) {
if(arguments.length === 0) throw new Error('pet name not provided');
console.log(`See ya later, ${petName}!`);
return `See ya later, ${petName}!`;
};

exports.sayHi(name);
exports.saySeeYaLater('Gaara');
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you are already using module.exports to export this greet.js file, it is not necessary to use exports again on lines 18-19. By nature of module.exports, everything within this file is already going to be exported :) You can then invoke both of these methods in index.js and you will still get the expected result.

30 changes: 30 additions & 0 deletions tests/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
'use strict';

const greet = require('../lib/greet.js');
const assert = require('assert');
var name = process.argv[2];

describe('Greet Module', function() {
describe('#sayHi', function() {
it('should return Hi {name}!', function() {
var result = greet.sayHi(name);
assert.ok(result === `Hi ${name}!`, 'not equal to Hi hawa!');
});
it('should throw a missing name error', function() {
assert.throws(function() {
greet.sayHi();
}, 'error not thrown');
});
});
describe('#saySeeYaLater', function() {
it('should return See ya later {petName}!', function(){
var results = greet.saySeeYaLater('Gaara');
assert.ok(results === 'See ya later, Gaara!', 'not equal to See ya later, Gaara!');
});
it('should throw a missing name error', function(){
assert.throws(function(){
greet.saySeeYaLater();
}, 'error not thrown');
});
});
});
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mocha doesn't accept command line arguments so process.argv[2] will always be undefined. A good work around for this would be to set process.argv[2] = 'string' and then you can test that it returns that value specifically.