forked from outmoded/university
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Assignment 3] Testing + Code Coverage
Closes outmoded#79 This introduces basic testing and code coverage at 94.74% There is definitely still some weirdness with testing error handling when Hoek is asserting. I'm still not sure the best way to teardown the server if no callback is given.
- Loading branch information
Myles Borins
committed
Mar 25, 2015
1 parent
6f84807
commit bd9b142
Showing
3 changed files
with
96 additions
and
1 deletion.
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,52 @@ | ||
// Load modules | ||
|
||
var Code = require('code'); | ||
var Lab = require('lab'); | ||
var lib = require('../lib'); | ||
|
||
|
||
// Declare internals | ||
|
||
var internals = {}; | ||
|
||
|
||
// Test shortcuts | ||
|
||
var lab = exports.lab = Lab.script(); | ||
var describe = lab.describe; | ||
var it = lab.it; | ||
var expect = Code.expect; | ||
|
||
describe('lib', function() { | ||
|
||
describe('.init()', function () { | ||
|
||
it('should throw when given an invalid port', function (done) { | ||
|
||
expect(function () { | ||
|
||
lib.init('I am going to throw'); | ||
}).to.throw('Invalid connection options {\n \"router\": {\n \"isCaseSensitive\": true,\n \"stripTrailingSlash\": false\n },\n \"routes\": {\n \"cache\": {\n \"statuses\": [\n 200\n ]\n },\n \"cors\": null,\n \"files\": {\n \"relativeTo\": \".\"\n },\n \"json\": {\n \"replacer\": null,\n \"space\": null,\n \"suffix\": null\n },\n \"payload\": {\n \"failAction\": \"error\",\n \"maxBytes\": 1048576,\n \"output\": \"data\",\n \"parse\": true,\n \"timeout\": 10000,\n \"uploads\": \"/var/folders/79/1_fjgmlj047ft1bc5s1hd_780000gn/T/\"\n },\n \"response\": {\n \"options\": {}\n },\n \"security\": null,\n \"state\": {\n \"parse\": true,\n \"failAction\": \"error\"\n },\n \"timeout\": {\n \"server\": false\n },\n \"validate\": {\n \"options\": {}\n }\n },\n \"port\" \u001b[31m[1, 2, 3]\u001b[0m: \"I am going to throw\"\n}\n\u001b[31m\n[1] \"port\" must be a number\n[2] \"port\" with value \"I am going to throw\" fails to match the required pattern: /\\//\n[3] \"port\" with value \"I am going to throw\" fails to match the required pattern: /^\\\\\\\\\\.\\\\pipe\\\\/\u001b[0m'); | ||
done(); | ||
}); | ||
|
||
it('should return an instance of server', function (done) { | ||
|
||
var server = lib.init(); | ||
setTimeout(function () { | ||
expect(server).to.not.be.undefined(); | ||
server.stop(done); | ||
}, 275); | ||
}); | ||
|
||
it('should create a server on port 8000 when no port is given', function (done) { | ||
|
||
lib.init(function (err, server) { | ||
|
||
expect(err).to.be.undefined(); | ||
expect(server.info.port).to.equal(8000); | ||
server.stop(done); | ||
}); | ||
}); | ||
}); | ||
}); |
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,38 @@ | ||
// Load modules | ||
|
||
var Code = require('code'); | ||
var Lab = require('lab'); | ||
var lib = require('../lib'); | ||
var Pkg = require('../package.json'); | ||
|
||
|
||
// Declare internals | ||
|
||
var internals = {}; | ||
|
||
|
||
// Test shortcuts | ||
|
||
var lab = exports.lab = Lab.script(); | ||
var describe = lab.describe; | ||
var it = lab.it; | ||
var expect = Code.expect; | ||
|
||
|
||
describe('version', function() { | ||
|
||
it('should return expected data', function (done) { | ||
|
||
lib.init(function (err, server) { | ||
|
||
expect(err).to.be.undefined(); | ||
expect(server.info.port).to.equal(8000); | ||
server.inject('/version', function (response) { | ||
|
||
expect(response.statusCode).to.equal(200); | ||
expect(response.result.version).to.equal(Pkg.version); | ||
server.stop(done); | ||
}); | ||
}); | ||
}); | ||
}); |