Skip to content

Commit

Permalink
Merge branch 'release/0.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanfoster committed Dec 4, 2016
2 parents 6bf0f00 + 3c0bab8 commit 5eb54f3
Show file tree
Hide file tree
Showing 7 changed files with 173 additions and 17 deletions.
30 changes: 16 additions & 14 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
sudo: false
language: node_js
node_js:
- "6"
- "5"
- "4"

- '6'
- '5'
- '4'
cache:
directories:
- node_modules

- node_modules
before_install:
- "npm config set spin false"

- npm config set spin false
os:
- osx
- linux

- osx
- linux
script: npm run test:cover

after_script:
cat coverage/lcov.info | node_modules/coveralls/bin/coveralls.js
after_script: cat coverage/lcov.info | node_modules/coveralls/bin/coveralls.js
deploy:
provider: npm
email: dylan947@gmail.com
api_key:
secure: Y7mnpEAfhjICTKIjfAyCMz11irbNQYGA+0gZ768uBadtn2A8IEuVSc6SUOQwcssCGlpWNzLw9h28uOl209HeVruH8u4jqhtATBQMH38StpCCaUZWD64bQblgu2tzBhSrrChag3bAmRuiKKyhmebpV59Ag6koaqR9WRtYeeCQRdmChcyhwLVlTiP8TNz4uJMeBAVWDqAXkNBWsWOQpRfK77XIPC8P8H8nOigGVVWt4zjKX2qVbFc45Yn8JTtbofKpx2CU5IYspk/eMKuRHwbcx1zXJ4DMRi4/iLDcsqkl0WoyIGkSfxkpbvfJtUrrg9N2JLtka+JvLpL7c27qxY2RSyPK3L3On0tFRGIAHPmur93zXALaaztiN8SIrw2MoGYoRjqzhRf2RHHNwbxS7HW+xr98ymfNXfJfSgZHsS4wOnpm8cm8TLFVJQatu9Cn4pgo/QEEJvdY77zF1tRVrHQzl+CP9zDzPFM0ntqgO1sbmccxxL6pI4TMB4IrWHje2Y9s5lrWRWRSUGZ+evnDkoOGjoaCS5UW03Qf7s4H1ACZDV5ib9/IHw/9hxGyLfP6IrGY4RT1vg51Eqe3uoRHfJpeeAn3socTcuMH9oio7PWXHZ5uyGtGFyu+Z9sSQRibDd2TxenTRZn0tPbhwREionvY9Hf0gFexvtP34IR62GQywrI=
on:
tags: true
repo: dylanfoster/parch
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
<a name="0.3.0"></a>
# [0.3.0](https://github.com/dylanfoster/parch/compare/0.2.0...v0.3.0) (2016-12-04)


### Features

