aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Burwell <ben@benburwell.com>2015-08-02 21:36:15 -0400
committerBen Burwell <ben@benburwell.com>2015-08-02 21:36:15 -0400
commit3adb8f65ed5dadd79469c56948fef0a7dde614bc (patch)
treeac122c9fed45522c56bebb1173861eae16d4f25a
parent52aeca23f6c9a86afbaec278bc2fcda0993e3d00 (diff)
parent8577be77e6ead88e7d9baf86f026fac4aeea4049 (diff)
Merge pull request #7 from benburwell/add-server-testsHEADmaster
Start some tests for the server
-rw-r--r--package.json1
-rw-r--r--src/index.js10
-rw-r--r--test/server.js39
3 files changed, 47 insertions, 3 deletions
diff --git a/package.json b/package.json
index 3f8c90c..feb2a70 100644
--- a/package.json
+++ b/package.json
@@ -19,6 +19,7 @@
},
"devDependencies": {
"mocha": "^2.2.5",
+ "request": "^2.60.0",
"should": "^7.0.2"
}
}
diff --git a/src/index.js b/src/index.js
index 9c1019e..71b70df 100644
--- a/src/index.js
+++ b/src/index.js
@@ -190,6 +190,10 @@ server.route({
}
});
-server.start(function() {
- console.log('Server running!');
-});
+if (!module.parent) {
+ server.start(function() {
+ console.log('Server running!');
+ });
+}
+
+module.exports = server;
diff --git a/test/server.js b/test/server.js
new file mode 100644
index 0000000..a003b50
--- /dev/null
+++ b/test/server.js
@@ -0,0 +1,39 @@
+var should = require('should');
+var request = require('request');
+var server = require('../src');
+
+var ROOT_URL = 'http://127.0.0.1:8000';
+
+describe('Server', function() {
+
+ before(function() {
+ server.start();
+ });
+
+ after(function() {
+ server.stop();
+ });
+
+ describe('Basic Connectivity', function() {
+ it('should be available on port 8000', function() {
+ request.get(ROOT_URL, function(err, response, body) {
+ response.should.be.html();
+ });
+ });
+
+ it('should serve the index', function() {
+ request.get(ROOT_URL, function(err, response, body) {
+ body.should.not.be.empty();
+ });
+ })
+ });
+
+ describe('Search results', function() {
+ it('should display search results', function() {
+ request.get(ROOT_URL + '/search?q=do+re+mi', function(err, res, body) {
+ body.should.not.be.empty();
+ response.should.have.status(200);
+ });
+ });
+ });
+});