-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Start on tests * Add .travis.yml * Clean up a bit * Test parseJson * Test routes * Test static * Switch methods and routes tests to supertest * Use http-errors instead of boom * Use path-match instead of path-to-regexp * Test mount * Add logo to readme * Cleanup
- Loading branch information
1 parent
6360ff8
commit 33c7da6
Showing
25 changed files
with
640 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
language: node_js | ||
node_js: | ||
- '7' | ||
- '6' | ||
before_install: | ||
- npm install -g [email protected] | ||
install: | ||
- yarn install --pure-lockfile | ||
script: | ||
- yarn test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
const Boom = require('boom') | ||
const { NotFound } = require('http-errors') | ||
|
||
const methods = handlers => req => | ||
handlers[req.method] | ||
? handlers[req.method](req) | ||
: Promise.reject(Boom.notFound()) | ||
new Promise((resolve, reject) => { | ||
handlers[req.method] | ||
? resolve(handlers[req.method](req)) | ||
: reject(new NotFound()) | ||
}) | ||
|
||
module.exports = methods |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
module.exports = (Location, statusCode=302) => ({ | ||
module.exports = (location, statusCode=302) => ({ | ||
body: '', | ||
headers: { Location }, | ||
headers: { location }, | ||
statusCode | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,14 @@ | ||
const { assoc, pluck, zipObj } = require('ramda') | ||
const Boom = require('boom') | ||
const pathToReg = require('path-to-regexp') | ||
|
||
const routes = handlers => req => { | ||
for (var route in handlers) { | ||
const keys = [], | ||
vals = pathToReg(route, keys).exec(req.pathname) | ||
|
||
if (vals) { | ||
req = assoc('params', zipObj(pluck('name', keys), vals.slice(1)), req) | ||
return handlers[route](req) | ||
const { merge } = require('ramda') | ||
const { NotFound } = require('http-errors') | ||
const pathMatch = require('path-match')() | ||
|
||
const routes = handlers => req => | ||
new Promise((resolve, reject) => { | ||
for (var route in handlers) { | ||
const params = pathMatch(route)(req.pathname) | ||
if (params) return resolve(handlers[route](merge(req, { params }))) | ||
} | ||
} | ||
|
||
return Promise.reject(Boom.notFound()) | ||
} | ||
reject(new NotFound()) | ||
}) | ||
|
||
module.exports = routes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
testing testing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
const { expect } = require('chai') | ||
|
||
const html = require('../lib/html') | ||
|
||
describe('html', function() { | ||
const body = '<html></html>', | ||
res = html(body) | ||
|
||
it('includes the body in the response', function() { | ||
expect(res.body).to.equal(body) | ||
}) | ||
|
||
it('sets the "content-type" header to "text/html"', function() { | ||
expect(res.headers).to.be.an('object') | ||
expect(res.headers['content-type']).to.equal('text/html') | ||
}) | ||
|
||
it('sets the statusCode to 200', function() { | ||
expect(res.statusCode).to.equal(200) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
const { expect } = require('chai') | ||
|
||
const json = require('../lib/json') | ||
|
||
describe('json', function() { | ||
const body = { foo: 'bar' }, | ||
res = json(body) | ||
|
||
it('stringifies the body', function() { | ||
expect(res.body).to.equal(JSON.stringify(body)) | ||
}) | ||
|
||
it('sets the "content-type" header to "application/json"', function() { | ||
expect(res.headers).to.be.an('object') | ||
expect(res.headers['content-type']).to.equal('application/json') | ||
}) | ||
|
||
it('sets the statusCode to 200', function() { | ||
expect(res.statusCode).to.equal(200) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = () => { | ||
const spy = x => spy.calls.push(x) | ||
spy.calls = [] | ||
spy.reset = () => spy.calls.length = 0 | ||
return spy | ||
} |
Oops, something went wrong.