* **application:** add ability to override logging directory and serializers ([d824fe9](https://github.com/dylanfoster/parch/commit/d824fe9))



<a name="0.2.0"></a>
# [0.2.0](https://github.com/dylanfoster/parch/compare/0.1.0...v0.2.0) (2016-11-28)

Expand Down
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,21 @@ const parch = new parch.Application({
},
models: {
dir: path.resolve(__dirname, "models")
},
logging: {
dir: path.resolve(__dirname, 'logs'),
serializers: {
req(req) {
return {
url: req.url
}
},
res(res) {
return {
statusCode: res.statusCode
}
}
}
}
}
});
Expand Down Expand Up @@ -310,3 +325,8 @@ Need to handle your own errors? `controller.errors` contains all of [restify-err
- `connection(Object)` [Sequelize connection options](http://docs.sequelizejs.com/en/latest/docs/getting-started/)
- `models`
- `dir(String)`: The path to your models directory. **Default**: `__dirname/models`
- **logging**
- `dir(String)`: Path where logs should be saved
- `serializers(Object)`:
- `req(Function)`: your request serializer. takes the request as its only argument
- `res(Function)`: your response serializer. takes the response as its only argument
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "parch",
"version": "0.2.0",
"version": "0.3.0",
"description": "Restify + Sequelize",
"main": "index.js",
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions src/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,11 @@ class Application {
options.database.connection = options.database.connection || DEFAULT_CONNECTION_SETTINGS;
options.database.models = options.database.models || {};
options.database.models.dir = options.database.models.dir || DEFAULT_MODEL_LOOKUP_PATH;
options.logging = options.logging || {};
options.server = options.server || {};

// TODO: add logger options
options.server.log = options.server.log || Logger.create();
options.server.log = options.server.log || Logger.create(null, options.logging);
options.server.middlewares = options.server.middlewares || [];

const app = options.app || restify.createServer(options.server);
Expand All @@ -64,7 +65,6 @@ class Application {
path: options.database.models.dir
});

// TODO: this should be separate from log once we have logger options
this.logger = options.server.log;
this.modelManager = new ModelManager({ connection });
this._addModels();
Expand Down
124 changes: 124 additions & 0 deletions test/application_tests.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
"use strict";

import fs from "fs";
import path from "path";

import chai, { expect } from "chai";
import del from "del";
import jwt from "jsonwebtoken";
import restify from "restify";
import sinon from "sinon";
import sinonChai from "sinon-chai";
import stream from "stream";
import supertest from "supertest";

chai.use(sinonChai);
Expand Down Expand Up @@ -152,4 +155,125 @@ describe("Application", function () {
.end(done);
});
});

describe("logging", function () {
let loggingDir, messages, writable;

beforeEach(function () {
loggingDir = path.resolve(__dirname, "fixtures/custom-logs");
messages = [];
stream.write = message => {
messages.push(JSON.parse(message));
};
});

afterEach(function () {
return del([`${loggingDir}/**/*.log`, `!${loggingDir}`]);
});

it("allows for a custom directory", function (done) {
application = new Application({
controllers: {
dir: path.resolve(__dirname, "fixtures", "controllers")
},
database: {
connection,
models: { dir: path.resolve(__dirname, "fixtures/models") }
},
logging: { dir: loggingDir }
});
application.map(function () {
this.resource("user");
});
supertest(application.getApp())
.get("/users")
.end(function (err, res) {
if (err) { return done(err); }

fs.readdir(loggingDir, (err2, files) => {
if (err2) { return done(err2); }

const log = JSON.parse(
fs.readFileSync(path.join(loggingDir, files.filter(file => file.match(/\.log/))[0])).toString()
);

expect(log.res.statusCode).to.eql(200);

done();
});
});
});

it("allows for custom request serializer", function (done) {
application = new Application({
controllers: {
dir: path.resolve(__dirname, "fixtures", "controllers")
},
database: {
connection,
models: { dir: path.resolve(__dirname, "fixtures/models") }
},
logging: {
serializers: {
req(req) {
return { url: req.url }
}
}
}
});

application.logger.addStream({
type: "stream",
stream
});
application.map(function () {
this.resource("user");
});
supertest(application.getApp())
.get("/users")
.end(function (err, res) {
if (err) { return done(err); }

expect(messages[0].req.url).to.eql("/users");
expect(messages[0].req).to.not.have.any.keys("httpVersion", "method");
done();
});
});

it("allows for custom response serializer", function (done) {
application = new Application({
controllers: {
dir: path.resolve(__dirname, "fixtures", "controllers")
},
database: {
connection,
models: { dir: path.resolve(__dirname, "fixtures/models") }
},
logging: {
serializers: {
res(res) {
return { statusCode: res.statusCode}
}
}
}
});

application.logger.addStream({
type: "stream",
stream
});
application.map(function () {
this.resource("user");
});
supertest(application.getApp())
.get("/users")
.end(function (err, res) {
if (err) { return done(err); }

expect(messages[0].res.statusCode).to.eql(200);
expect(messages[0].req).to.not.have.any.keys("headers");
done();
});
});
});
});
Empty file.

0 comments on commit 5eb54f3

Please sign in to comment.