-
Notifications
You must be signed in to change notification settings - Fork 116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix for #68, added utility functions, more descriptive error messages #71
Conversation
First, we should make a hard rule not to take this kind of stuff without tests. If it helps, you can add a Secondly, manipulating paths this way is potentially error prone - |
"mocha": "^2.3.4", | ||
"chai": "^3.4.1", | ||
"supertest": "^2.0.1", | ||
"mocha": "^3.2.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I previously downgraded some dependencies here to make things work with older versions of node. Surpried this works.
use a module for this. Do not write custom code to deal with pathing, separators, etc. |
This can go in the next release, no rush. |
I realize this is used for cosmetic display purposes only, so I think we can live without tests for it. I still believe these urls should be combined with something like https://www.npmjs.com/package/url-join. I fixed the places where we combine paths with |
I was actually going to change the intent of the PR. Right now, we have a bunch of repetitive code, specifically with loading the modules and other files, and I was thinking that it'd make more sense to make a small utils file that contains any/all helper functions. I'll update the PR in a couple of hours. |
If you don't mind looking/merging #72 first before it becomes a big conflict ... |
index.js
Outdated
@@ -26,13 +26,13 @@ var appServer = function(config) { | |||
app_dir: 'apps' | |||
}; | |||
|
|||
self.config = defaults(config, defaultOptions); | |||
self.config = utils.defaults(config, defaultOptions); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a wrapper for a require
, seems unnecessary as it provides no additional value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just moved defaults in utils.js
since it is technically a 'utility' function. I can move it back though.
index.js
Outdated
if (!pkg || !pkg.main || !pkg.name) { | ||
self.error(" failed to load " + package_json); | ||
return; | ||
} | ||
|
||
var main = fs.realpathSync(path.join(app_dir, dir, pkg.main)); | ||
if (!fs.existsSync(main) || !fs.statSync(main).isFile()) { | ||
var main = path.join(__dirname, app_dir, dir, pkg.main); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This inserts __dirname
, which is a change in behavior from a previous version. At the very least it needs to be documented in both README and UPGRADING.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, I did do some testing and it is kind of a breaking change. I'll open a new issue in the meantime.
index.js
Outdated
}); | ||
}; | ||
server_files(server_dir).forEach(function(file) { | ||
file = fs.realpathSync(path.join(server_dir, file)); | ||
file = path.join(__dirname, server_dir, file); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above with __dirname
.
index.js
Outdated
var privateKey = fs.readFileSync(privateKeyFile, 'utf8'); | ||
var certificate = fs.readFileSync(certificateFile, 'utf8'); | ||
if (utils.isValidFile(privateKeyFile) && utils.isValidFile(certificateFile)) { | ||
var privateKey = utils.readFile(privateKeyFile, 'utf8'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
readFile
doesn't take two parameters, the utf8
is implied.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. Thanks!
package.json
Outdated
@@ -20,21 +20,23 @@ | |||
"license": "MIT", | |||
"dependencies": { | |||
"alexa-app": "^3.0.0", | |||
"alexa-verifier-middleware": "^0.1.8", | |||
"alexa-verifier-middleware": "^0.1.9", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is a required change, the library works fine with 0.1.8, doesn't it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, since alexa-app already uses alexa-verifier-middleware
already, it will probably be removed.
package.json
Outdated
"bluebird": "^3.4.7", | ||
"body-parser": "~1.16.0", | ||
"ejs": "~2.5.5", | ||
"express": "~4.14.1", | ||
"hotswap": "^1.1.0", | ||
"lodash.defaults": "^4.2.0" | ||
"lodash.defaults": "^4.2.0", | ||
"lodash.endswith": "^4.2.1", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These aren't used, posix.
is better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. Thanks!
test/test-utils.js
Outdated
var utils = require("../utils"); | ||
|
||
describe("Utilities testing", function() { | ||
it("checks the integrity of the utilities", function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO this isn't a useful test. The actual calls matter, while the fact that these functions are declared seems superfluous.
test/test-utils.js
Outdated
chai.config.includeStack = true; | ||
var utils = require("../utils"); | ||
|
||
describe("Utilities testing", function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In BDD you describe what "things are" and "how they behave", instead of what you're doing. So this should just be Utils
.
test/test-utils.js
Outdated
]); | ||
}); | ||
|
||
describe("File verification tests", function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isValidFile
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean that it should be describe("isValidFile", function() {
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, because it describes the functionality of that function. If you want to be fancy you can add a period in front of it :) Some people do #isValidFile
or .isValidFile
utils.js
Outdated
|
||
var defaults = require("lodash.defaults"); | ||
|
||
// Utility functions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment here isn't helpful. It's pretty clear that utils declares utility functions. However you can document each individual function if you want.
@@ -27,13 +27,13 @@ Modify the "Stable Release" section in [README.md](README.md). Change the text t | |||
``` | |||
## Stable Release | |||
|
|||
You're reading the documentation for the stable release of alexa-app-server, 2.4.0. | |||
You're reading the documentation for the stable release of alexa-app-server, 3.0.1. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since these are examples I never change them, but no big deal.
@@ -2,6 +2,7 @@ | |||
|
|||
### 3.0.1 (Next) | |||
|
|||
* [#71](https://github.com/alexa-js/alexa-app-server/pull/71): Fixed [#68](https://github.com/alexa-js/alexa-app-server/issues/68), added utility functions, more descriptive error messages - [@tejashah88](https://github.com/tejashah88). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's important in changelog is to describe the actual fix to be helpful for the person reading it. So for example:
* [#71](https://github.com/alexa-js/alexa-app-server/pull/71), [#68](https://github.com/alexa-js/alexa-app-server/issues/68): Fixed log output containing multiple slashes - [@tejashah88](https://github.com/tejashah88).
Merged via 2be0f02. |
No description provided.