Contact Us

Testing node.js modules with Travis CI

Posted on 18/11/11 by Felix Geisendörfer

You have written a node.js module lately? It has a test suite? Awesome! Time to get yourself a nerd badge of honor:

build passing

But hang on nerdy warrior, this precious award has to be earned. So go ahead and check out the sweetness that is Travis CI. Travis is an open source, free to use, continuous integration server. Initially it was just building ruby stuff, but these days it supports a ton of other languages, including node.js.

And luckily, getting travis to run your tests on every GitHub push is really easy as well:

Step 1: Go to Travis and login/connect with your GitHub account.

Step 2: Hover over your name on the top right, and select "Profile" from the dropdown.

Step 3: You should see all your GitHub projects. Flip the "Off" switch to "On" for a node.js project you want to use with travis.

Step 4: Add a .travis.yml file to your project with the following:

language: node_js
  - 0.4
  - 0.6

Step 5: Make sure your package.json has something like this:

"scripts": {
    "test": "make test"

Step 6: Git push, and watch travis building your project on the home screen!

Step 7: Assuming your tests are passing, it is time to get your badge of honor. Adding it to your GitHub is as simple as:


If you want to see an example of what this looks like, and you also happen to be in the market for some no-bullshit testing tools, check out my new libs:

  • utest: The minimal unit testing library.
  • urun: The minimal test runner.

That's it. And in case you are not excited enough yet, go and check out the Travis Docs to discover additional goodies like how to work with databases, etc.



You can skip to the end and add a comment.

Nick said on Nov 18, 2011:

Step 7 should have:
#! in the link

But yes, this is a great idea. :)

Felix Geisendörfer said on Nov 20, 2011:

@Nick: Not sure what you mean?

Nick Campbell said on Nov 20, 2011:

When I use as the href link, I get a 404. But, if I change it to!/ncb000gt/node.bcrypt.js it is successful.

Felix Geisendörfer said on Nov 20, 2011:

Nick, that is strange. I believe this is a bug in travis because your project contains dots in the name.

Nick Campbell said on Nov 20, 2011:

Hmm. That could certainly be possible.

I see that urun worked fine without it. So it looks like whatever they are using for redirects is likely not working right.

Dan Jenkins said on Jan 17, 2012:

It's worth noting that if your repo belongs to an organization account that you belong to but you can't just login with the primary github account details, you need to setup a manual hook. Travis CI docs tell you how to do this:

You'd then need to go to your organization's generated url on travis/.Even though the hook is tied to my travis-ci token using the github account "danjenkins", I had to go to "!/holidayextras/node-asterisk-ami" to view the build status of my repo hosted on my organization's github, in this case "holidayextras".

This isn't very prominent on Travis CI's initial profile page with the switches. Hope it helps someone.

Felix Geisendörfer said on Jan 17, 2012:

Dan Jenkins: Thanks for the info!

This post is too old. We do not allow comments here anymore in order to fight spam. If you have real feedback or questions for the post, please contact us.