Dojo FAQ: How do I set up continuous integration testing with my Dojo app?

By on February 12, 2014 9:18 am

DojoFAQ

Continuous integration, the practice of frequently integrating the output of multiple developers into a common repository, has become very popular in recent years. A major benefit of CI is automated testing, which also makes CI useful for single developer projects. Intern, the complete JavaScript test stack from SitePen Labs, makes CI easy with your JavaScript-based source code.

Intern has out-of-the-box support for running both unit and functional tests through Travis CI, a popular hosted CI service that is free for open source projects and offers paid subscriptions for private projects. Before you start with CI you’ll need to write tests for your application. The Intern Tutorial is a good place to start, and the Intern Examples project shows how to use Intern with several popular JavaScript frameworks and libraries such as Dojo, AngularJS, jQuery, and Backbone.

Once you have created your tests, you’ll need to create a .travis.yml file in your repository. This file contains configuration information that tells Travis CI how to construct your testing environment and run your tests. For example, to run tests using Sauce Labs, a hosted web app testing service, your .travis.yml file should look like the following:

language: node_js
node_js:
  - "0.10"
env:
  global:
    - SAUCE_USERNAME: username
    - SAUCE_ACCESS_KEY: access-key
install:
  - npm install
  - cd node_modules/intern
  - npm install --production
  - cd ../..
script: node node_modules/intern/runner.js config=tests/intern

You will need to link your GitHub project to your Travis CI account for Travis CI to detect commits to your repository. The process for doing this is described in the Intern wiki. Once linked to your project, Travis CI will be notified of commits and will automatically run the tests specified in the .travis.yml file in the source code branch that was committed.

Intern is easy to use with Travis CI, but can also be extended to work with other CI tools like Jenkins and TeamCity. In many cases this just means writing compatible reporters to allow Intern to produce output, like unit test and coverage reports, that the CI system can understand. Reporters can be very simple, and the Intern wiki has more information on writing and using them. Intern 1.4 includes an official TeamCity reporter, as well as cobertura and lcovhtml reporters, which are helpful for Jenkins users.

If a simple reporter won’t get the job done, or you just need some help creating one, SitePen offers commercial JavaScript support and development services to assist you in your CI efforts.