Add Integration testing to Blogging App
by John Vincent
Posted on April 21, 2017
Continuous Integration with Travis
Add Continuous Integration to the Blogging App. Deploy to Heroku using Mongo database at mLab.
From Thinkful course Node 2.3.4.
Final Result
Getting Started
Create Github repository: blog-challenge-tests-ci
cd MyDevelopment/github/thinkful
create-repo blog-challenge-tests-ciCopy source files from:
/Users/jv/Desktop/MyDevelopment/github/thinkful/mongoose-challenge-with-tests
to:
/Users/jv/Desktop/MyDevelopment/github/thinkful/blog-challenge-tests-ciInstall dependencies:
cd /Users/jv/Desktop/MyDevelopment/github/thinkful/blog-challenge-tests-ci
rm -rf node_modules
npm installTo run the tests:
npm testCommit to repository
Configure Travis CI
.travis.yml
language: node_js
node_js: node
services:
- mongodbGit commit but do not push
git add .
git commit -m "travis"Add Travis CI Service in Github
https://github.com/johnvincentio/blog-challenge-tests-ci
Settings, Integration & Services
Add service, Travis CI
Add Service (green button at bottom)Configure Travis
Travis Dashboard
https://travis-ci.org/
click icon (top-right)
Sync Account (top-right)
Check:
johnvincentio/blog-challenge-tests-ciGit commit to remote
git pushVerify Building
Travis Dashboard
https://travis-ci.org/
Select:
johnvincentio/blog-challenge-tests-ciDeploy to Heroku
Login to Travis CI
cd /Users/jv/Desktop/MyDevelopment/github/thinkful/blog-challenge-tests-ci
travis login --auto-passwordTo deploy to Heroku:
travis setup heroku
"return" to the questions.
git diff (see differences)
note deploy block added to .travis.ymlCreate app on Heroku
heroku create johnvincentio-blog-appNotice
johnvincentio-blog-app
https://johnvincentio-blog-app.herokuapp.com/
https://git.heroku.com/johnvincentio-blog-app.gitPush to Heroku:
git push heroku masterStart up a dyno:
heroku ps:scale web=1Edit .travis.yml
deploy:
app: johnvincentio-blog-appGit commit changes to master
Mongo, Mongoose, mLab, and Heroku
At mLab, create new database: blog-challenge-tests-ci
mongo ds021289.mlab.com:21289/blog-challenge-tests-ci -u <dbuser> -p <dbpassword>
mongodb://<dbuser>:<dbpassword>@ds021289.mlab.com:21289/blog-challenge-tests-ciCreate user: jvtest
Import data:
cd MyDevelopment/github/thinkful/blog-challenge-tests-ci/data
mongoimport --db blog-challenge-tests-ci --collection blogs --drop --file seed-data.json --host ds021289.mlab.com --port 21289 -u jvtest -p <password>Note, local import
mongoimport --db blogDB --collection blogs --drop --file seed-data.jsonConnect:
mongo ds021289.mlab.com:21289/blog-challenge-tests-ci -u jvtest -p <password>
use blog-challenge-tests-ci
db.blogs.find()Connect using Studio3T
- Start Studio3T
- New Connection
Server
Name: ds021289.mlab.com
Type: Direct Connection
Server: ds021289.mlab.com
Port: 21289
Authentication, Basic
User name: jvtest
DB: blog-challenge-tests-ci
Server
Test Connection
OK>
Connect
will find blog-challenge-tests-ci etcSelect Connection (left menu), right click, IntelliShell
use blog-challenge-tests-ci
db.blogs.findOne()Configure Heroku
From the Heroku dashboard
select: johnvincentio-blog-app
Settings, Reveal Config Vars
Key: DATABASE_URL
Value: mongodb://jvtest:<dbpassword>@ds021289.mlab.com:21289/blog-challenge-tests-ciTest Heroku App
Open App, adding /blog (to test)
https://blog-challenge-tests-ci.herokuapp.com/blog
should retrieve some blogs dataHeroku
- Add Integration testing to Blogging App
- Add Mongoose to blogging app
- Continuous Integration with Travis CI
- Create SpringBoot App and Deploy to Heroku
- Deploy Node Express App to Heroku using Travis Continuous Integration
- Deploy React App to Heroku using Travis Continuous Integration
- Deploy Static Website to Heroku
- Heroku Notes
- Integrating Mongoose into an Express app
- Integration testing in a Mongoose world
- Tests and CI for Blogging App