Skip to content

Commit

Permalink
Update tests to be less weird and report more accurate coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-coles committed Apr 20, 2016
1 parent aac1079 commit ff1565e
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 20 deletions.
37 changes: 23 additions & 14 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,23 @@ var auth = function (req, res, next) {
};
};

// ensure log directory exists
fs.existsSync(logDirectory) || fs.mkdirSync(logDirectory)
/*istanbul ignore if*/
if (production === "-p") {
// ensure log directory exists
fs.existsSync(logDirectory) || fs.mkdirSync(logDirectory)

// create a rotating write stream
var accessLogStream = FileStreamRotator.getStream({
date_format: 'YYYYMMDD',
filename: logDirectory + '/access-%DATE%.log',
frequency: 'daily',
verbose: false
})
// create a rotating write stream
var accessLogStream = FileStreamRotator.getStream({
date_format: 'YYYYMMDD',
filename: logDirectory + '/access-%DATE%.log',
frequency: 'daily',
verbose: false
})

// setup the logger
app.use(morgan('short', {stream: accessLogStream}))
app.use(morgan('short'));
// setup the logger
app.use(morgan('short', {stream: accessLogStream}))
app.use(morgan('short'));
}

app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
Expand All @@ -68,7 +71,7 @@ if (production === "-p") {
app.use('/log', auth, serveIndex('log', {'icons': true}));
}

app.listen(3000, function () {
var server = app.listen(3000, function () {
console.log('Now accepting connections on port 3000.');
});

Expand All @@ -92,4 +95,10 @@ if (production === "-p") {
process.on('SIGINT', function() {
console.log( "\nRecieved Ctrl-C, shutting down." );
process.exit(0);
})
});

module.exports = {
close: function () {
server.close();
}
};
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
"description": "Server for the IP project",
"main": "index.js",
"scripts": {
"pretest": "istanbul cover index.js > debug.log &",
"test": "sleep 2; node jasmine-runner.js; node utils/flushdb.js",
"posttest": "killall -2 node"
"test": "istanbul cover jasmine-runner.js && node utils/flushdb.js"
},
"repository": {
"type": "git",
Expand Down
2 changes: 2 additions & 0 deletions spec/friends-ops-spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var request = require("request");
var base_url = "http://localhost:3000";
var server = require("../index.js");

describe("Friends Operations", function () {

Expand Down Expand Up @@ -137,6 +138,7 @@ describe("Friends Operations", function () {
expect(response.statusCode).toBe(200);
expect(body.success).toBe(0);
expect(body.error).toBe(3);
server.close();
done();
});
});
Expand Down
1 change: 1 addition & 0 deletions spec/misc-ops-spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var request = require("request");
var base_url = "http://localhost:3000";
var server = require("../index.js");

describe("Misc Operations", function () {
describe("GET /hello/:name", function () {
Expand Down
4 changes: 1 addition & 3 deletions spec/user-ops-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ describe("User Operations", function () {
request(register_user("foo123"), function (error, response, body) {
expect(response.statusCode).toBe(200);
expect(body.registered).toBe(1);
if (body["auth-key"]) {
expect(body["auth-key"].length).toBe(60);
}
expect(body["auth-key"].length).toBe(60);
expect(body.error).toBe(0);
done();
});
Expand Down

0 comments on commit ff1565e

Please sign in to comment.