
[If you don't know how awesome Travis CI is, or why you should use it for your open source project, read this first]
Travis VMs includes Node 0.4.8 and NPM 1.0.12. You can use these to build and test your Node.js project. Add the following line to .travis.yml:
1 2 | before_script: "npm install --dev" script: "npm test" |
The first command installs the project’s runtime and development dependencies (listed as devDependencies in the project’s package.json file). The second command runs the test script specified in package.json.
You can tell npm how to run your test suite by adding a line in package.json. For example, to test using Vows:
1 2 3 | scripts: {
test: "vows --spec"
}, |
To setup the database and test using Expresso:
1 2 3 4 | scripts: {
pretest: "NODE_ENV=test node setup_db",
test: "expresso test/*"
}, |
Keeping the test script configuration in package.json makes it easy for other people to collaborate on your project, all they need to remember are the npm install and npm test conventions.