- Patch Requirements
- Logging
- Style Guide
- Unit Tests
- 1 commit per issue PR.
- Tests pass locally on your machine. See the README for the most up-to-date way to run tests
- Confirm that travis-ci is passing
In the PR, confirm that travis-ci has passed the tests. In every pull request, you'll see this when travis-ci is running:
And this when tests have passed:
Our logging module provides four logging methods:
var log = require('./bin/logger');
log.info(...);
log.warn(...);
log.error(...);
log.fatal(...);
Whenever a successful request
occurs, after a response is sent, log the req
,
res
and data objects using info
:
res.status(200).send(student);
log.info({
req: req,
res: res,
student: student
});
If a request is unsuccessful, our error handling middleware will catch and log
it with warn
on a 404, or error
on anything else.
If you are programming an error case that is guaranteed to crash the program,
or should cause the server to abort, log the error with fatal
:
case 'EADDRINUSE':
log.fatal(bind + ' is already in use');
process.exit(1);
break;
Follow this styling for all code commited on the front or back end:
// Single line comments to explain stuff
var camelCaseVariableNames;
/**
* Multiline comments for section names ONLY
*/
function CapitalizedCamelClassNames() {
// Constructor logic here
}
function camelCasedFunctionNames() {
/**
* Prefer early returns, like this:
*/
if (failCondition) { // `failCondition == true` or `failCondition != undefined` is usually unnecessary
// Conditional logic here
return;
}
if (!otherCondition) {
// Conditional logic here
return;
}
/**
* Instead of this:
*/
if (failCondition) {
// Conditional logic here
} else if(!otherCondition) {
// Conditional logic here
}
}
// Space before curly braces:
function codeBlock() {}
// vs
function codeBlock(){}
xx// Two
xxxx// Space
xxxxxx// Indents
function niceAndCompact {
If (derp) {
return;
}
}
// Simple single statement if conditions:
if (err) throw err;
// vs
if (err) {
throw err;
}
// Comments directly above code block they relate to
function blah() {
// ...
}
// vs
// Comments not directly above code block
function blah() {
// ...
}
All of our unit tests are required into 1 main test file - /tests/index.js
.
Please be sure to add in your new test suite to this file, since our automated
test runners all point to this location.
Any reusable helper functions that can be placed in a new module test should be added
to utils.js
, and all of the api
route tests are logically placed in the api
subfolder.