This repository contains build and test automation for JavaScript projects. It's intended as a starting point for your own JavaScript projects. It includes:
- Automated continuous integration (using Git)
- Automated deployment (to Heroku)
- Automated build (using Jake) with:
- Linting (using JSHint)
- Node.js tests (using NodeUnit)
- Cross-browser tests (using Testacular, Mocha, and expect.js)
- Example code:
- Server-side integration test
- Development smoke test
- Release smoke test
- Client-side DOM test
This code was developed for the "Lessons Learned 8: Automatopia" episode of James Shore's Let's Code: Test-Driven JavaScript screencast. For details, the video, and a transcript, see letscodejavascript.com.
Before building for the first time:
- Install Node.js.
- Download and unzip the source code into a convenient directory.
- All commands must run from the root of the source tree:
cd <directory>
. - To cause the build to fail unless certain browsers are tested, edit
REQUIRED_BROWSERS
at the top ofJakefile.js
.
To build (and test):
- Run
./jake.sh testacular
(Unix/Mac) orjake testacular
(Windows) to start the Testacular server. - Start Safari or any other browsers you want to test against and point each one at
http://localhost:8080
. - Run
./jake.sh
(Unix/Mac) orjake
(Windows) every time you want to build and test.
To set up continuous integration for a team of developers:
- Choose a machine to be the integration machine.
- Follow the steps for "Building and Testing" on the integration machine.
- Run
git init
,git add .
, andgit commit -a -m "Initial Commit"
to initialize the git repository. - Run
git checkout -b integration
to create an integration branch.
To set up each development workstation:
- Choose an easy-to-type name for the development workstation, such as
dev1
. Put a label on the machine with this name so you don't forget it--you'll use it when you integrate. - On the integration machine, run
git branch <name>
create a branch for the development workstation. - Clone the integration machine's repository to the development workstation. (The steps here depend on your network configuration. Talk to your local Git expert.)
- On the development workstation, run
git checkout <name>
to switch to the development branch. - Now you can build and test as described above.
To integrate:
- On the development workstation, get to a clean build and commit your code.
- Run
./ci.sh pull
(Unix/Mac) orci pull
(Windows) to integrate the latest changes from the integration machine. - Run the build to make sure the integration didn't break anything.
- Run
./ci.sh push[<name>]
(Unix/Mac) orci push[<name>]
(Windows) to push your changes to your workstation's branch on the integration machine. - On the integration machine, run
./ci.sh promote[<name>]
(Unix/Mac) orci promote[<name>]
(Windows) to double-check your build and merge it into the known-good integration branch. - Start over on your development machine if anything breaks or if someone else integrates before you're done.
Before deploying for the first time:
- Follow the steps for "Continuous Integration" first.
- Sign up for a Heroku account.
- On the integration machine, install the Heroku Toolbelt.
- Create a Heroku application:
heroku create <app_name>
. - Change
PRODUCTION_URL
at the top ofdeploy.jakefile
tohttp://<app_name>.herokuapp.com
. - Update
package.json
to match your installed versions of Node and npm. (Usenode --version
andnpm --version
to get the version numbers.)
To deploy:
- On the integration machine, run
./deploy.sh latest
(Unix/Mac) ordeploy latest
(Windows) to deploy the integration branch to Heroku. The script will tag your git repository withdeploy-<timestamp>
if the deploy succeeds and passes the smoke tests.
In case of a bad deployment:
- On the integration machine, run
./deploy.sh rollback
(Unix/Mac) ordeploy rollback
(Windows) to do a band-aid rollback to the previous Heroku deployment. This rollback won't "stick", so you'll need to deploy new code soon. - If you aren't able to deploy new code right away, choose a previous, good commit to deploy.
gitk
and thedeploy-<timestamp>
tags may be helpful here. - Check out the commit:
git checkout <commit_id>
- Run
./deploy.sh head
(Unix/Mac) ordeploy head
(Windows) to deploy the commit to Heroku. As above, the script will tag the git repository withdeploy-<timestamp>
if the deploy succeeds and passes the smoke tests.