Skip to content

Assignment 2

bmcgair edited this page Sep 29, 2017 · 3 revisions

Assignment 2 - Create Continuous Integration Environment

Prerequsites

  • Student has Github account
  • Student has Node JS installed on local laptop

Concepts Introduced

  • Continuous Build
  • Continuous Integration
  • Working with AWS CLI
  • Test Driven Development (TDD)

Step 1 - Fork and clone sample project

$ git clone https://github.com/YOURGITHUBUSERNAME/programmingforprogress-frontend.git

Step 2 - Setup Travis/GitHub integration

  1. Log in to http://travis-ci.org using your github credentials
  2. Add your repository
  3. Activate the repository /programmingforprogress-frontend

Note: if the setup/welcome page doesn't redirect you after five minutes, just browse to your Accounts page (https://travis-ci.org/profile/) to activate the repository

Step 3 - Install local travis client and login using github credentials

$ sudo gem install travis
$ travis login --auto

Step 4 - AWS Configuration

  1. Do Steps 1-3 in AWS tutorial to setup bucket policy
  2. Follow the instructions to create your AWS CLI credentials

Step 5 - Configure Travis build config file replacing with your AWS key id

Create .travis.yml file and save to project directory

language: node_js
node_js:
- '6.0'
install: npm install
deploy:
  provider: s3
  access_key_id: "${AWS_ACCESS_KEY_ID}"
  secret_access_key: "${AWS_SECRET_ACCESS_KEY}"
  bucket: "<your bucket name>"
  region: us-west-2

Step 6 - Add Environment Variables to travis

In the travis-ci.org config for your repo, add the following environment variables with your AWS credentials making sure that your keys are not exposed:

AWS_ACCESS_KEY
AWS_SECRET_KEY

Step 7 - Push changes & check build

$ git add .
$ git commit . -m "added travis configuration"
$ git push origin master

Browse to your travis home page (https://travis-ci.org/) and watch the build. It will fail.

Step 8 - Install Mocha & Setup Tests

Add the following line to your .travis.yml file before the install: line to install the mocha framework

before_install: npm install mocha

From your local command line:

$ npm install mocha

Edit package.json file in project directory to this:

"scripts": {
  "test":"mocha",

create a stubbed unit test function (yes this test will always pass - i.e. not a recommended pattern for real unit testing):

$ mkdir test

in your favorite editor create the file test/test.js with the following:

var assert = require('assert');
describe('Array', function() {
  describe('#indexOf()', function() {
    it('should return -1 when the value is not present', function() {
      assert.equal(-1, [1,2,3].indexOf(4));
    });
  });
});

from your command line run:

$ npm test

You should see:

Array
  #indexOf()
    ✓ should return -1 when the value is not present

1 passing (12ms)

Commit your changes from the command line

$ git add .
$ git commit . -m "added first test"
$ git push origin master

Switch to travis page and watch build. It should pass.

Clone this wiki locally