-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests to reach 100 percent test coverage
- Loading branch information
Showing
7 changed files
with
152 additions
and
5 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 |
---|---|---|
@@ -1,5 +1,4 @@ | ||
module.exports = ({err, req, res}) => { | ||
console.log(e.stack) | ||
res.statusCode = 500; | ||
res.end("Internal server error") | ||
} |
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,23 @@ | ||
const assert = require('assert') | ||
|
||
const errorHandler = require('./../../src/defaults/error') | ||
|
||
describe("default error handler", function() { | ||
|
||
it('should set the error status code', () => { | ||
let mockRes = { | ||
end: function() {} | ||
} | ||
errorHandler({res: mockRes}) | ||
assert.strictEqual(mockRes.statusCode, 500) | ||
}) | ||
|
||
it('should call the end method with a message', () => { | ||
let mockRes = { | ||
end: function(msg) { | ||
assert.strictEqual("Internal server error", msg) | ||
} | ||
} | ||
errorHandler({res: mockRes}) | ||
}) | ||
}) |
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,25 @@ | ||
const assert = require('assert') | ||
|
||
const { Server } = require('http') | ||
const { Server: HttpsServer } = require('tls') | ||
const makeCreateServer = require('../../src/http/make-create-server') | ||
|
||
describe('make create server', function() { | ||
|
||
it("should return a function when passed an http option", () => { | ||
assert.strictEqual(typeof makeCreateServer(false), 'function') | ||
assert.strictEqual(typeof makeCreateServer({}), 'function') | ||
assert.strictEqual(typeof makeCreateServer(true), 'function') | ||
}) | ||
|
||
it("should make an HTTP server (not HTTPs) when HTTPS is disabled", () => { | ||
const makeserver = makeCreateServer(false) | ||
assert.strictEqual(makeserver(() => {}) instanceof Server, true) | ||
}) | ||
|
||
it("should make an HTTPs server (not HTTP) when HTTPS is enabled", () => { | ||
const makeserver = makeCreateServer({}) | ||
assert.strictEqual(makeserver(() => {}) instanceof HttpsServer, true) | ||
}) | ||
|
||
}) |
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,29 @@ | ||
const assert = require('assert') | ||
|
||
const makeFinal = require('./../../src/routes/make-final') | ||
|
||
describe('routes/make-final', function() { | ||
|
||
it('should return a routeable object when passed a configuration object', () => { | ||
assert.strictEqual(typeof makeFinal({}), 'object') | ||
assert.strictEqual(typeof makeFinal({ | ||
lost: () => {} | ||
}).handler, 'function') | ||
}) | ||
|
||
it('should bypass the static service when a static path is not provided', () => { | ||
const lost = () => {}; | ||
assert.strictEqual(makeFinal({lost}).handler, lost) | ||
}) | ||
|
||
it('should bypass the static service when the static option is false', () => { | ||
const lost = () => {}; | ||
assert.strictEqual(makeFinal({lost, static: false}).handler, lost) | ||
}) | ||
|
||
it('should attempt to serve static files when the static path is not false', () => { | ||
const lost = () => {}; | ||
assert.notStrictEqual(makeFinal({lost, static: "/"}).handler, lost) | ||
}) | ||
|
||
}) |
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,63 @@ | ||
const assert = require('assert') | ||
|
||
const makeMatcher = require('./../../src/routes/make-matcher') | ||
|
||
|
||
describe('routes/make-matcher', function() { | ||
|
||
const testPath = "/some-path"; | ||
const matcher = makeMatcher(path => { | ||
assert.strictEqual(path, testPath) | ||
return new RegExp(path) | ||
}) | ||
|
||
it("should take a function that constructs a regular expression to match the path", () => { | ||
matcher({ | ||
route: { | ||
path: testPath | ||
}, | ||
url: testPath | ||
}) | ||
}) | ||
|
||
it("should match the request method if given even if cases mismatch", () => { | ||
assert.strictEqual(matcher({ | ||
route: { | ||
path: testPath, | ||
method: "GET" | ||
}, | ||
url: testPath, | ||
method: "get" | ||
}), true) | ||
}) | ||
|
||
it("should fail to match if the methods are different", () => { | ||
assert.strictEqual(matcher({ | ||
route: { | ||
path: testPath, | ||
method: "GET" | ||
}, | ||
url: testPath, | ||
method: "post" | ||
}), false) | ||
}) | ||
|
||
it("should match all methods if no method is specified", () => { | ||
assert.strictEqual(matcher({ | ||
route: { path: testPath }, | ||
url: testPath, | ||
method: "post" | ||
}), true) | ||
assert.strictEqual(matcher({ | ||
route: { path: testPath }, | ||
url: testPath, | ||
method: "get" | ||
}), true) | ||
assert.strictEqual(matcher({ | ||
route: { path: testPath }, | ||
url: testPath, | ||
method: "head" | ||
}), true) | ||
}) | ||
|
||
}) |