Skip to content

Commit

Permalink
Merge 85af4ee into 381d9be
Browse files Browse the repository at this point in the history
  • Loading branch information
nicosommi committed Jul 16, 2015
2 parents 381d9be + 85af4ee commit 42ca273
Show file tree
Hide file tree
Showing 11 changed files with 463 additions and 256 deletions.
9 changes: 4 additions & 5 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"no-duplicate-case": 2,
"no-else-return": 0,
"no-empty": 2,
"no-empty-class": 2,
"no-empty-character-class": 2,
"no-empty-label": 2,
"no-eq-null": 0,
"no-eval": 2,
Expand All @@ -42,7 +42,7 @@
"no-extra-boolean-cast": 2,
"no-extra-parens": 0,
"no-extra-semi": 2,
"no-extra-strict": 2,
"strict": 2,
"no-fallthrough": 2,
"no-floating-decimal": 0,
"no-func-assign": 2,
Expand Down Expand Up @@ -108,7 +108,7 @@
"no-var": 0,
"no-warning-comments": [0, { "terms": ["todo", "fixme", "xxx"], "location": "start" }],
"no-with": 2,
"no-wrap-func": 2,
"no-extra-parens": 2,

"block-scoped-var": 0,
"brace-style": [0, "1tbs"],
Expand All @@ -128,7 +128,6 @@
"func-style": [0, "declaration"],
"generator-star": 0,
"generator-star-spacing": 0,
"global-strict": [2, "never"],
"guard-for-in": 0,
"handle-callback-err": 0,
"indent": 0,
Expand Down Expand Up @@ -172,4 +171,4 @@
"wrap-regex": 0,
"yoda": [2, "never"]
}
}
}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ pids
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage file
lcov.info

# Coverage directory used by tools like istanbul
coverage

Expand Down
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ language: node_js
node_js:
- '0.12'
- '0.11'
- '0.10'
- 'iojs-v1'
- 'iojs-v2'
script: npm test
before_script:
- npm install
after_success:
- ./node_modules/coveralls/bin/coveralls.js < ./lcov.info

91 changes: 73 additions & 18 deletions es5/lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,20 @@ Object.defineProperty(exports, "__esModule", {
value: true
});

var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; desc = parent = getter = undefined; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; continue _function; } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } };

var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var _events = require("events");

var _events2 = _interopRequireDefault(_events);

var _responseJs = require("./response.js");

var _responseJs2 = _interopRequireDefault(_responseJs);
Expand All @@ -18,7 +26,8 @@ var express = require("express");
var bodyParser = require("body-parser");

var _createRequest = Symbol(),
_createResponse = Symbol();
_createResponse = Symbol(),
_defineExpressRoute = Symbol();

