diff --git a/README.md b/README.md index f01d5fe..3b53b70 100755 --- a/README.md +++ b/README.md @@ -1,8 +1,12 @@ -Node.js CouchDB Sample +Node.js CouchDB test Sample ================= + Implements a simple web application using CouchDB, with tests. Uses Grunt to run tests against an Express server, then generates reports with Xunit and Istanbul. This sample is built for Shippable, a docker based continuous integration and deployment platform. + + +[![Build Status](https://api.shippable.com/projects/54d9cce25ab6cc13528b686e/badge?branchName=master)](https://app.shippable.com/projects/54d9cce25ab6cc13528b686e/builds/latest) diff --git a/index.js b/index.js index 67f211c..a1e78c4 100755 --- a/index.js +++ b/index.js @@ -2,10 +2,22 @@ var express = require("express"), nano = require('nano')('http://localhost:5984'), app = express(); -nano.db.destroy('test'); -nano.db.create('test'); +var db = null; +nano.db.destroy('test', function(){ + nano.db.create('test', function(err, body){ + if(err) { + console.log('Error creating database'); + console.log(err); + return; + } + db = nano.db.use('test'); + + app.listen(3000, function () { + console.log('Express listening on port 3000'); + }); + }); +}); -var db = nano.db.use('test'); app.get("/", function (req, res) { res.send("Hey buddy!"); @@ -16,17 +28,16 @@ app.get("/:name", function (req, res) { if (body === undefined) { db.insert({'name': req.params.name}, req.params.name, function(err, b) { if (err) { + console.log('Error creating a new thing'); + console.log(err); res.send(500); } else { - res.send("Created a new thing with name " + req.params.name); + res.send({returnObj: b, created:true}); } }); } else { - res.send(body); + res.send({returnObj: body, created:false}); } }); }); -app.listen(3000, function () { - console.log('Express listening on port 3000'); -}); diff --git a/shippable.yml b/shippable.yml index a5ede7a..76e4aac 100755 --- a/shippable.yml +++ b/shippable.yml @@ -3,15 +3,21 @@ language: node_js # Version number node_js: - - 0.10.25 + - 0.10.31 + - 0.11 # CouchDB binds to 127.0.0.1 by default services: - couchdb +#test pr1 # The path for Xunit to output test reports env: + global: - XUNIT_FILE=shippable/testresults/result.xml + - secure: eHd8W6oPZ5x+yYmIrvrPh8EdON1J6Sdf0JthhAqWtisKJirbNbnnBsC6d4RlKUVPU20g1g66EvtJfzLJbihB2ZUfTqsI09Q/L4eDh+l3Gp1mWfvaL9YaVDID7pkVsBPFPw8mQtMzBf2AZeeWwM5ydrGO0yngUmUqDcy3oKDZzyyMw2aJKXJk1Wr1M9TGpGf/Rgvt59KyKY7yf8QN8l+Zsnc/IS5Lz2FgD2l4XUNSxbkSdZ0wFw2kV/9KidR7CpgO+GanZHtZCrUQRCVF4SC4djV4X9X34T9uQSSgFm10lmn37KXIYJN4YI7LrsQMMb2V0dUPDgDiTIKfOzs8o1cxnQ== + #- secure: pHx5dR/qpqAnTJo5GCm7FUzD5YVvmB+y5YmcrGK09TQtBsi3d+p9dyf6V0DnsuJy8gIDS71YnDjbnycdqnKgGevjul4fQkWF+T52DvF49q5PbkDkqAbzo2HIr2VIOboutuhSy+FwlQb7aGjq9/AHTKlQSubFCjqvouB1uw7R9thsvUBnW/Ea+h39W4+0mzpLp9k6tmCAGkj/tGEMXgiZQvjX/3wvM45F3x5eGl+2bkxRELSr51NJAcBYC8+6k5svo6utNKQFhBE2HxFwpkJsJEh4oSOMf0GqWs0Vea7RRlA3lLJ116gQNKh7GuKLgxXN38w+GXPU8beIRZfHTpCHNw== + - secure: nSB5a9lUKw2vzoKmT2iqCPrj8qFcfTB3Uox8DRPMxXGu5A9M/OaEZMEGoBEEdRjWTlJOGRtc4hdkSdPRtJ6pGzTbCK3p+Du1kwO/7QukWDiNEB+dSOxBdbh0mZXVqlOwJLZ2npI5KROpRCCe2qxah/NnMvc5qqcdCkSZf9uhQqm+RbYCwPs/xZqK857whtnHiqvTOnEojBH0Hb2lBLsolRMfpH19UFAvh1XAf4nq+mNZZoaSCFc8LEovfnXPUTbJXtWWzpJKy2ncg98MtRKerxOTUpl7uVbOuGtIDu8ikQ1QzFwOTaM+f2Gz6Tyky/dV28D95Q9Oc6s5vM5Ea3rSzg== # Create directories for test and coverage reports before_script: @@ -21,8 +27,18 @@ before_script: # Running the tests with grunt script: - grunt - + - echo $COMPARE_URL + - echo $LAST_SUCCESSFUL_BUILD_TIMESTAMP + - echo $key1 and $key2 + # Tell istanbul to generate a coverage report after_script: + - echo $key - ./node_modules/.bin/istanbul cover grunt -- -u tdd - ./node_modules/.bin/istanbul report cobertura --dir shippable/codecoverage/ + - echo $BUILD_NUMBER + - echo $BUILD_URL +archive: true + +#build_image: shippable/minv2:beta +#cache: true diff --git a/test.js b/test.js index 6c69b23..7296498 100755 --- a/test.js +++ b/test.js @@ -19,8 +19,8 @@ describe("Persistence", function () { superagent.get("http://localhost:3000/doobie") .end(function (e, res) { (e === null).should.equal(true); - var response = (res.text.indexOf("new") !== -1); - expect(response).to.equal(true); + var response = res.body; + expect(response.created).to.equal(true); done(); }); }); @@ -29,6 +29,8 @@ describe("Persistence", function () { .end(function (e, res) { (e === null).should.equal(true); var response = res.body; + expect(response.created).to.equal(false); + response = response.returnObj; response.should.have.property("name", "doobie"); done(); });