var Router = (function () {
function Router() {
Expand Down Expand Up @@ -83,40 +92,58 @@ var Router = (function () {
return new _responseJs2["default"](expressResponse, this._middlewares);
}
}, {
key: "get",
value: function get(path, callback) {
key: _defineExpressRoute,
value: function value(method, path) {
var _this = this;

this._express.get(path, function (expressRequest, expressResponse) {
callback(_this[_createRequest](expressRequest), _this[_createResponse](expressResponse));
var route = new Route(path, this);
route.on("callback", function (routeCallback) {
_this._express[method](path, function (expressRequest, expressResponse) {
routeCallback(_this[_createRequest](expressRequest), _this[_createResponse](expressResponse));
});
});

return route;
}
}, {
key: "get",
value: function get(path, callback) {
var route = this[_defineExpressRoute]("get", path);

if (callback !== undefined) {
route.then(callback);
}
return route;
}
}, {
key: "post",
value: function post(path, callback) {
var _this2 = this;
var route = this[_defineExpressRoute]("post", path);

this._express.post(path, function (expressRequest, expressResponse) {
callback(_this2[_createRequest](expressRequest), _this2[_createResponse](expressResponse));
});
if (callback !== undefined) {
route.then(callback);
}
return route;
}
}, {
key: "put",
value: function put(path, callback) {
var _this3 = this;
var route = this[_defineExpressRoute]("put", path);

this._express.put(path, function (expressRequest, expressResponse) {
callback(_this3[_createRequest](expressRequest), _this3[_createResponse](expressResponse));
});
if (callback !== undefined) {
route.then(callback);
}
return route;
}
}, {
key: "delete",
value: function _delete(path, callback) {
var _this4 = this;
var route = this[_defineExpressRoute]("delete", path);

this._express["delete"](path, function (expressRequest, expressResponse) {
callback(_this4[_createRequest](expressRequest), _this4[_createResponse](expressResponse));
});
if (callback !== undefined) {
route.then(callback);
}
return route;
}
}, {
key: "use",
Expand Down Expand Up @@ -164,4 +191,32 @@ var Request = (function () {
return Request;
})();

exports.Request = Request;
exports.Request = Request;

var Route = (function (_EventEmitter) {
function Route(type, path, router) {
_classCallCheck(this, Route);

_get(Object.getPrototypeOf(Route.prototype), "constructor", this).call(this);
this.setMaxListeners(0);
Object.defineProperties(this, {
"type": { value: type },
"path": { value: path },
"router": { value: router }
});
}

_inherits(Route, _EventEmitter);

_createClass(Route, [{
key: "then",
value: function then(callback) {
Object.defineProperty(this, "callback", { value: callback });
this.emit("callback", this.callback);
}
}]);

return Route;
})(_events2["default"]);

exports.Route = Route;
23 changes: 23 additions & 0 deletions es5/spec/route.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"use strict";

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

var _libRouterJs = require("../lib/router.js");

var _libRouterJs2 = _interopRequireDefault(_libRouterJs);

describe("Route", function () {
describe("(methods)", function () {
it("should have a then function", function () {
new _libRouterJs.Route("/someroute").should.have.property("then");
});

it("should have a path propety after creating an instance", function () {
new _libRouterJs.Route("/someroute").should.have.property("path");
});

it("should have a router propety after creating an instance", function () {
new _libRouterJs.Route("/someroute", new _libRouterJs2["default"]()).should.have.property("router");
});
});
});
138 changes: 138 additions & 0 deletions es5/spec/router.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,144 @@ describe("Router(...options)", function () {
});
});

describe("(chaining)", function () {
describe(".get", function () {
var route = undefined,
path = undefined,
url = undefined,
callback = undefined;

before(function (done) {
router = new _libRouterJs2["default"]();
callback = sinon.spy(function (request, response) {
response.end();
});
path = "/chained-spock";
url = "" + host + path;
route = router.get(path);
route.then(callback);
router.listen(portNumber, done);
});

after(function (done) {
router.close(done);
});

it("should return a Route instance", function () {
route.should.be.instanceOf(_libRouterJs.Route);
});

it("should callback", function (done) {
_appeal2["default"].get.url(url).results(function () {
callback.called.should.be["true"];
done();
});
});
});

describe(".post", function () {
var route = undefined,
path = undefined,
url = undefined,
callback = undefined;

before(function (done) {
router = new _libRouterJs2["default"]();
callback = sinon.spy(function (request, response) {
response.end();
});
path = "/chained-spock";
url = "" + host + path;
route = router.post(path);
route.then(callback);
router.listen(portNumber, done);
});

after(function (done) {
router.close(done);
});

it("should return a Route instance", function () {
route.should.be.instanceOf(_libRouterJs.Route);
});

it("should callback", function (done) {
_appeal2["default"].post.url(url).results(function () {
callback.called.should.be["true"];
done();
});
});
});

describe(".put", function () {
var route = undefined,
path = undefined,
url = undefined,
callback = undefined;

before(function (done) {
router = new _libRouterJs2["default"]();
callback = sinon.spy(function (request, response) {
response.end();
});
path = "/chained-spock";
url = "" + host + path;
route = router.put(path);
route.then(callback);
router.listen(portNumber, done);
});

after(function (done) {
router.close(done);
});

it("should return a Route instance", function () {
route.should.be.instanceOf(_libRouterJs.Route);
});

it("should callback", function (done) {
_appeal2["default"].put.url(url).results(function () {
callback.called.should.be["true"];
done();
});
});
});

describe(".delete", function () {
var route = undefined,
path = undefined,
url = undefined,
callback = undefined;

before(function (done) {
router = new _libRouterJs2["default"]();
callback = sinon.spy(function (request, response) {
response.end();
});
path = "/chained-spock";
url = "" + host + path;
route = router["delete"](path);
route.then(callback);
router.listen(portNumber, done);
});

after(function (done) {
router.close(done);
});

it("should return a Route instance", function () {
route.should.be.instanceOf(_libRouterJs.Route);
});

it("should callback", function (done) {
_appeal2["default"]["delete"].url(url).results(function () {
callback.called.should.be["true"];
done();
});
});
});
});

describe("(middleware)", function () {
describe(".use(middleware)", function () {
var path = undefined,
Expand Down
Loading

0 comments on commit 42ca273

Please sign in to comment.